Skip to content

Commit

Permalink
Add 'http' loglevel, by default
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Dec 8, 2011
1 parent 759c1fa commit 4e5130b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 26 deletions.
7 changes: 5 additions & 2 deletions doc/cli/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,16 @@ The location to write log output.

### loglevel

* Default: "warn"
* Default: "http"
* Type: String
* Values: "silent", "win", "error", "warn", "info", "verbose", "silly"
* Values: "silent", "win", "error", "warn", "http", "info", "verbose", "silly"

What level of logs to report. On failure, *all* logs are written to
`npm-debug.log` in the current working directory.

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
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/config-defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Object.defineProperty(exports, "defaults", {get: function () {
, "init.author.url" : ""
, link: false
, logfd : 2
, loglevel : "warn"
, loglevel : "http"
, logprefix : process.platform !== "win32" || winColor
, long : false
, message : "%s"
Expand Down Expand Up @@ -236,7 +236,7 @@ exports.types =
, "init.author.url" : ["", url]
, link: Boolean
, logfd : [Number, Stream]
, loglevel : ["silent","win","error","warn","info","verbose","silly"]
, loglevel : ["silent","win","error","warn","http","info","verbose","silly"]
, logprefix : Boolean
, long : Boolean
, message: String
Expand Down
9 changes: 7 additions & 2 deletions lib/utils/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = fetch

function fetch (remote, local, headers, cb) {
if (typeof cb !== "function") cb = headers, headers = {}
log.info(remote, "fetch")
log.verbose(local, "fetch to")
mkdir(path.dirname(local), function (er) {
if (er) return cb(er)
Expand All @@ -42,6 +41,7 @@ function fetch_ (remote, local, headers, cb) {

function makeRequest (remote, fstr, headers) {
remote = url.parse(remote)
log.http(remote.pathname, "GET")
regHost = regHost || url.parse(npm.config.get("registry")).host

if (remote.host === regHost && npm.config.get("always-auth")) {
Expand All @@ -58,5 +58,10 @@ function makeRequest (remote, fstr, headers) {
request({ url: remote
, proxy: proxy
, agent: getAgent(remote)
, strictSSL: npm.config.get("strict-ssl") }).pipe(fstr)
, strictSSL: npm.config.get("strict-ssl")
, onResponse: onResponse }).pipe(fstr)
function onResponse (er, res) {
if (er) return cb(er)
log.http(res.statusCode + " " + remote.pathname)
}
}
19 changes: 2 additions & 17 deletions lib/utils/log.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@

/*
log levels:
0,1,2,3
verbose,info,warn,error
Default setting for logs is "info"
Default setting to show is "info"
Possible values of level/loglevel:
silly,verbose,info,warn,error,win,silent
silent quiets everything
*/


module.exports = log

var output = require("./output.js")
Expand All @@ -28,6 +11,7 @@ var l = -1
, LEVEL = { silly : l++
, verbose : l++
, info : l++
, "http" : l++
, WARN : l++
, "ERR!" : l++
, ERROR : "ERR!"
Expand Down Expand Up @@ -59,6 +43,7 @@ Object.keys(LEVEL).forEach(function (l) {
COLOR[LEVEL.silly] = 30
COLOR[LEVEL.verbose] = "34;40"
COLOR[LEVEL.info] = 32
COLOR[LEVEL.http] = "32;40"
COLOR[LEVEL.warn] = "30;41"
COLOR[LEVEL.error] = "31;40"
for (var c in COLOR) COLOR[LEVEL[c]] = COLOR[c]
Expand Down
6 changes: 4 additions & 2 deletions lib/utils/npm-registry-client/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ function regRequest (method, where, what, etag, nofollow, cb_) {
if (typeof cb_ !== "function") cb_ = etag, etag = null
if (typeof cb_ !== "function") cb_ = what, what = null

log.verbose(where||"/", method)

// Since there are multiple places where an error could occur,
// don't let the cb be called more than once.
var errState = null
Expand Down Expand Up @@ -119,6 +117,8 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb) {
opts.followRedirect = false
}

log.http(remote.pathname || "/", method)

var req = request(opts, requestDone(method, where, cb))
var r = npm.config.get("registry")
if (!r) {
Expand All @@ -136,6 +136,8 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb) {
function requestDone (method, where, cb) { return function (er, response, data) {
if (er) return cb(er)

log.http(response.statusCode + " " + url.parse(where).pathname)

var parsed

if (Buffer.isBuffer(data)) {
Expand Down
5 changes: 4 additions & 1 deletion lib/utils/tar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ exports.makeList = makeList

function pack (targetTarball, folder, pkg, dfc, cb) {
if (typeof cb !== "function") cb = dfc, dfc = true
folder = path.resolve(process.cwd(), folder)
folder = path.resolve(folder)

log.verbose(folder, "pack")

if (typeof pkg === "function") {
cb = pkg, pkg = null
return readJson(path.resolve(folder, "package.json"), function (er, pkg) {
Expand Down

0 comments on commit 4e5130b

Please sign in to comment.