diff options
author | isaacs <i@izs.me> | 2010-08-25 11:05:35 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-08-25 16:21:53 +0400 |
commit | 63a0176d6163a8617b01a6b9e9f7bece655e9050 (patch) | |
tree | 13e310561688ad88d0cc4fee8bdaf9f6377f5c41 /lib | |
parent | 30122afd23076ec207709580553871030b1988c5 (diff) |
Make it a bit prettier
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils/log.js | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/utils/log.js b/lib/utils/log.js index 15cdd37c2..5383513c5 100644 --- a/lib/utils/log.js +++ b/lib/utils/log.js @@ -39,25 +39,29 @@ var l = -1 , verbose : l++ , info : l++ , WARN : l++ - , ERROR : l++ + , "ERR!" : l++ + , ERROR : "ERR!" + , ERR : "ERR!" , win : 0x15AAC5 , silent : 0xDECAFBAD } , COLOR = {} , SHOWLEVEL Object.keys(LEVEL).forEach(function (l) { - LEVEL[LEVEL[l]] = l + if (typeof LEVEL[l] === "string") LEVEL[l] = LEVEL[LEVEL[l]] + else LEVEL[LEVEL[l]] = l LEVEL[l.toLowerCase()] = LEVEL[l] if (l === "silent") return log[l] = log[l.toLowerCase()] = function (msg, pref, cb) { return log(msg, pref, l, cb) } }) -// COLOR[LEVEL.verbose] = '0' +COLOR[LEVEL.silly] = 30 +COLOR[LEVEL.verbose] = 34 COLOR[LEVEL.info] = 32 COLOR[LEVEL.warn] = 33 COLOR[LEVEL.error] = 31 for (var c in COLOR) COLOR[LEVEL[c]] = COLOR[c] -COLOR.npm = 37 +COLOR.npm = "37;40" COLOR.pref = 35 var logBuffer = [] @@ -111,7 +115,8 @@ function log (msg, pref, level, cb) { if (!isFinite(level) || level < show) return cb && cb() // console.error("level, showlevel, show", level, show, (level >= show)) pref = colorize("npm", COLOR.npm) - + (COLOR[level] ? " "+colorize(LEVEL[level], COLOR[level]) : "") + + (COLOR[level] ? " "+colorize( + (LEVEL[level]+spaces).substr(0,4), COLOR[level]) : "") + (pref && COLOR.pref ? " " + colorize(pref, COLOR.pref) : "") if (msg.indexOf("\n") !== -1) { msg = msg.split(/\n/).join("\n"+pref+" ") @@ -120,7 +125,7 @@ function log (msg, pref, level, cb) { sys.error(msg) cb && cb() } - +var spaces = " " log.er = function (cb, msg) { if (!msg) throw new Error( "Why bother logging it if you're not going to print a message?") |