X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Flog_logstash.c;h=28cc34c83fb17b9fc907039507033503ace055f4;hp=837796197a24387efa26e303405d61544db446b4;hb=7111bb6df7628edce3a8e538b386fbe27633a191;hpb=2079ee1517e34de372f58e7e2267ad5c71a8a41f diff --git a/src/log_logstash.c b/src/log_logstash.c index 83779619..28cc34c8 100644 --- a/src/log_logstash.c +++ b/src/log_logstash.c @@ -41,8 +41,6 @@ #define HAVE_YAJL_V2 1 #endif -#define DEFAULT_LOGFILE LOCALSTATEDIR "/log/" PACKAGE_NAME ".json.log" - #if COLLECT_DEBUG static int log_level = LOG_DEBUG; #else @@ -81,7 +79,6 @@ static void log_logstash_print(yajl_gen g, int severity, struct tm timestamp_tm; char timestamp_str[64]; const unsigned char *buf; - time_t tt; #if HAVE_YAJL_V2 size_t len; #else @@ -129,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 @@ -151,8 +147,7 @@ static void log_logstash_print(yajl_gen g, int severity, pthread_mutex_lock(&file_lock); if (log_file == NULL) { - fh = fopen(DEFAULT_LOGFILE, "a"); - do_close = 1; + fh = stderr; } else if (strcasecmp(log_file, "stdout") == 0) { fh = stdout; do_close = 0; @@ -166,8 +161,7 @@ static void log_logstash_print(yajl_gen g, int severity, if (fh == NULL) { char errbuf[1024]; - fprintf(stderr, "log_logstash plugin: fopen (%s) failed: %s\n", - (log_file == NULL) ? DEFAULT_LOGFILE : log_file, + fprintf(stderr, "log_logstash plugin: fopen (%s) failed: %s\n", log_file, sstrerror(errno, errbuf, sizeof(errbuf))); } else { fprintf(fh, "%s\n", buf); @@ -242,7 +236,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) @@ -329,12 +323,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) { @@ -345,5 +339,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 : */