diff options
author | isaacs <i@izs.me> | 2010-08-24 10:03:28 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-08-24 10:05:17 +0400 |
commit | 177bb5f4b4d2483101ebf7ef7d43754f703236a3 (patch) | |
tree | 54d5c241e33302d40ac6f384e9e5e6bfb9234a03 | |
parent | 50999ff18d7ef6b12599ae8e5fb502be39381d5f (diff) |
log better
-rw-r--r-- | lib/adduser.js | 6 | ||||
-rw-r--r-- | lib/build.js | 12 | ||||
-rw-r--r-- | lib/cache.js | 2 | ||||
-rw-r--r-- | lib/install.js | 14 | ||||
-rw-r--r-- | lib/link.js | 11 | ||||
-rw-r--r-- | lib/owner.js | 4 | ||||
-rw-r--r-- | lib/publish.js | 4 | ||||
-rw-r--r-- | lib/uninstall.js | 8 | ||||
-rw-r--r-- | lib/utils/log.js | 10 |
9 files changed, 30 insertions, 41 deletions
diff --git a/lib/adduser.js b/lib/adduser.js index 8d428f189..ac612c110 100644 --- a/lib/adduser.js +++ b/lib/adduser.js @@ -42,10 +42,8 @@ function adduser (args, cb) { ini.set("username", u.u, "user") ini.set("_password", u.p, "user") ini.set("email", u.e, "user") - log( "Authorized user " + u.u - + " and configured authentication credentials for npm." - , "adduser") - log("Remember to clear your shell history!", "adduser") + log("Authorized user " + u.u, "adduser") + log.warn("Remember to clear your shell history!", "adduser") ini.save(cb) }) }) diff --git a/lib/build.js b/lib/build.js index 1ee2ec91f..784a62544 100644 --- a/lib/build.js +++ b/lib/build.js @@ -59,7 +59,7 @@ function buildStep (pkg, cb) { } function autoUpdate (pkg, cb) { var auto = npm.config.get("update-dependents") - if (!auto) return log( + if (!auto) return log.verbose( "update-dependents disabled by config", "update-dependents", cb) pkg = pkg && pkg._data || pkg if (auto === "always") { @@ -72,14 +72,14 @@ function autoUpdate (pkg, cb) { .sort(semver.sort) , maxHave = versions.pop() if (!maxHave) return cb() - if (!semver.gt(pkg.version, maxHave)) return log( + if (!semver.gt(pkg.version, maxHave)) return log.verbose( "downgrade, not updating dependencencies", "update-dependents", cb) npm.commands["update-dependents"]([pkg], cb) }) } function autoActivate (pkg, cb) { var auto = npm.config.get("auto-activate") - if (!auto) return log( + if (!auto) return log.verbose( "auto-activate disabled by config", "auto-activate", cb) pkg = pkg && pkg._data || pkg // get the list of versions of this package. @@ -89,7 +89,7 @@ function autoActivate (pkg, cb) { if (auto !== "always" && versions.indexOf("active") !== -1) { log("another version already active", "auto-activate") log("to activate, do: npm activate "+ - pkg.name+" "+pkg.version, "auto-activate") + pkg.name+"@"+pkg.version, "auto-activate") return cb() } log(pkg.name+"@"+pkg.version, "activate") @@ -119,7 +119,7 @@ function resolveDependencies (pkg, cb) { asyncMap(pkg.dependencies && Object.keys(pkg.dependencies), function (i, cb) { var req = { name:i, version:pkg.dependencies[i] } - // log(req.name+"@"+req.version, "required") + log.verbose(req.name+"@"+req.version, "required") // see if we have this thing installed. fs.readdir(path.join(npm.dir, req.name), function (er, versions) { if (er) return cb(new Error( @@ -260,7 +260,7 @@ function linkBins (pkg, cb) { asyncMap(Object.keys(pkg.bin).filter(function (i) { return i.charAt(0) !== "_" }), function (i, cb) { - log(i+" "+pkg.bin[i], "linkBin") + log.verbose(i+" "+pkg.bin[i], "linkBin") var to = path.join(binroot, i+"-"+pkg.version) , from = path.join(npm.dir, pkg.name, pkg.version, "package", pkg.bin[i]) shimTest(from, to, dep, cb) diff --git a/lib/cache.js b/lib/cache.js index c09cb17b5..8a6c22e0d 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -62,7 +62,7 @@ function ls (args, cb) { log("nothing found", "cache") return cb() } - cb(null, files.map(function (f) { log(f, msg); return f })) + cb(null, log(files.join("\n"), msg)) }) }) } diff --git a/lib/install.js b/lib/install.js index 00678127b..faca6ffe9 100644 --- a/lib/install.js +++ b/lib/install.js @@ -73,7 +73,7 @@ function install_ (pkg, reg, seen, mustInstall, pkglist, cb) { // it's a local thing or a url if it has a / in it. if (pkg.indexOf("/") !== -1 || pkg === ".") { - log(pkg, "install local") + log.verbose(pkg, "install local") return cache.add(pkg, finisher(pkg, reg, pkglist, cb)) } @@ -128,8 +128,8 @@ function getData (name, cb) { if (data) return cb(null, data) registry.get(name, function (er, data) { if (data && data.error === "not_found") { - log( "\nIt seems like '"+name+"' is not in the registry\n" - + "You should bug the author to publish it.\n", "! 404 !") + log.error( "\nIt seems like '"+name+"' is not in the registry\n" + + "You should bug the author to publish it.\n", "! 404 !") er = new Error("404 Not Found: "+name) } if (er) return cb(er) @@ -189,7 +189,7 @@ function getDeps (data) { function filterNodeVersion (data) { for (var v in data.versions) { if (!data.versions[v]._nodeSupported) { - log(data._id, "not supported on node@"+process.version) + log.warn(data._id, "not supported on node@"+process.version) delete data.versions[v] } } @@ -216,7 +216,7 @@ function buildAll (installed, cb) { }) } function rollbackFailure (installList, cb) { return function (er) { - if (!er) return log(installList.map(function (i) { + if (!er) return log.verbose(installList.map(function (i) { return i.join("@") }).join("\n"), "installed", cb) // error happened, roll back @@ -224,12 +224,12 @@ function rollbackFailure (installList, cb) { return function (er) { return (""+p).replace(/\//, '@') }) npm.ROLLBACK = true - log(er, "install failed") + log.error(er, "install failed") log("rollback", "install failed") return npm.commands.uninstall ( installList , function (er_) { - if (er_) log(er_, "rollback failed") + if (er_) log.error(er_, "rollback failed") else log("rolled back", "install failed") cb(er) } diff --git a/lib/link.js b/lib/link.js index 3438e6353..fd32643a1 100644 --- a/lib/link.js +++ b/lib/link.js @@ -35,7 +35,7 @@ function link (args, cb) { "npm link requires a directory")) cb() })} - , [log, "reading "+jsonFile, "link"] + , [log.verbose, "reading "+jsonFile, "link"] , [readAndLink, jsonFile, folder] , cb ) @@ -58,7 +58,7 @@ function getDeps (data) { } function doLink (folder, cb) { return function (er, data) { if (er) return cb(er) - log(data.name+" "+data.version, "link") + log.verbose(data.name+" "+data.version, "link") var pkgDir = path.join(npm.dir, data.name, data.version, "package") , deps = getDeps(data) , depNames = Object.keys(deps) @@ -73,7 +73,7 @@ function doLink (folder, cb) { return function (er, data) { var depsNeeded = Object.keys(deps).map(function (d) { return d+"@"+deps[d] }) - log(depsNeeded, "link install deps") + log.verbose(depsNeeded, "link install deps") chain ( depsNeeded.length ? [ npm.commands, "install", depsNeeded.slice(0) ] @@ -83,10 +83,11 @@ function doLink (folder, cb) { return function (er, data) { , function (er) { if (!er) return cb() // error, rollback - log(er, "error linking, rollback") + npm.ROLLBACK = true + log.error(er, "error linking, rollback") var rb = depsNeeded.concat([data.name+"@"+data.version]) npm.commands.rm(rb, function (er_) { - if (er_) log(er_, "error rolling back") + if (er_) log.error(er_, "error rolling back") cb(er) }) } diff --git a/lib/owner.js b/lib/owner.js index f24475ebb..718a6f5e3 100644 --- a/lib/owner.js +++ b/lib/owner.js @@ -32,7 +32,7 @@ function ls (pkg, cb) { } function add (user, pkg, cb) { - log(user+" to "+pkg, "owner add") + log.verbose(user+" to "+pkg, "owner add") mutate(pkg, user, function (u, owners) { if (!owners) owners = [] for (var i = 0, l = owners.length; i < l; i ++) { @@ -49,7 +49,7 @@ function add (user, pkg, cb) { }, cb) } function rm (user, pkg, cb) { - log(user+" from "+pkg, "owner rm") + log.verbose(user+" from "+pkg, "owner rm") mutate(pkg, user, function (u, owners) { var found = false , m = owners.filter(function (o) { diff --git a/lib/publish.js b/lib/publish.js index 8834b41fe..0c7481999 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -7,10 +7,10 @@ var npm = require("../npm") function publish (args, cb) { if (args.length === 0) args = ["."] - log(args, "publish") + log.verbose(args, "publish") npm.commands.cache.add(args[0], args[1], function (er, data) { if (er) return cb(er) - log(data, "publish") + log.verbose(data, "publish") if (!data) return cb(new Error("no data!?")) registry.publish(data, cb) }) diff --git a/lib/uninstall.js b/lib/uninstall.js index 04c4103f4..6a199f370 100644 --- a/lib/uninstall.js +++ b/lib/uninstall.js @@ -18,12 +18,6 @@ var rm = require("./utils/rm-rf") , mkdir = require("./utils/mkdir-p") function uninstall (args, cb) { - // TODO: remove this when it's more commonplace. - if (args.length === 2 && !semver.valid(args[0]) && semver.valid(args[1]) - || args.length === 0) { - log("http://github.com/isaacs/npm/issues/issue/91", "See:") - return cb(new Error("Usage: npm uninstall <pkg>[@<version>] [pkg[@<version>] ...]")) - } // for each arg: // unpack if no version found @@ -48,7 +42,7 @@ function unpackArgs (rawArgs, cb) { , pkg = arg[0] || "" arg = arg.join("@") if (!installed.hasOwnProperty(pkg)) return log(arg, "not installed") - log(Object.keys(installed[pkg]), "installed "+pkg) + log.verbose( Object.keys(installed[pkg]).join("\n"), "installed "+pkg) Object.keys(installed[pkg]).forEach(function (v) { if (semver.satisfies(v, ver)) args.push([pkg, v]) }) diff --git a/lib/utils/log.js b/lib/utils/log.js index 2f2650d57..0952f65f1 100644 --- a/lib/utils/log.js +++ b/lib/utils/log.js @@ -67,7 +67,9 @@ function log (msg, pref, level, cb) { var show if (typeof SHOWLEVEL !== "undefined") { show = SHOWLEVEL - // if (!isFinite(show)) return cb && cb() + if (show === LEVEL.silent || show === "silent") { + return cb && cb() + } } else { show = npm.config.get("loglevel") if (!show) return logBuffer.push(arguments) @@ -80,12 +82,6 @@ function log (msg, pref, level, cb) { if (isNaN(show)) show = LEVEL[show] else show = +show } - // console.error("logBuffer", logBuffer) - // if (logBuffer.length) logBuffer.forEach(function (l) { - // log.apply(null, l) - // }) - // logBuffer.length = 0 - if (level == null) level = LEVEL.info if (isNaN(level)) level = LEVEL[level] else level = +level |