X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Flogfile.c;h=fa56a1bcc95e790d5aac21d4aa42394fc5548835;hp=ef3aa97e59b4547fec0aa57992223212bf0071f2;hb=06a86a60a7dabc685bdbd81ce3d36ea5f7e2c2d4;hpb=92e19cb238c23c63599e035fd07b9c09a8bef2e3 diff --git a/src/logfile.c b/src/logfile.c index ef3aa97e..fa56a1bc 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -39,9 +39,9 @@ static int log_level = LOG_INFO; 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"}; @@ -53,7 +53,7 @@ static int logfile_config(const char *key, const char *value) { 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); @@ -77,8 +77,7 @@ static int logfile_config(const char *key, const char *value) { static void logfile_print(const char *msg, int severity, cdtime_t timestamp_time) { FILE *fh; - _Bool do_close = 0; - struct tm timestamp_tm; + bool do_close = false; char timestamp_str[64]; char level_str[16] = ""; @@ -105,8 +104,8 @@ static void logfile_print(const char *msg, int severity, } if (print_timestamp) { - time_t tt = CDTIME_T_TO_TIME_T(timestamp_time); - localtime_r(&tt, ×tamp_tm); + struct tm timestamp_tm; + localtime_r(&CDTIME_T_TO_TIME_T(timestamp_time), ×tamp_tm); strftime(timestamp_str, sizeof(timestamp_str), "%Y-%m-%d %H:%M:%S", ×tamp_tm); @@ -123,13 +122,12 @@ static void logfile_print(const char *msg, int severity, 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, - sstrerror(errno, errbuf, sizeof(errbuf))); + STRERRNO); } else { if (print_timestamp) fprintf(fh, "[%s] %s%s\n", timestamp_str, level_str, msg); @@ -164,7 +162,7 @@ static int logfile_notification(const notification_t *n, int buf_len = sizeof(buf); int status; - status = ssnprintf( + status = snprintf( buf_ptr, buf_len, "Notification: severity = %s", (n->severity == NOTIF_FAILURE) ? "FAILURE" @@ -178,7 +176,7 @@ static int logfile_notification(const notification_t *n, #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; \ @@ -195,7 +193,7 @@ static int logfile_notification(const notification_t *n, logfile_print(buf, LOG_INFO, (n->time != 0) ? n->time : cdtime()); - return (0); + return 0; } /* int logfile_notification */ void module_register(void) { @@ -205,5 +203,3 @@ void module_register(void) { plugin_register_notification("logfile", logfile_notification, /* user_data = */ NULL); } /* void module_register (void) */ - -/* vim: set sw=4 ts=4 tw=78 noexpandtab : */