From: Costa Tsaousis (ktsaou) Date: Thu, 20 Oct 2016 20:18:40 +0000 (+0300) Subject: unified logging for all plugins X-Git-Tag: v1.5.0~226^2~7 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netdata.git;a=commitdiff_plain;h=d2fcdc9eb1ca5d89387c6094128922b726719b02 unified logging for all plugins --- diff --git a/node.d/node_modules/netdata.js b/node.d/node_modules/netdata.js index 6183993b..706f75f4 100644 --- a/node.d/node_modules/netdata.js +++ b/node.d/node_modules/netdata.js @@ -1,5 +1,10 @@ 'use strict'; +// netdata +// real-time performance and health monitoring, done right! +// (C) 2016 Costa Tsaousis +// GPL v3+ + var url = require('url'); var http = require('http'); var util = require('util'); @@ -108,7 +113,8 @@ var netdata = { }); req.on('error', function(e) { - service.error('Failed to make request: ' + netdata.stringify(service.request) + ', message: ' + e.message); + if(netdata.options.DEBUG === true) netdata.debug('Failed to make request: ' + netdata.stringify(service.request) + ', message: ' + e.message); + service.error('Failed to make request, message: ' + e.message); callback(null); }); @@ -127,18 +133,33 @@ var netdata = { return util.inspect(obj, {depth: 10}); }, + zeropad2: function(s) { + if(typeof s !== 'string') + s = s.toString(); + + switch(s.length) { + case 0: return '00'; + case 1: return '0' + s; + default: return s; + } + }, + + logdate: function(d) { + if(typeof d === 'undefined') d = new Date(); + return this.zeropad2(d.getFullYear()) + '-' + this.zeropad2(d.getMonth()) + '-' + this.zeropad2(d.getDay()) + + ' ' + this.zeropad2(d.getHours()) + ':' + this.zeropad2(d.getMinutes()) + ':' + this.zeropad2(d.getSeconds()); + }, + // show debug info, if debug is enabled debug: function(msg) { if(this.options.DEBUG === true) { - var now = new Date(); - console.error(now.toString() + ': ' + netdata.options.filename + ': DEBUG: ' + ((typeof(msg) === 'object')?netdata.stringify(msg):msg).toString()); + console.error(this.logdate() + ': ' + netdata.options.filename + ': DEBUG: ' + ((typeof(msg) === 'object')?netdata.stringify(msg):msg).toString()); } }, // log an error error: function(msg) { - var now = new Date(); - console.error(now.toString() + ': ' + netdata.options.filename + ': ERROR: ' + ((typeof(msg) === 'object')?netdata.stringify(msg):msg).toString()); + console.error(this.logdate() + ': ' + netdata.options.filename + ': ERROR: ' + ((typeof(msg) === 'object')?netdata.stringify(msg):msg).toString()); }, // send data to netdata diff --git a/plugins.d/node.d.plugin b/plugins.d/node.d.plugin index df96ecb2..8b7047fc 100755 --- a/plugins.d/node.d.plugin +++ b/plugins.d/node.d.plugin @@ -8,6 +8,11 @@ // Then, the second line, finds nodejs or node or js in the system path // and executes it with the shell parameters. +// netdata +// real-time performance and health monitoring, done right! +// (C) 2016 Costa Tsaousis +// GPL v3+ + // -------------------------------------------------------------------------------------------------------------------- 'use strict'; diff --git a/python.d/python_modules/msg.py b/python.d/python_modules/msg.py index ecefba0a..203751af 100644 --- a/python.d/python_modules/msg.py +++ b/python.d/python_modules/msg.py @@ -24,7 +24,7 @@ def log_msg(msg_type, *args): LOG_COUNTER -= 1 now = time() if LOG_COUNTER >= 0: - timestamp = strftime('%y-%m-%d %X') + timestamp = strftime('%Y-%m-%d %X') msg = "%s: %s %s: %s" % (timestamp, PROGRAM, str(msg_type), " ".join(args)) WRITE(msg + "\n") FLUSH() @@ -33,7 +33,7 @@ def log_msg(msg_type, *args): if NEXT_CHECK <= now: NEXT_CHECK = now - (now % LOG_INTERVAL) + LOG_INTERVAL if LOG_COUNTER < 0: - timestamp = strftime('%y-%m-%d %X') + timestamp = strftime('%Y-%m-%d %X') msg = "%s: Prevented %s log messages from displaying" % (timestamp, str(0 - LOG_COUNTER)) WRITE(msg + "\n") FLUSH() diff --git a/src/log.c b/src/log.c index b7ec64bc..86716987 100644 --- a/src/log.c +++ b/src/log.c @@ -200,7 +200,7 @@ int error_log_limit(int reset) { void log_date(FILE *out) { - char outstr[24]; + char outstr[26]; time_t t; struct tm *tmp, tmbuf; @@ -208,7 +208,7 @@ void log_date(FILE *out) tmp = localtime_r(&t, &tmbuf); if (tmp == NULL) return; - if (unlikely(strftime(outstr, sizeof(outstr), "%y-%m-%d %H:%M:%S", tmp) == 0)) return; + if (unlikely(strftime(outstr, sizeof(outstr), "%Y-%m-%d %H:%M:%S", tmp) == 0)) return; fprintf(out, "%s: ", outstr); } @@ -222,7 +222,7 @@ void debug_int( const char *file, const char *function, const unsigned long line log_date(stdout); va_start( args, fmt ); - printf("DEBUG (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name); + printf("%s: DEBUG (%04lu@%-10.10s:%-15.15s): ", program_name, line, file, function); vprintf(fmt, args); va_end( args ); putchar('\n'); @@ -249,8 +249,8 @@ void info_int( const char *file, const char *function, const unsigned long line, log_date(stderr); va_start( args, fmt ); - if(debug_flags) fprintf(stderr, "INFO (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name); - else fprintf(stderr, "INFO: %s: ", program_name); + if(debug_flags) fprintf(stderr, "%s: INFO: (%04lu@%-10.10s:%-15.15s):", program_name, line, file, function); + else fprintf(stderr, "%s: INFO: ", program_name); vfprintf( stderr, fmt, args ); va_end( args ); @@ -298,8 +298,8 @@ void error_int( const char *prefix, const char *file, const char *function, cons log_date(stderr); va_start( args, fmt ); - if(debug_flags) fprintf(stderr, "%s (%04lu@%-10.10s:%-15.15s): %s: ", prefix, line, file, function, program_name); - else fprintf(stderr, "%s: %s: ", prefix, program_name); + if(debug_flags) fprintf(stderr, "%s: %s: (%04lu@%-10.10s:%-15.15s): ", program_name, prefix, line, file, function); + else fprintf(stderr, "%s: %s: ", program_name, prefix); vfprintf( stderr, fmt, args ); va_end( args ); @@ -325,8 +325,8 @@ void fatal_int( const char *file, const char *function, const unsigned long line log_date(stderr); va_start( args, fmt ); - if(debug_flags) fprintf(stderr, "FATAL (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name); - else fprintf(stderr, "FATAL: %s: ", program_name); + if(debug_flags) fprintf(stderr, "%s: FATAL: (%04lu@%-10.10s:%-15.15s): ", program_name, line, file, function); + else fprintf(stderr, "%s: FATAL: ", program_name); vfprintf( stderr, fmt, args ); va_end( args );