From 53c7e2cc802bc083a8e9d72d5b27e2a37fc5c951 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Sun, 17 Jun 2012 16:18:19 +1000 Subject: [PATCH] `logstream` option to replace removed `logfd` --- doc/cli/config.md | 12 ++++++++++++ lib/npm.js | 1 + lib/utils/config-defs.js | 11 +++++++++++ lib/utils/lifecycle.js | 2 ++ 4 files changed, 26 insertions(+) diff --git a/doc/cli/config.md b/doc/cli/config.md index d9d94bcd..505b9bac 100644 --- a/doc/cli/config.md +++ b/doc/cli/config.md @@ -427,6 +427,18 @@ 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. +### logstream + +* Default: process.stderr +* Type: Stream + +This is the stream that is passed to the +[npmlog](https://github.com/isaacs/npmlog) module at run time. + +It cannot be set from the command line, but if you are using npm +programmatically, you may wish to send logs to somewhere other than +stderr. + ### long * Default: false diff --git a/lib/npm.js b/lib/npm.js index 9b954591..5b257d67 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -263,6 +263,7 @@ function load (npm, conf, cb) { ini.resolveConfigs(conf, function (er) { log.level = npm.config.get("loglevel") log.heading = "npm" + log.stream = npm.config.get("logstream") switch (npm.config.get("color")) { case "always": log.enableColor(); break case false: log.disableColor(); break diff --git a/lib/utils/config-defs.js b/lib/utils/config-defs.js index fb87af29..f7f01462 100644 --- a/lib/utils/config-defs.js +++ b/lib/utils/config-defs.js @@ -28,8 +28,14 @@ function validateSemver (data, k, val) { data[k] = semver.valid(val) } +function validateStream (data, k, val) { + if (!(val instanceof Stream)) return false + data[k] = val +} + nopt.typeDefs.semver = { type: semver, validate: validateSemver } nopt.typeDefs.Octal = { type: Octal, validate: validateOctal } +nopt.typeDefs.Stream = { type: Stream, validate: validateStream } nopt.invalidHandler = function (k, val, type, data) { log.warn("invalid config", k + "=" + JSON.stringify(val)) @@ -52,6 +58,9 @@ nopt.invalidHandler = function (k, val, type, data) { case Number: log.warn("invalid config", "Must be a numeric value") break + case Stream: + log.warn("invalid config", "Must be an instance of the Stream class") + break } } @@ -141,6 +150,7 @@ Object.defineProperty(exports, "defaults", {get: function () { , json: false , link: false , loglevel : "http" + , logstream : process.stderr , long : false , message : "%s" , "node-version" : process.version @@ -222,6 +232,7 @@ exports.types = , json: Boolean , link: Boolean , loglevel : ["silent","win","error","warn","http","info","verbose","silly"] + , logstream : Stream , long : Boolean , message: String , "node-version" : [null, semver] diff --git a/lib/utils/lifecycle.js b/lib/utils/lifecycle.js index 7fc5e711..90b5002b 100644 --- a/lib/utils/lifecycle.js +++ b/lib/utils/lifecycle.js @@ -10,6 +10,7 @@ var log = require("npmlog") , chain = require("slide").chain , constants = require("constants") , output = require("./output.js") + , Stream = require("stream").Stream , PATH = "PATH" // windows calls it's path "Path" usually, but this is not guaranteed. @@ -260,6 +261,7 @@ function makeEnv (data, prefix, env) { return } var value = ini.get(i) + if (value instanceof Stream) return if (!value) value = "" else if (typeof value !== "string") value = JSON.stringify(value)