Permalink
Browse files

Replace the log util with npmlog module

This feels so good.  lib/utils/log.js is the worst kind of
glue code that keeps the npm project from being properly
abstracted into independent pieces.

In the process, also cleaned up a lot of unproductive logging,
and made the npm-debug.log generated on errors be a bit more
easy to read.
  • Loading branch information...
1 parent d4b2d11 commit 2568e40a395b809fb34125b3383f9f2616004f73 @isaacs isaacs committed Jun 6, 2012
Showing with 498 additions and 621 deletions.
  1. +6 −6 bin/npm-cli.js
  2. +5 −16 doc/cli/coding-style.md
  3. +0 −22 doc/cli/config.md
  4. +2 −2 lib/adduser.js
  5. +2 −2 lib/bugs.js
  6. +9 −9 lib/build.js
  7. +78 −43 lib/cache.js
  8. +2 −2 lib/config.js
  9. +0 −1 lib/deprecate.js
  10. +2 −2 lib/docs.js
  11. +0 −1 lib/edit.js
  12. +5 −2 lib/help-search.js
  13. +3 −1 lib/help.js
  14. +4 −5 lib/init.js
  15. +35 −32 lib/install.js
  16. +7 −4 lib/link.js
  17. +5 −3 lib/ls.js
  18. +14 −6 lib/npm.js
  19. +0 −1 lib/outdated.js
  20. +28 −16 lib/owner.js
  21. +9 −9 lib/publish.js
  22. +4 −4 lib/rebuild.js
  23. +0 −1 lib/root.js
  24. +2 −2 lib/run-script.js
  25. +0 −1 lib/search.js
  26. +3 −3 lib/shrinkwrap.js
  27. +2 −2 lib/star.js
  28. +12 −2 lib/substack.js
  29. +1 −1 lib/unbuild.js
  30. +3 −3 lib/uninstall.js
  31. +6 −2 lib/unpublish.js
  32. +2 −2 lib/update.js
  33. +3 −3 lib/utils/cmd-shim.js
  34. +4 −4 lib/utils/completion/users.js
  35. +8 −15 lib/utils/config-defs.js
  36. +55 −48 lib/utils/error-handler.js
  37. +3 −37 lib/utils/exec.js
  38. +4 −4 lib/utils/fetch.js
  39. +4 −4 lib/utils/ini.js
  40. +11 −14 lib/utils/lifecycle.js
  41. +0 −1 lib/utils/link.js
  42. +4 −4 lib/utils/load-package-defaults.js
  43. +0 −170 lib/utils/log.js
  44. +6 −6 lib/utils/npm-registry-client/adduser.js
  45. +6 −6 lib/utils/npm-registry-client/get.js
  46. +17 −15 lib/utils/npm-registry-client/publish.js
  47. +9 −9 lib/utils/npm-registry-client/request.js
  48. +3 −3 lib/utils/npm-registry-client/star.js
  49. +17 −10 lib/utils/npm-registry-client/unpublish.js
  50. +4 −4 lib/utils/read-installed.js
  51. +18 −18 lib/utils/read-json.js
  52. +10 −7 lib/utils/sha.js
  53. +49 −23 lib/utils/tar.js
  54. +5 −2 lib/version.js
  55. +2 −2 lib/view.js
  56. +0 −1 lib/whoami.js
  57. +5 −3 lib/xmas.js
