Or if you don't want to use the util.format and just pass the arguments to
clim.logWrite, you can use noFormat option to do that:
var console = require("clim")("", {}, { noFormat: true, patch: false});console.log("message")
Prefix Inheriting
Add prefix to your log messages by passing it as the first argument:
var console = require("clim")("myapp");console.log("message");
Sun Sep 30 2012 16:45:57 GMT+0300 (EEST) INFO myapp message
Inherit prefixes from some other console object by passing it as the second
parameter:
var clim = require("clim");var console = clim("myapp");console.log("message");function somefunc(){ var logger = clim("somefunc", console); logger.warn("in function");}somefunc();
Sun Sep 30 2012 16:59:12 GMT+0300 (EEST) INFO myapp messageSun Sep 30 2012 16:59:12 GMT+0300 (EEST) WARNING myapp somefunc in function
Customizing
Change date format by overriding getTime:
clim.getTime = function(){ return new Date().toString();};
Change global log target and formatting details by overriding logWrite:
clim.logWrite = function(level, prefixes, msg) { // Default implementation writing to stderr var line = clim.getTime() + " " + level; if (prefixes.length > 0) line += " " + prefixes.join(" "); line += " " + msg; process.stderr.write(line + "\n"); // or post it web service, save to database etc...};
Design Philosophies
Keep the same api as in the original console object