summaryrefslogtreecommitdiffstats
path: root/node.d
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2016-10-20 23:18:40 +0300
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2016-10-20 23:18:40 +0300
commitd2fcdc9eb1ca5d89387c6094128922b726719b02 (patch)
treea511d70bf01cc7dc325e4daa624311fbccc08a4c /node.d
parent0a26e46c36e7fc1c343f9512ae6ade05a78349a1 (diff)
unified logging for all plugins
Diffstat (limited to 'node.d')
-rw-r--r--node.d/node_modules/netdata.js31
1 files changed, 26 insertions, 5 deletions
diff --git a/node.d/node_modules/netdata.js b/node.d/node_modules/netdata.js
index 6183993b5b..706f75f4f6 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 <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