View
@@ -15,9 +15,9 @@ if (typeof WScript !== "undefined") {
process.title = "npm"
-var log = require("../lib/utils/log.js")
-log.waitForConfig()
-log.info("ok", "it worked if it ends with")
+var log = require("npmlog")
+log.pause() // will be unpaused when config is loaded.
+log.info("it worked if it ends with", "ok")
var fs = require("graceful-fs")
, path = require("path")
@@ -36,7 +36,7 @@ if (path.basename(process.argv[1]).slice(-1) === "g") {
process.argv.splice(1, 1, "npm", "-g")
}
-log.verbose(process.argv, "cli")
+log.verbose("cli", process.argv)
var conf = nopt(types, shorthands)
npm.argv = conf.argv.remain
@@ -56,8 +56,8 @@ if (conf.versions) {
return
}
-log.info("npm@"+npm.version, "using")
-log.info("node@"+process.version, "using")
+log.info("using", "npm@%s", npm.version)
+log.info("using", "node@%s", process.version)
// make sure that this version of node works with this version of npm.
var semver = require("semver")
View
@@ -129,29 +129,18 @@ Just send the error message back as the first argument to the callback.
Always create a new Error object with your message. Don't just return a
string message to the callback. Stack traces are handy.
-Use the `require("./utils/log").er` function. It takes a callback and an
-error message, and returns an object that will report the message in the
-event of a failure. It's quite handy.
-
- function myThing (args, cb) {
- getData(args, function (er, data) {
- if (er) return log.er(cb, "Couldn't get data")(er)
- doSomethingElse(data, cb)
- })
- }
- function justHasToWork (cb) {
- doSomething(log.er(cb, "the doSomething failed."))
- }
-
## Logging
+Logging is done using the [npmlog](https://github.com/isaacs/npmlog)
+utility.
+
Please clean up logs when they are no longer helpful. In particular,
logging the same object over and over again is not helpful. Logs should
report what's happening so that it's easier to track down where a fault
occurs.
-Use appropriate log levels. The default log() function logs at the
-"info" level. See `npm-config(1)` and search for "loglevel".
+Use appropriate log levels. See `npm-config(1)` and search for
+"loglevel".
## Case, naming, etc.
View
@@ -430,13 +430,6 @@ if one of the two conditions are met:
* the globally installed version is identical to the version that is
being installed locally.
-### logfd
-
-* Default: stderr file descriptor
-* Type: Number or Stream
-
-The location to write log output.
-
### loglevel
* Default: "http"
@@ -449,14 +442,6 @@ What level of logs to report. On failure, *all* logs are written to
Any logs of a higher level than the setting are shown.
The default is "http", which shows http, warn, and error output.
-### logprefix
-
-* Default: true on Posix, false on Windows
-* Type: Boolean
-
-Whether or not to prefix log messages with "npm" and the log level. See
-also "color" and "loglevel".
-
### long
* Default: false
@@ -503,13 +488,6 @@ The url to report npat test results.
A node module to `require()` when npm loads. Useful for programmatic
usage.
-### outfd
-
-* Default: standard output file descriptor
-* Type: Number or Stream
-
-Where to write "normal" output. This has no effect on log output.
-
### parseable
* Default: false
View
@@ -3,7 +3,7 @@ module.exports = adduser
var registry = require("./utils/npm-registry-client/index.js")
, ini = require("./utils/ini.js")
- , log = require("./utils/log.js")
+ , log = require("npmlog")
, npm = require("./npm.js")
, read = require("read")
, promiseChain = require("./utils/promise-chain.js")
@@ -42,7 +42,7 @@ 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, "adduser")
+ log.info("adduser", "Authorized user %s", u.u)
ini.save("user", cb)
})
})
View
@@ -13,7 +13,7 @@ bugs.completion = function (opts, cb) {
var exec = require("./utils/exec.js")
, registry = require("./utils/npm-registry-client/index.js")
, npm = require("./npm.js")
- , log = require("./utils/log.js")
+ , log = require("npmlog")
function bugs (args, cb) {
if (!args.length) return cb(bugs.usage)
@@ -29,7 +29,7 @@ function bugs (args, cb) {
if (repo) {
if (Array.isArray(repo)) repo = repo.shift()
if (repo.hasOwnProperty("url")) repo = repo.url
- log.verbose(repo, "repository")
+ log.verbose("repository", repo)
if (repo && repo.match(/^(https?:\/\/|git(:\/\/|@))github.com/)) {
return open(repo.replace(/^git(@|:\/\/)/, "http://")
.replace(/^https?:\/\/github.com:/, "github.com/")
View
@@ -9,7 +9,7 @@
// This runs AFTER install or link are completed.
var npm = require("./npm.js")
- , log = require("./utils/log.js")
+ , log = require("npmlog")
, chain = require("slide").chain
, fs = require("graceful-fs")
, path = require("path")
@@ -44,7 +44,7 @@ function build (args, global, didPre, didRB, cb) {
function build_ (global, didPre, didRB) { return function (folder, cb) {
folder = path.resolve(folder)
build._didBuild[folder] = true
- log.info(folder, "build")
+ log.info("build", folder)
readJson(path.resolve(folder, "package.json"), function (er, pkg) {
if (er) return cb(er)
chain
@@ -76,17 +76,17 @@ function linkStuff (pkg, folder, global, didRB, cb) {
, top = parent === npm.dir
, gtop = parent === gnm
- log.verbose([global, gnm, gtop, parent], "linkStuff")
- log(pkg._id, "linkStuff")
+ log.verbose("linkStuff", [global, gnm, gtop, parent])
+ log.info("linkStuff", pkg._id)
if (top && pkg.preferGlobal && !global) {
- log.warn(pkg._id + " should be installed with -g", "prefer global")
+ log.warn("prefer global", pkg._id + " should be installed with -g")
}
asyncMap( [linkBins, linkMans, !didRB && rebuildBundles]
, function (fn, cb) {
if (!fn) return cb()
- log.verbose(pkg._id, fn.name)
+ log.verbose(fn.name, pkg._id)
fn(pkg, folder, parent, gtop, cb)
}, cb)
}
@@ -102,7 +102,7 @@ function rebuildBundles (pkg, folder, parent, gtop, cb) {
// error means no bundles
if (er) return cb()
- log.verbose(files, "rebuildBundles")
+ log.verbose("rebuildBundles", files)
// don't asyncMap these, because otherwise build script output
// gets interleaved and is impossible to read
chain(files.filter(function (file) {
@@ -117,7 +117,7 @@ function rebuildBundles (pkg, folder, parent, gtop, cb) {
file = path.resolve(folder, "node_modules", file)
return function (cb) {
if (build._didBuild[file]) return cb()
- log.verbose(file, "rebuild bundle")
+ log.verbose("rebuild bundle", file)
// if file is not a package dir, then don't do it.
fs.lstat(path.resolve(file, "package.json"), function (er, st) {
if (er) return cb()
@@ -133,7 +133,7 @@ function linkBins (pkg, folder, parent, gtop, cb) {
}
var binRoot = gtop ? npm.globalBin
: path.resolve(parent, ".bin")
- log.verbose([pkg.bin, binRoot, gtop], "bins linking")
+ log.verbose("link bins", [pkg.bin, binRoot, gtop])
asyncMap(Object.keys(pkg.bin), function (b, cb) {
linkBin( path.resolve(folder, pkg.bin[b])
Oops, something went wrong.

0 comments on commit 2568e40

Please sign in to comment.