diff options
author | isaacs <i@izs.me> | 2012-06-07 01:11:09 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-06-07 01:56:35 +0400 |
commit | efbf0276ae474bf2cfc7ca068e628d92e605b83d (patch) | |
tree | 45bfaf30ca6bf15fb86b7895abff3167ae1ccb8a /node_modules/npmlog | |
parent | a0d858930c1afd00eff38c03a113437dc192411c (diff) |
update npmlog
Diffstat (limited to 'node_modules/npmlog')
-rw-r--r-- | node_modules/npmlog/LICENSE | 25 | ||||
-rw-r--r-- | node_modules/npmlog/README.md | 17 | ||||
-rw-r--r-- | node_modules/npmlog/example.js | 39 | ||||
-rw-r--r-- | node_modules/npmlog/log.js | 16 | ||||
-rw-r--r-- | node_modules/npmlog/package.json | 7 | ||||
-rw-r--r-- | node_modules/npmlog/test/basic.js | 461 |
6 files changed, 551 insertions, 14 deletions
diff --git a/node_modules/npmlog/LICENSE b/node_modules/npmlog/LICENSE new file mode 100644 index 000000000..74489e2e2 --- /dev/null +++ b/node_modules/npmlog/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) Isaac Z. Schlueter +All rights reserved. + +The BSD License + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/node_modules/npmlog/README.md b/node_modules/npmlog/README.md index 590d1c0de..ad67688d7 100644 --- a/node_modules/npmlog/README.md +++ b/node_modules/npmlog/README.md @@ -96,13 +96,16 @@ Emit all buffered messages that were written while paused. Emit a log message at the specified level. -## log[level](prefix, message, ...) -## log.silly(prefix, message, ...) -## log.verbose(prefix, message, ...) -## log.info(prefix, message, ...) -## log.http(prefix, message, ...) -## log.warn(prefix, message, ...) -## log.error(prefix, message, ...) +## log\[level](prefix, message, ...) + +For example, + +* log.silly(prefix, message, ...) +* log.verbose(prefix, message, ...) +* log.info(prefix, message, ...) +* log.http(prefix, message, ...) +* log.warn(prefix, message, ...) +* log.error(prefix, message, ...) Like `log.log(level, prefix, message, ...)`. In this way, each level is given a shorthand, so you can do `log.info(prefix, message)`. diff --git a/node_modules/npmlog/example.js b/node_modules/npmlog/example.js new file mode 100644 index 000000000..c009fb157 --- /dev/null +++ b/node_modules/npmlog/example.js @@ -0,0 +1,39 @@ +var log = require('./log.js') + +log.heading = 'npm' + +console.error('log.level=silly') +log.level = 'silly' +log.silly('silly prefix', 'x = %j', {foo:{bar:'baz'}}) +log.verbose('verbose prefix', 'x = %j', {foo:{bar:'baz'}}) +log.info('info prefix', 'x = %j', {foo:{bar:'baz'}}) +log.http('http prefix', 'x = %j', {foo:{bar:'baz'}}) +log.warn('warn prefix', 'x = %j', {foo:{bar:'baz'}}) +log.error('error prefix', 'x = %j', {foo:{bar:'baz'}}) +log.silent('silent prefix', 'x = %j', {foo:{bar:'baz'}}) + +console.error('log.level=silent') +log.level = 'silent' +log.silly('silly prefix', 'x = %j', {foo:{bar:'baz'}}) +log.verbose('verbose prefix', 'x = %j', {foo:{bar:'baz'}}) +log.info('info prefix', 'x = %j', {foo:{bar:'baz'}}) +log.http('http prefix', 'x = %j', {foo:{bar:'baz'}}) +log.warn('warn prefix', 'x = %j', {foo:{bar:'baz'}}) +log.error('error prefix', 'x = %j', {foo:{bar:'baz'}}) +log.silent('silent prefix', 'x = %j', {foo:{bar:'baz'}}) + +console.error('log.level=info') +log.level = 'info' +log.silly('silly prefix', 'x = %j', {foo:{bar:'baz'}}) +log.verbose('verbose prefix', 'x = %j', {foo:{bar:'baz'}}) +log.info('info prefix', 'x = %j', {foo:{bar:'baz'}}) +log.http('http prefix', 'x = %j', {foo:{bar:'baz'}}) +log.warn('warn prefix', 'x = %j', {foo:{bar:'baz'}}) +log.error('error prefix', 'x = %j', {foo:{bar:'baz'}}) +log.silent('silent prefix', 'x = %j', {foo:{bar:'baz'}}) +log.error('404', 'This is a longer\n'+ + 'message, with some details\n'+ + 'and maybe a stack.\n'+ + new Error('a 404 error').stack) +log.addLevel('noise', 10000, {beep: true}) +log.noise(false, 'LOUD NOISES') diff --git a/node_modules/npmlog/log.js b/node_modules/npmlog/log.js index aef6c9d82..320788e7a 100644 --- a/node_modules/npmlog/log.js +++ b/node_modules/npmlog/log.js @@ -49,14 +49,22 @@ log.log = function (lvl, prefix, message) { } var a = new Array(arguments.length - 2) + var stack = null for (var i = 2; i < arguments.length; i ++) { - a[i-2] = arguments[i] + var arg = a[i-2] = arguments[i] + + // resolve stack traces to a plain string. + if (typeof arg === 'object' && arg && + (arg instanceof Error) && arg.stack) { + arg.stack = stack = arg.stack + '' + } } + if (stack) a.unshift(stack + '\n') message = util.format.apply(util, a) var m = { id: id++, level: lvl, - prefix: prefix, + prefix: String(prefix || ''), message: message, messageRaw: a } @@ -139,8 +147,8 @@ log.levels = {} log.disp = {} log.addLevel('silly', -Infinity, { inverse: true }, 'sill') log.addLevel('verbose', 1000, { fg: 'blue', bg: 'black' }, 'verb') -log.addLevel('info', 2000, { fg: 'green', inverse: true }) -log.addLevel('http', 3000, { fg: 'green' }) +log.addLevel('info', 2000, { fg: 'green' }) +log.addLevel('http', 3000, { fg: 'green', bg: 'black' }) log.addLevel('warn', 4000, { fg: 'black', bg: 'red' }, 'WARN') log.addLevel('error', 5000, { fg: 'red', bg: 'black' }, 'ERR!') log.addLevel('silent', Infinity) diff --git a/node_modules/npmlog/package.json b/node_modules/npmlog/package.json index 39b724741..0cdc56dd8 100644 --- a/node_modules/npmlog/package.json +++ b/node_modules/npmlog/package.json @@ -6,7 +6,7 @@ }, "name": "npmlog", "description": "logger for npm", - "version": "0.0.1", + "version": "0.0.2", "repository": { "type": "git", "url": "git://github.com/isaacs/npmlog.git" @@ -21,11 +21,12 @@ "devDependencies": { "tap": "" }, + "license": "BSD", "_npmUser": { "name": "isaacs", "email": "i@izs.me" }, - "_id": "npmlog@0.0.1", + "_id": "npmlog@0.0.2", "optionalDependencies": {}, "engines": { "node": "*" @@ -34,5 +35,5 @@ "_npmVersion": "1.1.24", "_nodeVersion": "v0.7.10-pre", "_defaultsLoaded": true, - "_from": "npmlog" + "_from": "npmlog@0" } diff --git a/node_modules/npmlog/test/basic.js b/node_modules/npmlog/test/basic.js new file mode 100644 index 000000000..8b5e7eb42 --- /dev/null +++ b/node_modules/npmlog/test/basic.js @@ -0,0 +1,461 @@ +var tap = require('tap') +var log = require('../') + +var result = [] +var logEvents = [] +var logInfoEvents = [] +var logPrefixEvents = [] + +var util = require('util') + +var resultExpect = +[ '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[7m', + 'sill', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + 'silly prefix', + '\u001b[0m', + ' x = {"foo":{"bar":"baz"}}\n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[34m', + '\u001b[40m', + 'verb', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + 'verbose prefix', + '\u001b[0m', + ' x = {"foo":{"bar":"baz"}}\n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[32m', + '\u001b[7m', + 'info', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + 'info prefix', + '\u001b[0m', + ' x = {"foo":{"bar":"baz"}}\n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[32m', + 'http', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + 'http prefix', + '\u001b[0m', + ' x = {"foo":{"bar":"baz"}}\n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[30m', + '\u001b[41m', + 'WARN', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + 'warn prefix', + '\u001b[0m', + ' x = {"foo":{"bar":"baz"}}\n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[31m', + '\u001b[40m', + 'ERR!', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + 'error prefix', + '\u001b[0m', + ' x = {"foo":{"bar":"baz"}}\n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[32m', + '\u001b[7m', + 'info', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + 'info prefix', + '\u001b[0m', + ' x = {"foo":{"bar":"baz"}}\n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[32m', + 'http', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + 'http prefix', + '\u001b[0m', + ' x = {"foo":{"bar":"baz"}}\n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[30m', + '\u001b[41m', + 'WARN', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + 'warn prefix', + '\u001b[0m', + ' x = {"foo":{"bar":"baz"}}\n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[31m', + '\u001b[40m', + 'ERR!', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + 'error prefix', + '\u001b[0m', + ' x = {"foo":{"bar":"baz"}}\n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[31m', + '\u001b[40m', + 'ERR!', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + '404', + '\u001b[0m', + ' This is a longer\n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[31m', + '\u001b[40m', + 'ERR!', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + '404', + '\u001b[0m', + ' message, with some details\n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[31m', + '\u001b[40m', + 'ERR!', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + '404', + '\u001b[0m', + ' and maybe a stack.\n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[31m', + '\u001b[40m', + 'ERR!', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u001b[35m', + '404', + '\u001b[0m', + ' \n', + '\u001b[0m', + '\u001b[37m', + '\u001b[40m', + 'npm', + '\u001b[0m', + ' ', + '\u001b[0m', + '\u0007', + 'noise', + '\u001b[0m', + '\u001b[35m', + '', + '\u001b[0m', + ' LOUD NOISES\n', + '\u001b[0m' ] + +var logPrefixEventsExpect = +[ { id: 2, + level: 'info', + prefix: 'info prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 9, + level: 'info', + prefix: 'info prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 16, + level: 'info', + prefix: 'info prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] } ] + +// should be the same. +var logInfoEventsExpect = logPrefixEventsExpect + +var logEventsExpect = +[ { id: 0, + level: 'silly', + prefix: 'silly prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 1, + level: 'verbose', + prefix: 'verbose prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 2, + level: 'info', + prefix: 'info prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 3, + level: 'http', + prefix: 'http prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 4, + level: 'warn', + prefix: 'warn prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 5, + level: 'error', + prefix: 'error prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 6, + level: 'silent', + prefix: 'silent prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 7, + level: 'silly', + prefix: 'silly prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 8, + level: 'verbose', + prefix: 'verbose prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 9, + level: 'info', + prefix: 'info prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 10, + level: 'http', + prefix: 'http prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 11, + level: 'warn', + prefix: 'warn prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 12, + level: 'error', + prefix: 'error prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 13, + level: 'silent', + prefix: 'silent prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 14, + level: 'silly', + prefix: 'silly prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 15, + level: 'verbose', + prefix: 'verbose prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 16, + level: 'info', + prefix: 'info prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 17, + level: 'http', + prefix: 'http prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 18, + level: 'warn', + prefix: 'warn prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 19, + level: 'error', + prefix: 'error prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 20, + level: 'silent', + prefix: 'silent prefix', + message: 'x = {"foo":{"bar":"baz"}}', + messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] }, + { id: 21, + level: 'error', + prefix: '404', + message: 'This is a longer\nmessage, with some details\nand maybe a stack.\n', + messageRaw: [ 'This is a longer\nmessage, with some details\nand maybe a stack.\n' ] }, + { id: 22, + level: 'noise', + prefix: false, + message: 'LOUD NOISES', + messageRaw: [ 'LOUD NOISES' ] } ] + +var Stream = require('stream').Stream +var s = new Stream() +s.write = function (m) { + result.push(m) +} + +s.writable = true +s.isTTY = true +s.end = function () {} + +log.stream = s + +log.heading = 'npm' + + +tap.test('basic', function (t) { + log.on('log', logEvents.push.bind(logEvents)) + log.on('log.info', logInfoEvents.push.bind(logInfoEvents)) + log.on('info prefix', logPrefixEvents.push.bind(logPrefixEvents)) + + console.error('log.level=silly') + log.level = 'silly' + log.silly('silly prefix', 'x = %j', {foo:{bar:'baz'}}) + log.verbose('verbose prefix', 'x = %j', {foo:{bar:'baz'}}) + log.info('info prefix', 'x = %j', {foo:{bar:'baz'}}) + log.http('http prefix', 'x = %j', {foo:{bar:'baz'}}) + log.warn('warn prefix', 'x = %j', {foo:{bar:'baz'}}) + log.error('error prefix', 'x = %j', {foo:{bar:'baz'}}) + log.silent('silent prefix', 'x = %j', {foo:{bar:'baz'}}) + + console.error('log.level=silent') + log.level = 'silent' + log.silly('silly prefix', 'x = %j', {foo:{bar:'baz'}}) + log.verbose('verbose prefix', 'x = %j', {foo:{bar:'baz'}}) + log.info('info prefix', 'x = %j', {foo:{bar:'baz'}}) + log.http('http prefix', 'x = %j', {foo:{bar:'baz'}}) + log.warn('warn prefix', 'x = %j', {foo:{bar:'baz'}}) + log.error('error prefix', 'x = %j', {foo:{bar:'baz'}}) + log.silent('silent prefix', 'x = %j', {foo:{bar:'baz'}}) + + console.error('log.level=info') + log.level = 'info' + log.silly('silly prefix', 'x = %j', {foo:{bar:'baz'}}) + log.verbose('verbose prefix', 'x = %j', {foo:{bar:'baz'}}) + log.info('info prefix', 'x = %j', {foo:{bar:'baz'}}) + log.http('http prefix', 'x = %j', {foo:{bar:'baz'}}) + log.warn('warn prefix', 'x = %j', {foo:{bar:'baz'}}) + log.error('error prefix', 'x = %j', {foo:{bar:'baz'}}) + log.silent('silent prefix', 'x = %j', {foo:{bar:'baz'}}) + log.error('404', 'This is a longer\n'+ + 'message, with some details\n'+ + 'and maybe a stack.\n') + log.addLevel('noise', 10000, {beep: true}) + log.noise(false, 'LOUD NOISES') + + t.deepEqual(result, resultExpect, 'result') + t.deepEqual(log.record, logEventsExpect, 'record') + t.deepEqual(logEvents, logEventsExpect, 'logEvents') + t.deepEqual(logInfoEvents, logInfoEventsExpect, 'logInfoEvents') + t.deepEqual(logPrefixEvents, logPrefixEventsExpect, 'logPrefixEvents') + + t.end() +}) |