#include "common.h"
#include "plugin.h"
-#define DEFAULT_LOGFILE LOCALSTATEDIR "/log/collectd.log"
-
#if COLLECT_DEBUG
static int log_level = LOG_DEBUG;
#else
static pthread_mutex_t file_lock = PTHREAD_MUTEX_INITIALIZER;
-static char *log_file = NULL;
+static char *log_file;
static int print_timestamp = 1;
-static int print_severity = 0;
+static int print_severity;
static const char *config_keys[] = {"LogLevel", "File", "Timestamp",
"PrintSeverity"};
if (log_level < 0) {
log_level = LOG_INFO;
ERROR("logfile: invalid loglevel [%s] defaulting to 'info'", value);
- return (1);
+ return 1;
}
} else if (0 == strcasecmp(key, "File")) {
sfree(log_file);
static void logfile_print(const char *msg, int severity,
cdtime_t timestamp_time) {
FILE *fh;
- _Bool do_close = 0;
+ bool do_close = false;
char timestamp_str[64];
char level_str[16] = "";
pthread_mutex_lock(&file_lock);
if (log_file == NULL) {
- fh = fopen(DEFAULT_LOGFILE, "a");
- do_close = 1;
+ fh = stderr;
} else if (strcasecmp(log_file, "stderr") == 0)
fh = stderr;
else if (strcasecmp(log_file, "stdout") == 0)
fh = stdout;
else {
fh = fopen(log_file, "a");
- do_close = 1;
+ do_close = true;
}
if (fh == NULL) {
- char errbuf[1024];
- fprintf(stderr, "logfile plugin: fopen (%s) failed: %s\n",
- (log_file == NULL) ? DEFAULT_LOGFILE : log_file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ fprintf(stderr, "logfile plugin: fopen (%s) failed: %s\n", log_file,
+ STRERRNO);
} else {
if (print_timestamp)
fprintf(fh, "[%s] %s%s\n", timestamp_str, level_str, msg);
int buf_len = sizeof(buf);
int status;
- status = ssnprintf(
+ status = snprintf(
buf_ptr, buf_len, "Notification: severity = %s",
(n->severity == NOTIF_FAILURE)
? "FAILURE"
#define APPEND(bufptr, buflen, key, value) \
if ((buflen > 0) && (strlen(value) > 0)) { \
- status = ssnprintf(bufptr, buflen, ", %s = %s", key, value); \
+ status = snprintf(bufptr, buflen, ", %s = %s", key, value); \
if (status > 0) { \
bufptr += status; \
buflen -= status; \
logfile_print(buf, LOG_INFO, (n->time != 0) ? n->time : cdtime());
- return (0);
+ return 0;
} /* int logfile_notification */
void module_register(void) {