X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Flog_logstash.c;h=8f3063f32a6d284d6a6be090dddcd9e9789bca7c;hb=a396da422740caf336a6d594515e8d80de6f440a;hp=3ef7139702a270ce9c8e3f1d6139625012c60f99;hpb=92e19cb238c23c63599e035fd07b9c09a8bef2e3;p=collectd.git diff --git a/src/log_logstash.c b/src/log_logstash.c index 3ef71397..8f3063f3 100644 --- a/src/log_logstash.c +++ b/src/log_logstash.c @@ -49,7 +49,7 @@ 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 const char *config_keys[] = {"LogLevel", "File"}; static int config_keys_num = STATIC_ARRAY_SIZE(config_keys); @@ -75,11 +75,10 @@ static int log_logstash_config(const char *key, const char *value) { static void log_logstash_print(yajl_gen g, int severity, cdtime_t timestamp_time) { FILE *fh; - _Bool do_close = 0; + bool do_close = false; struct tm timestamp_tm; char timestamp_str[64]; const unsigned char *buf; - time_t tt; #if HAVE_YAJL_V2 size_t len; #else @@ -127,8 +126,7 @@ static void log_logstash_print(yajl_gen g, int severity, yajl_gen_status_ok) goto err; - tt = CDTIME_T_TO_TIME_T(timestamp_time); - gmtime_r(&tt, ×tamp_tm); + gmtime_r(&CDTIME_T_TO_TIME_T(timestamp_time), ×tamp_tm); /* * format time as a UTC ISO 8601 compliant string @@ -152,19 +150,18 @@ static void log_logstash_print(yajl_gen g, int severity, fh = stderr; } else if (strcasecmp(log_file, "stdout") == 0) { fh = stdout; - do_close = 0; + do_close = false; } else if (strcasecmp(log_file, "stderr") == 0) { fh = stderr; - do_close = 0; + do_close = false; } else { fh = fopen(log_file, "a"); - do_close = 1; + do_close = true; } if (fh == NULL) { - char errbuf[1024]; fprintf(stderr, "log_logstash plugin: fopen (%s) failed: %s\n", log_file, - sstrerror(errno, errbuf, sizeof(errbuf))); + STRERRNO); } else { fprintf(fh, "%s\n", buf); if (do_close) { @@ -238,7 +235,7 @@ static int log_logstash_notification(const notification_t *n, if (g == NULL) { fprintf(stderr, "Could not allocate JSON generator.\n"); - return (0); + return 0; } if (yajl_gen_map_open(g) != yajl_gen_status_ok) @@ -325,12 +322,12 @@ static int log_logstash_notification(const notification_t *n, } log_logstash_print(g, LOG_INFO, (n->time != 0) ? n->time : cdtime()); - return (0); + return 0; err: yajl_gen_free(g); fprintf(stderr, "Could not correctly generate JSON notification\n"); - return (0); + return 0; } /* int log_logstash_notification */ void module_register(void) { @@ -341,5 +338,3 @@ void module_register(void) { plugin_register_notification("log_logstash", log_logstash_notification, /* user_data = */ NULL); } /* void module_register (void) */ - -/* vim: set sw=4 ts=4 tw=78 noexpandtab : */