]> arthur.barton.de Git - netdata.git/commitdiff
unified logging for all plugins
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 20 Oct 2016 20:18:40 +0000 (23:18 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 20 Oct 2016 20:18:40 +0000 (23:18 +0300)
node.d/node_modules/netdata.js
plugins.d/node.d.plugin
python.d/python_modules/msg.py
src/log.c

index 6183993b5ba03898cca4e5e982e8fccf2551e922..706f75f4f6140aeb8c685bc84c87609311f71ee1 100644 (file)
@@ -1,5 +1,10 @@
 'use strict';
 
+// netdata
+// real-time performance and health monitoring, done right!
+// (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
+// 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
index df96ecb207e05a266ed22a9c04b0e6999e9c1582..8b7047fcbbbfdb5423cb10593a084576fca7e9e2 100755 (executable)
@@ -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 <costa@tsaousis.gr>
+// GPL v3+
+
 // --------------------------------------------------------------------------------------------------------------------
 
 'use strict';
index ecefba0a4fa185b38cb4e02b5a1c8b4f07651dc4..203751afdb051d39ab98c5f5b883c3dc772d017f 100644 (file)
@@ -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()
index b7ec64bcb9463eb31b2eab07c37685c7f6a6d5ee..86716987aeba7eab4dbab471732d5dcafa4a9da3 100644 (file)
--- 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 );