'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');
});
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);
});
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