X-Git-Url: http://git.pjr.cc/?p=nodejs-repoproxy.git;a=blobdiff_plain;f=lib%2Flog.js;fp=lib%2Flog.js;h=24f31d23e13bccef69f68818e7958657a22585ae;hp=0000000000000000000000000000000000000000;hb=d7478970127408f056b157f18df74fef7db3f892;hpb=efd3942c83ad1235b32f983f53f89c984ef81db4 diff --git a/lib/log.js b/lib/log.js new file mode 100644 index 0000000..24f31d2 --- /dev/null +++ b/lib/log.js @@ -0,0 +1,70 @@ + + +/* + * # level for logging (1 = error, 2 = warning, 3=info, 4=debug); +loggerlevel:4 + + */ +function testLogSettings() { + var curtime = new Date().getTime(); + debug("This is a DEBUG TeST (%d)", curtime); + info("This is an Info TEST (%d)", curtime); + warning("This is a WARN test (%d)", curtime); + error("This is an ERROR test (%d)", curtime); +} + + +function info() { + var orig = arguments["0"]; + var ts = new Date().toISOString(); + //var ts = ts_t.format("%Y-%m-%d %H:%M:%S"); + arguments["0"] = "[??INFO??] ("+ts+"): "+orig; + + if(global.repoproxy.loglevel >= 3) { + sendLog.apply(this, arguments); + } +} + +function debug() { + var orig = arguments["0"]; + var ts = new Date().toISOString(); + //var ts = ts_t.format("%Y-%m-%d %H:%M:%S"); + arguments["0"] = "[^^DEBUG^^] ("+ts+"): "+orig; + + if(global.repoproxy.loglevel >= 4) { + sendLog.apply(this, arguments); + } +} + +function warning() { + var orig = arguments["0"]; + var ts = new Date().toISOString(); + //var ts = ts_t.format("%Y-%m-%d %H:%M:%S"); + arguments["0"] = "[!!WARNING!!] ("+ts+"): "+orig; + + if(global.repoproxy.loglevel >= 2) { + sendLog.apply(this, arguments); + } +} + +function error() { + var orig = arguments["0"]; + var ts = new Date().toISOString(); + //var ts = ts_t.format("%Y-%m-%d %H:%M:%S"); + arguments["0"] = "[**ERROR**] ("+ts+"): "+orig; + + if(global.repoproxy.loglevel >= 1) { + sendLog.apply(this, arguments); + } +} + +function sendLog() { + console.log.apply(this, arguments); +} + + +exports.info = info; +exports.debug = debug; +exports.warning = warning; +exports.error = error; +exports.testLogSettings = testLogSettings;