fixing up log entries
[nodejs-repoproxy.git] / lib / config.js
index 8d6d2fc..8af15f0 100644 (file)
@@ -9,6 +9,7 @@ exports.loadConfig = function (conffile) {
        global.repoproxy.repo = new Object();
        global.repoproxy.scancache = 1;
        global.repoproxy.downloads = new Object();
+       global.repoproxy.loglevel = 3;
 
        // set a global file id for file trashing
        //global.repoproxy.fileid = new Object();
@@ -33,43 +34,46 @@ exports.loadConfig = function (conffile) {
                // parse the line
                switch(line_real[0]) {
                case "repo":
-                       
                        // TODO: VALIDATE!
-                       console.log("Adding repo: '/%s' type '%s' from '%s', with update interval of '%s' days, and expire time of '%s' days.", line_real[1], line_real[2], line_real[3]+":"+line_real[4], line_real[5], line_real[6]);
+                       log.info("Adding repo: '/%s' type '%s' from '%s', with update interval of '%s' days, and expire time of '%s' days.", line_real[1], line_real[2], line_real[3]+":"+line_real[4], line_real[5], line_real[6]);
                        var thisrepo = { type : line_real[2], url: line_real[3]+":"+line_real[4], updateinterval: line_real[5], expiretime: line_real[6] };
                        global.repoproxy.repo[line_real[1]] = thisrepo;
-                       
                        break;
+                       
                case "cachedir":
                        var tmppath = line_real[1].replace(/\/+/g, "/");
-                       console.log("Cache dir set to: ", tmppath);
+                       log.info("Cache dir set to: ", tmppath);
                        global.repoproxy.cacheDir = tmppath;
                        break;
+                       
                case "listenport":
-                       console.log("Port set to: ", line_real[1]);
+                       log.info("Port set to: ", line_real[1]);
                        global.repoproxy.listenPort = line_real[1];
                        break;
+                       
                case "cachescan":
-                       console.log("Set cache scan rate to: '%s' hours", line_real[1]);
+                       log.info("Set cache scan rate to: '%s' hours", line_real[1]);
                        global.repoproxy.scancache = parseInt(line_real[1]);
                        if(global.repoproxy.scancache == 0) {
-                               console.log("Cache scan rate didnt make sense, it was 0, and should be at least 1 - it is set to 24, but you should check this setting");
+                               log.info("Cache scan rate didnt make sense, it was 0, and should be at least 1 - it is set to 24, but you should check this setting");
                                global.repoproxy.scancache = 24;
                        }
                        break;
+                       
                case "loggerlevel":
                        global.repoproxy.loglevel = parseInt(line_real[1]);
-                       console.log("log level set to: ", global.repoproxy.loglevel);
+                       log.info("log level set to: ", global.repoproxy.loglevel);
                        break;
+                       
                default:
                        if(line_real[0] != "") {
-                               console.log("WARNING Invalid line in configuration file ignored: '%s'", line_one);
+                               log.info("WARNING Invalid line in configuration file ignored: '%s'", line_one);
                        }
                }
        }
        
        createCacheStructure();
-       log.testLogSettings();
+       //log.testLogSettings();
 }
 
 
@@ -77,40 +81,40 @@ exports.loadConfig = function (conffile) {
 function createCacheStructure() {
        try {
                var state = fs.statSync(global.repoproxy.cacheDir);
-               //console.log("state is:", state);
+               //log.info("state is:", state);
        } catch(e) {
-               //console.log("try failure of cache dir stat ", e);
+               //log.info("try failure of cache dir stat ", e);
                try {
                        fs.mkdirSync(global.repoproxy.cacheDir);
                } catch(ex) {
-                       console.log("ERROR: failure to create cache directory, '%s'", global.repoproxy.cacheDir);
+                       log.error("failure to create cache directory, '%s'", global.repoproxy.cacheDir);
                }
        }
        
        try {
                var state = fs.statSync(global.repoproxy.cacheDir + "/.cleanup");
-               //console.log("state is:", state);
+               //log.info("state is:", state);
        } catch(e) {
                try {
                        fs.mkdirSync(global.repoproxy.cacheDir + "/.cleanup");
                } catch(ex) {
-                       console.log("ERROR: cant create cleanup directory, '%s'", global.repoproxy.cacheDir + "/.cleanup");
+                       log.error("cant create cleanup directory, '%s'", global.repoproxy.cacheDir + "/.cleanup");
                }
        }
        
-       //console.log("next: ", global.repoproxy.repo);
+       //log.info("next: ", global.repoproxy.repo);
        for(var index in global.repoproxy.repo) {
                var fullDir = global.repoproxy.cacheDir + "/" + index;
-               //console.log("on end, ", fullDir);
+               //log.info("on end, ", fullDir);
                try {
                        var state = fs.statSync(fullDir);
-                       //console.log("state is:", state);
+                       //log.info("state is:", state);
                } catch(e) {
                        try {
-                               //console.log("attempted to create cache dir, ", fullDir);
+                               //log.info("attempted to create cache dir, ", fullDir);
                                fs.mkdirSync(fullDir);
                        } catch(ex) {
-                               console.log("ERROR: failed to create cache directory, '%s' for '%s'", fullDir, index);
+                               log.error("failed to create cache directory, '%s' for '%s'", fullDir, index);
                        }
                }
        }