#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
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);
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;
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;
+ 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 == NULL) ? DEFAULT_LOGFILE : log_file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ fprintf(stderr, "log_logstash plugin: fopen (%s) failed: %s\n", log_file,
+ STRERRNO);
} else {
fprintf(fh, "%s\n", buf);
if (do_close) {
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)
}
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) {
plugin_register_notification("log_logstash", log_logstash_notification,
/* user_data = */ NULL);
} /* void module_register (void) */
-
-/* vim: set sw=4 ts=4 tw=78 noexpandtab : */