added a logger, started working on the maintenance timer routines
[nodejs-repoproxy.git] / lib / log.js
diff --git a/lib/log.js b/lib/log.js
new file mode 100644 (file)
index 0000000..24f31d2
--- /dev/null
@@ -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;