@cryptotaxi247 / netdata-1 / commits / d2fcdc9eb

unified logging for all plugins

Costa Tsaousis (ktsaou) committed Oct 20, 2016 at 23:18 UTC d2fcdc9eb1ca5d89387c6094128922b726719b02
4 files changed +42 -16
node.d/node_modules/netdata.js
+26 -5
@@ -1,5 +1,10 @@
1 'use strict';
2
3 +// netdata
4 +// real-time performance and health monitoring, done right!
5 +// (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6 +// GPL v3+
7 +
8 var url = require('url');
9 var http = require('http');
10 var util = require('util');
@@ -108,7 +113,8 @@ var netdata = {
113 });
114
115 req.on('error', function(e) {
111 - service.error('Failed to make request: ' + netdata.stringify(service.request) + ', message: ' + e.message);
116 + if(netdata.options.DEBUG === true) netdata.debug('Failed to make request: ' + netdata.stringify(service.request) + ', message: ' + e.message);
117 + service.error('Failed to make request, message: ' + e.message);
118 callback(null);
119 });
120
@@ -127,18 +133,33 @@ var netdata = {
133 return util.inspect(obj, {depth: 10});
134 },
135
136 + zeropad2: function(s) {
137 + if(typeof s !== 'string')
138 + s = s.toString();
139 +
140 + switch(s.length) {
141 + case 0: return '00';
142 + case 1: return '0' + s;
143 + default: return s;
144 + }
145 + },
146 +
147 + logdate: function(d) {
148 + if(typeof d === 'undefined') d = new Date();
149 + return this.zeropad2(d.getFullYear()) + '-' + this.zeropad2(d.getMonth()) + '-' + this.zeropad2(d.getDay())
150 + + ' ' + this.zeropad2(d.getHours()) + ':' + this.zeropad2(d.getMinutes()) + ':' + this.zeropad2(d.getSeconds());
151 + },
152 +
153 // show debug info, if debug is enabled
154 debug: function(msg) {
155 if(this.options.DEBUG === true) {
133 - var now = new Date();
134 - console.error(now.toString() + ': ' + netdata.options.filename + ': DEBUG: ' + ((typeof(msg) === 'object')?netdata.stringify(msg):msg).toString());
156 + console.error(this.logdate() + ': ' + netdata.options.filename + ': DEBUG: ' + ((typeof(msg) === 'object')?netdata.stringify(msg):msg).toString());
157 }
158 },
159
160 // log an error
161 error: function(msg) {
140 - var now = new Date();
141 - console.error(now.toString() + ': ' + netdata.options.filename + ': ERROR: ' + ((typeof(msg) === 'object')?netdata.stringify(msg):msg).toString());
162 + console.error(this.logdate() + ': ' + netdata.options.filename + ': ERROR: ' + ((typeof(msg) === 'object')?netdata.stringify(msg):msg).toString());
163 },
164
165 // send data to netdata
plugins.d/node.d.plugin
+5
@@ -8,6 +8,11 @@
8 // Then, the second line, finds nodejs or node or js in the system path
9 // and executes it with the shell parameters.
10
11 +// netdata
12 +// real-time performance and health monitoring, done right!
13 +// (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
14 +// GPL v3+
15 +
16 // --------------------------------------------------------------------------------------------------------------------
17
18 'use strict';
python.d/python_modules/msg.py
+2 -2
@@ -24,7 +24,7 @@ def log_msg(msg_type, *args):
24 LOG_COUNTER -= 1
25 now = time()
26 if LOG_COUNTER >= 0:
27 - timestamp = strftime('%y-%m-%d %X')
27 + timestamp = strftime('%Y-%m-%d %X')
28 msg = "%s: %s %s: %s" % (timestamp, PROGRAM, str(msg_type), " ".join(args))
29 WRITE(msg + "\n")
30 FLUSH()
@@ -33,7 +33,7 @@ def log_msg(msg_type, *args):
33 if NEXT_CHECK <= now:
34 NEXT_CHECK = now - (now % LOG_INTERVAL) + LOG_INTERVAL
35 if LOG_COUNTER < 0:
36 - timestamp = strftime('%y-%m-%d %X')
36 + timestamp = strftime('%Y-%m-%d %X')
37 msg = "%s: Prevented %s log messages from displaying" % (timestamp, str(0 - LOG_COUNTER))
38 WRITE(msg + "\n")
39 FLUSH()
src/log.c
+9 -9
@@ -200,7 +200,7 @@ int error_log_limit(int reset) {
200
201 void log_date(FILE *out)
202 {
203 - char outstr[24];
203 + char outstr[26];
204 time_t t;
205 struct tm *tmp, tmbuf;
206
@@ -208,7 +208,7 @@ void log_date(FILE *out)
208 tmp = localtime_r(&t, &tmbuf);
209
210 if (tmp == NULL) return;
211 - if (unlikely(strftime(outstr, sizeof(outstr), "%y-%m-%d %H:%M:%S", tmp) == 0)) return;
211 + if (unlikely(strftime(outstr, sizeof(outstr), "%Y-%m-%d %H:%M:%S", tmp) == 0)) return;
212
213 fprintf(out, "%s: ", outstr);
214 }
@@ -222,7 +222,7 @@ void debug_int( const char *file, const char *function, const unsigned long line
222
223 log_date(stdout);
224 va_start( args, fmt );
225 - printf("DEBUG (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
225 + printf("%s: DEBUG (%04lu@%-10.10s:%-15.15s): ", program_name, line, file, function);
226 vprintf(fmt, args);
227 va_end( args );
228 putchar('\n');
@@ -249,8 +249,8 @@ void info_int( const char *file, const char *function, const unsigned long line,
249 log_date(stderr);
250
251 va_start( args, fmt );
252 - if(debug_flags) fprintf(stderr, "INFO (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
253 - else fprintf(stderr, "INFO: %s: ", program_name);
252 + if(debug_flags) fprintf(stderr, "%s: INFO: (%04lu@%-10.10s:%-15.15s):", program_name, line, file, function);
253 + else fprintf(stderr, "%s: INFO: ", program_name);
254 vfprintf( stderr, fmt, args );
255 va_end( args );
256
@@ -298,8 +298,8 @@ void error_int( const char *prefix, const char *file, const char *function, cons
298 log_date(stderr);
299
300 va_start( args, fmt );
301 - if(debug_flags) fprintf(stderr, "%s (%04lu@%-10.10s:%-15.15s): %s: ", prefix, line, file, function, program_name);
302 - else fprintf(stderr, "%s: %s: ", prefix, program_name);
301 + if(debug_flags) fprintf(stderr, "%s: %s: (%04lu@%-10.10s:%-15.15s): ", program_name, prefix, line, file, function);
302 + else fprintf(stderr, "%s: %s: ", program_name, prefix);
303 vfprintf( stderr, fmt, args );
304 va_end( args );
305
@@ -325,8 +325,8 @@ void fatal_int( const char *file, const char *function, const unsigned long line
325 log_date(stderr);
326
327 va_start( args, fmt );
328 - if(debug_flags) fprintf(stderr, "FATAL (%04lu@%-10.10s:%-15.15s): %s: ", line, file, function, program_name);
329 - else fprintf(stderr, "FATAL: %s: ", program_name);
328 + if(debug_flags) fprintf(stderr, "%s: FATAL: (%04lu@%-10.10s:%-15.15s): ", program_name, line, file, function);
329 + else fprintf(stderr, "%s: FATAL: ", program_name);
330 vfprintf( stderr, fmt, args );
331 va_end( args );
332