cache maintenance remove routine added - needs a real one
[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(typeof global.repoproxy == "undefined" || 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(typeof global.repoproxy != "undefined") {
35                 if(global.repoproxy.loglevel >= 4) {
36                         sendLog.apply(this, arguments);
37                 }       
38         }
39 }
40
41 function warning() {
42         var orig = arguments["0"];
43         var ts = new Date().toISOString();
44         //var ts = ts_t.format("%Y-%m-%d %H:%M:%S");
45         arguments["0"] = "[!!WARNING!!] ("+ts+"): "+orig;
46         
47         if(typeof global.repoproxy == "undefined" || global.repoproxy.loglevel >= 2) {
48                 sendLog.apply(this, arguments);
49         }
50 }
51
52 function error() {
53         var orig = arguments["0"];
54         var ts = new Date().toISOString();
55         //var ts = ts_t.format("%Y-%m-%d %H:%M:%S");
56         arguments["0"] = "[**ERROR**] ("+ts+"): "+orig;
57         
58         if(typeof global.repoproxy == "undefined" || global.repoproxy.loglevel >= 1) {
59                 sendLog.apply(this, arguments);         
60         }       
61 }
62
63 function sendLog() {
64         console.log.apply(this, arguments);
65 }
66
67
68 exports.info = info;
69 exports.debug = debug;
70 exports.warning = warning;
71 exports.error = error;
72 exports.testLogSettings = testLogSettings;