# define HAVE_YAJL_V2 1
#endif
-#define DEFAULT_LOGFILE LOCALSTATEDIR"/log/collectd.json.log"
+#define DEFAULT_LOGFILE LOCALSTATEDIR"/log/"PACKAGE_NAME".json.log"
#if COLLECT_DEBUG
static int log_level = LOG_DEBUG;
if (0 == strcasecmp (key, "LogLevel")) {
log_level = parse_log_severity(value);
- printf("parsed log level: %d\n", log_level);
- if (log_level == -1) return 1; /* to keep previous behaviour */
+ if (log_level < 0) {
+ log_level = LOG_INFO;
+ ERROR("log_logstash: invalid loglevel [%s] defaulting to 'info'",
+ value);
+ return 1;
+ }
}
else if (0 == strcasecmp (key, "File")) {
sfree (log_file);
size_t len;
#else
unsigned int len;
-#endif
+#endif
if (yajl_gen_string(g, (u_char *)"@level", strlen("@level")) !=
yajl_gen_status_ok)
tt = CDTIME_T_TO_TIME_T (timestamp_time);
gmtime_r (&tt, ×tamp_tm);
- /*
+ /*
* format time as a UTC ISO 8601 compliant string
*/
strftime (timestamp_str, sizeof (timestamp_str),
"%Y-%m-%d %H:%M:%SZ", ×tamp_tm);
timestamp_str[sizeof (timestamp_str) - 1] = '\0';
-
+
if (yajl_gen_string(g, (u_char *)timestamp_str,
strlen(timestamp_str)) !=
yajl_gen_status_ok)
{
fh = fopen (DEFAULT_LOGFILE, "a");
do_close = 1;
- }
- else
- {
+ } else if (strcasecmp(log_file, "stdout") == 0) {
+ fh = stdout;
+ do_close = 0;
+ } else if (strcasecmp(log_file, "stderr") == 0) {
+ fh = stderr;
+ do_close = 0;
+ } else {
fh = fopen (log_file, "a");
do_close = 1;
}
yajl_gen_config conf;
conf.beautify = 0;
-#endif
+#endif
if (severity > log_level)
return;
yajl_gen_free(g);
fprintf(stderr, "Could not generate JSON message preamble\n");
return;
-
+
} /* void log_logstash_log (int, const char *) */
static int log_logstash_notification (const notification_t *n,
yajl_gen_status_ok)
goto err;
if (yajl_gen_string(g, (u_char *)n->type_instance,
- strlen(n->type_instance)) !=
+ strlen(n->type_instance)) !=
yajl_gen_status_ok)
goto err;
}
} /* void module_register (void) */
/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
-