added a logger, started working on the maintenance timer routines
[nodejs-repoproxy.git] / lib / log.js
1
2
3 /*
4  * # level for logging (1 = error, 2 = warning, 3=info, 4=debug);
5 loggerlevel:4
6
7  */
8 function testLogSettings() {
9         var curtime = new Date().getTime();
10         debug("This is a DEBUG TeST (%d)", curtime);
11         info("This is an Info TEST (%d)", curtime);
12         warning("This is a WARN test (%d)", curtime);
13         error("This is an ERROR test (%d)", curtime);
14 }
15
16
17 function info() {
18         var orig = arguments["0"];
19         var ts = new Date().toISOString();
20         //var ts = ts_t.format("%Y-%m-%d %H:%M:%S");
21         arguments["0"] = "[??INFO??] ("+ts+"): "+orig;
22         
23         if(global.repoproxy.loglevel >= 3) {
24                 sendLog.apply(this, arguments);
25         }
26 }
27
28 function debug() {
29         var orig = arguments["0"];
30         var ts = new Date().toISOString();
31         //var ts = ts_t.format("%Y-%m-%d %H:%M:%S");
32         arguments["0"] = "[^^DEBUG^^] ("+ts+"): "+orig;
33         
34         if(global.repoproxy.loglevel >= 4) {
35                 sendLog.apply(this, arguments); 
36         }
37 }
38
39 function warning() {
40         var orig = arguments["0"];
41         var ts = new Date().toISOString();
42         //var ts = ts_t.format("%Y-%m-%d %H:%M:%S");
43         arguments["0"] = "[!!WARNING!!] ("+ts+"): "+orig;
44         
45         if(global.repoproxy.loglevel >= 2) {
46                 sendLog.apply(this, arguments);
47         }
48 }
49
50 function error() {
51         var orig = arguments["0"];
52         var ts = new Date().toISOString();
53         //var ts = ts_t.format("%Y-%m-%d %H:%M:%S");
54         arguments["0"] = "[**ERROR**] ("+ts+"): "+orig;
55         
56         if(global.repoproxy.loglevel >= 1) {
57                 sendLog.apply(this, arguments);         
58         }       
59 }
60
61 function sendLog() {
62         console.log.apply(this, arguments);
63 }
64
65
66 exports.info = info;
67 exports.debug = debug;
68 exports.warning = warning;
69 exports.error = error;
70 exports.testLogSettings = testLogSettings;