Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2010-08-25 13:57:38 +0400
committerisaacs <i@izs.me>2010-08-25 16:21:53 +0400
commit2e7fb6c7cc049cd11b02f369182f3ca2e1eed01c (patch)
tree5f5d0d9aa3053fa0d7ad7801fb406daa8ec242d4
parent7501ac40c9d81cf39ffdd6ed0bf30e936910ca37 (diff)
Make the show level a getter/setter
-rw-r--r--lib/utils/log.js47
1 files changed, 27 insertions, 20 deletions
diff --git a/lib/utils/log.js b/lib/utils/log.js
index 5383513c5..27306f64d 100644
--- a/lib/utils/log.js
+++ b/lib/utils/log.js
@@ -8,7 +8,7 @@ Default setting for logs is "info"
Default setting to show is "info"
Possible values of level/loglevel:
-verbose,info,warn,error,win,silent
+silly,verbose,info,warn,error,win,silent
silent quiets everything
@@ -47,6 +47,7 @@ var l = -1
}
, COLOR = {}
, SHOWLEVEL
+log.LEVEL = LEVEL
Object.keys(LEVEL).forEach(function (l) {
if (typeof LEVEL[l] === "string") LEVEL[l] = LEVEL[LEVEL[l]]
else LEVEL[LEVEL[l]] = l
@@ -69,26 +70,32 @@ var logBuffer = []
, waitForConfig
log.waitForConfig = function () { waitForConfig = true }
-function log (msg, pref, level, cb) {
- if (typeof level === "function") cb = level, level = null
- var show
- if (typeof SHOWLEVEL !== "undefined") {
- show = SHOWLEVEL
- if (show === LEVEL.silent || show === "silent") {
- return cb && cb()
+
+
+Object.defineProperty(log, "level",
+ { get : function () {
+ if (typeof SHOWLEVEL !== "undefined") return SHOWLEVEL
+ var show = npm.config.get("loglevel")
+ if (!show) return logBuffer.push(arguments)
+ show = show.split(",")[0]
+ if (!isNaN(show)) show = +show
+ else if (!LEVEL.hasOwnProperty(show)) {
+ sys.error("Invalid loglevel config: "+JSON.stringify(show))
+ show = "info"
+ }
+ if (isNaN(show)) show = LEVEL[show]
+ else show = +show
+ return SHOWLEVEL = show
}
- } else {
- show = npm.config.get("loglevel")
- if (!show) return logBuffer.push(arguments)
- show = show.split(",")[0]
- if (!isNaN(show)) show = +show
- else if (!LEVEL.hasOwnProperty(show)) {
- sys.error("Invalid loglevel config: "+JSON.stringify(show))
- show = "info"
+ , set : function (l) {
+ SHOWLEVEL = undefined
+ npm.config.set("showlevel", l)
}
- if (isNaN(show)) show = LEVEL[show]
- else show = +show
- }
+ })
+function log (msg, pref, level, cb) {
+ if (typeof level === "function") cb = level, level = null
+ var show = log.level
+ if (show === LEVEL.silent) return cb && cb()
if (level == null) level = LEVEL.info
if (isNaN(level)) level = LEVEL[level]
else level = +level
@@ -110,7 +117,7 @@ function log (msg, pref, level, cb) {
delete logBuffer.discharging
return
}
- SHOWLEVEL = show
+ log.level = show
if (!isFinite(level) || level < show) return cb && cb()
// console.error("level, showlevel, show", level, show, (level >= show))