winston
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -0,4 +1,37 @@ | ||
## v1.1.0 / 2015-10-09 | ||
### GREETINGS FROM CARTAGENA EDITION | ||
#### Notable Changes | ||
* [#721](https://github.com/winstonjs/winston/pull/721) Fixed octal literal to work with node 4 strict mode (`wesleyeff`) | ||
* [#630](https://github.com/winstonjs/winston/pull/630) Add stderrLevels option to Console Transport and update docs (`paulhroth`) | ||
* [#626](https://github.com/winstonjs/winston/pull/626) Add the logger (this) in the fourth argument in the rewriters and filters functions (`christophehurpeau `) | ||
* [#623](https://github.com/winstonjs/winston/pull/623) Fix Console Transport's align option tests (`paulhroth`, `kikobeats`) | ||
* [#692](https://github.com/winstonjs/winston/pull/692) Adding winston-aws-cloudwatch to transport docs (`timdp`) | ||
## v1.0.2 2015-09-25 | ||
### LET'S TALK ON GITTER EDITION | ||
#### Notable Changes | ||
* [de80160](https://github.com/winstonjs/winston/commit/de80160) Add Gitter badge (`The Gitter Badger`) | ||
* [44564de](https://github.com/winstonjs/winston/commit/44564de) [fix] Correct listeners in `logException`. Fixes [#218](https://github.com/winstonjs/winston/issues/218) [#213](https://github.com/winstonjs/winston/issues/213) [#327](https://github.com/winstonjs/winston/issues/327). (`indexzero`) | ||
* [45b1eeb](https://github.com/winstonjs/winston/commit/45b1eeb) [fix] Get `tailFile` function working on latest/all node versions (`Christopher Jeffrey`) | ||
* [c6d45f9](https://github.com/winstonjs/winston/commit/c6d45f9) Fixed event subscription on close (`Roman Stetsyshin`) | ||
#### Other changes | ||
* TravisCI updates & best practices [87b97cc](https://github.com/winstonjs/winston/commit/87b97cc) [91a5bc4](https://github.com/winstonjs/winston/commit/91a5bc4), [cf24e6a](https://github.com/winstonjs/winston/commit/cf24e6a) (`indexzero`) | ||
* [d5397e7](https://github.com/winstonjs/winston/commit/d5397e7) Bump async version (`Roderick Hsiao`) | ||
* Documentation updates & fixes [86d7527](https://github.com/winstonjs/winston/commit/86d7527), [38254c1](https://github.com/winstonjs/winston/commit/38254c1), [04e2928](https://github.com/winstonjs/winston/commit/04e2928), [61c8a89](https://github.com/winstonjs/winston/commit/61c8a89), [c42a783](https://github.com/winstonjs/winston/commit/c42a783), [0688a22](https://github.com/winstonjs/winston/commit/0688a22), [eabc113](https://github.com/winstonjs/winston/commit/eabc113) [c9506b7](https://github.com/winstonjs/winston/commit/c9506b7), [17534d2](https://github.com/winstonjs/winston/commit/17534d2), [b575e7b](https://github.com/winstonjs/winston/commit/b575e7b) (`Stefan Thies`, `charukiewicz`, `unLucio`, `Adam Cohen`, `Denis Gorbachev`, `Frederik Ring`, `Luigi Pinca`, `jeffreypriebe`) | ||
* Documentation refactor & cleanup [a19607e](https://github.com/winstonjs/winston/commit/a19607e), [d1932b4](https://github.com/winstonjs/winston/commit/d1932b4), [7a13132](https://github.com/winstonjs/winston/commit/7a13132) (`indexzero`) | ||
## v1.0.1 / 2015-06-26 | ||
### YAY DOCS EDITION | ||
* [#639](https://github.com/winstonjs/winston/pull/639) Fix for [#213](https://github.com/winstonjs/winston/issues/213): More than 10 containers triggers EventEmitter memory leak warning (`marcus`) | ||
* Documentation and `package.json` updates [cec892c](https://github.com/winstonjs/winston/commit/cec892c), [2f13b4f](https://github.com/winstonjs/winston/commit/2f13b4f), [b246efd](https://github.com/winstonjs/winston/commit/b246efd), [22a5f5a](https://github.com/winstonjs/winston/commit/22a5f5a), [5868b78](https://github.com/winstonjs/winston/commit/5868b78), [99b6b44](https://github.com/winstonjs/winston/commit/99b6b44), [447a813](https://github.com/winstonjs/winston/commit/447a813), [7f75b48](https://github.com/winstonjs/winston/commit/7f75b48) (`peteward44`, `Gilad Peleg`, `Anton Ian Sipos`, `nimrod-becker`, `LarsTi`, `indexzero`) | ||
## v1.0.0 / 2015-04-07 | ||
### OMG 1.0.0 FINALLY EDITION | ||
### Breaking Changes | ||
#### Breaking Changes | ||
* [#587](https://github.com/winstonjs/winston/pull/587) Do not extend `String` prototypes as a side effect of using `colors`. (`kenperkins`) | ||
@@ -11,3 +44,3 @@ * [#581](https://github.com/winstonjs/winston/pull/581) File transports now emit `error` on error of the underlying streams after `maxRetries` attempts. (`ambbell`). | ||
### Other changes | ||
#### Other changes | ||
@@ -14,0 +47,0 @@ * [b83de62](https://github.com/winstonjs/winston/commit/b83de62) Fix rendering of stack traces. |
@@ -24,2 +24,3 @@ # Winston Transports | ||
* [Amazon SNS](#amazon-sns-simple-notification-system-transport) | ||
* [Amazon CloudWatch](#amazon-cloudwatch-transport) | ||
* [Graylog2](#graylog2-transport) | ||
@@ -60,3 +61,4 @@ * [Cassandra](#cassandra-transport) | ||
* __formatter:__ If function is specified, its return value will be used instead of default output. (default undefined) | ||
* __debugStdout:__ Boolean flag indicating if 'debug'-level output should be redirected to stdout instead of to stderr. (default false) | ||
* __stderrLevels__ Array of strings containing the levels to log to stderr instead of stdout, for example `['error', 'debug', 'info']`. (default `['error', 'debug']`) | ||
* (Deprecated: Use __stderrLevels__ instead) __debugStdout:__ Boolean flag indicating if 'debug'-level output should be redirected to stdout instead of to stderr. Cannot be used with __stderrLevels__. (default false) | ||
@@ -325,2 +327,21 @@ *Metadata:* Logged via util.inspect(meta); | ||
### Amazon CloudWatch Transport | ||
The [winston-aws-cloudwatch][25] transport relays your log messages to Amazon CloudWatch. | ||
```js | ||
var winston = require('winston'), | ||
winstonAwsCloudWatch = require('winston-aws-cloudwatch'); | ||
winston.add(winstonAwsCloudWatch, options); | ||
``` | ||
Options: | ||
* __logGroupName:__ The name of the CloudWatch log group to which to log. *[required]* | ||
* __logStreamName:__ The name of the CloudWatch log stream to which to log. *[required]* | ||
* __awsConfig:__ An object containing your `accessKeyId`, `secretAccessKey`, `region`, etc. | ||
Alternatively, you may be interested in [winston-cloudwatch][26]. | ||
### Amazon DynamoDB Transport | ||
@@ -497,3 +518,3 @@ The [winston-dynamodb][26] transport uses Amazon's DynamoDB as a sink for log messages. You can take advantage of the various authentication methods supports by Amazon's aws-sdk module. See [Configuring the SDK in Node.js](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html). | ||
var winston = require('winston') | ||
var Logsene = require('winston-logsene') | ||
var Logsene = require('winston-logsene') | ||
var logger = new winston.Logger() | ||
@@ -503,9 +524,9 @@ logger.add (Logsene, {token: process.env.LOGSENE_TOKEN}) | ||
``` | ||
Options: | ||
* __token__: Logsene Application Token | ||
Options: | ||
* __token__: Logsene Application Token | ||
* __source__: Source of the logs (defaults to main module) | ||
[Logsene](http://www.sematext.com/logsene/) features: | ||
- Fulltext search | ||
- Anomaly detection and alerts | ||
- Fulltext search | ||
- Anomaly detection and alerts | ||
- Kibana4 integration | ||
@@ -573,1 +594,3 @@ - Integration with [SPM Performance Monitoring for Node.js](http://www.sematext.com/spm/integrations/nodejs-monitoring.html) | ||
[24]: https://github.com/sematext/winston-logsene | ||
[25]: https://github.com/timdp/winston-aws-cloudwatch | ||
[26]: https://github.com/lazywithclass/winston-cloudwatch |
@@ -123,2 +123,3 @@ /* | ||
// colorize: false, // Colorizes output (only if `.json` is false) | ||
// align: false // Align message level. | ||
// timestamp: true // Adds a timestamp to the serialized message | ||
@@ -210,2 +211,3 @@ // label: 'label to prepend the message' | ||
output += (options.align) ? '\t' : ''; | ||
output += (timestamp || showLevel) ? ': ' : ''; | ||
@@ -369,3 +371,3 @@ output += options.label ? ('[' + options.label + '] ') : ''; | ||
fs.open(options.file, 'a+', 0644, function(err, fd) { | ||
fs.open(options.file, 'a+', '0644', function(err, fd) { | ||
if (err) { | ||
@@ -449,1 +451,20 @@ if (!callback) { | ||
}; | ||
// | ||
// ### function stringArrayToSet (array) | ||
// #### @strArray {Array} Array of Set-elements as strings. | ||
// #### @errMsg {string} **Optional** Custom error message thrown on invalid input. | ||
// Returns a Set-like object with strArray's elements as keys (each with the value true). | ||
// | ||
exports.stringArrayToSet = function (strArray, errMsg) { | ||
if (typeof errMsg === 'undefined') { | ||
errMsg = 'Cannot make set from Array with non-string elements'; | ||
} | ||
return strArray.reduce(function (set, el) { | ||
if (!(typeof el === 'string' || el instanceof String)) { | ||
throw new Error(errMsg); | ||
} | ||
set[el] = true; | ||
return set; | ||
}, Object.create(null)); | ||
}; |
@@ -154,7 +154,7 @@ /* | ||
this.rewriters.forEach(function (rewriter) { | ||
meta = rewriter(level, msg, meta); | ||
meta = rewriter(level, msg, meta, self); | ||
}); | ||
this.filters.forEach(function(filter) { | ||
var filtered = filter(msg, meta, level); | ||
var filtered = filter(msg, meta, level, self); | ||
if (typeof filtered === 'string') | ||
@@ -161,0 +161,0 @@ msg = filtered; |
@@ -24,11 +24,12 @@ /* | ||
this.json = options.json || false; | ||
this.colorize = options.colorize || false; | ||
this.prettyPrint = options.prettyPrint || false; | ||
this.timestamp = typeof options.timestamp !== 'undefined' ? options.timestamp : false; | ||
this.showLevel = options.showLevel === undefined ? true : options.showLevel; | ||
this.label = options.label || null; | ||
this.logstash = options.logstash || false; | ||
this.debugStdout = options.debugStdout || false; | ||
this.depth = options.depth || null; | ||
this.json = options.json || false; | ||
this.colorize = options.colorize || false; | ||
this.prettyPrint = options.prettyPrint || false; | ||
this.timestamp = typeof options.timestamp !== 'undefined' ? options.timestamp : false; | ||
this.showLevel = options.showLevel === undefined ? true : options.showLevel; | ||
this.label = options.label || null; | ||
this.logstash = options.logstash || false; | ||
this.depth = options.depth || null; | ||
this.align = options.align || false; | ||
this.stderrLevels = setStderrLevels(options.stderrLevels, options.debugStdout); | ||
@@ -40,2 +41,31 @@ if (this.json) { | ||
} | ||
// | ||
// Convert stderrLevels into an Object for faster key-lookup times than an Array. | ||
// | ||
// For backwards compatibility, stderrLevels defaults to ['error', 'debug'] | ||
// or ['error'] depending on whether options.debugStdout is true. | ||
// | ||
function setStderrLevels (levels, debugStdout) { | ||
var defaultMsg = 'Cannot have non-string elements in stderrLevels Array'; | ||
if (debugStdout) { | ||
if (levels) { | ||
// | ||
// Don't allow setting both debugStdout and stderrLevels together, | ||
// since this could cause behaviour a programmer might not expect. | ||
// | ||
throw new Error('Cannot set debugStdout and stderrLevels together'); | ||
} | ||
return common.stringArrayToSet(['error'], defaultMsg); | ||
} | ||
if (!levels) { | ||
return common.stringArrayToSet(['error', 'debug'], defaultMsg); | ||
} else if (!(Array.isArray(levels))) { | ||
throw new Error('Cannot set stderrLevels to type other than Array'); | ||
} | ||
return common.stringArrayToSet(levels, defaultMsg); | ||
}; | ||
}; | ||
@@ -84,6 +114,7 @@ | ||
formatter: this.formatter, | ||
align: this.align, | ||
humanReadableUnhandledException: this.humanReadableUnhandledException | ||
}); | ||
if (level === 'error' || (level === 'debug' && !this.debugStdout) ) { | ||
if (this.stderrLevels[level]) { | ||
process.stderr.write(output + '\n'); | ||
@@ -90,0 +121,0 @@ } else { |
{ | ||
"name": "winston", | ||
"description": "A multi-transport async logging library for Node.js", | ||
"version": "1.0.2", | ||
"author": "Nodejitsu Inc. <info@nodejitsu.com>", | ||
"version": "1.1.0", | ||
"author": "Charlie Robbins <charlie.robbins@gmail.com>", | ||
"maintainers": [ | ||
@@ -7,0 +7,0 @@ "indexzero <charlie@nodejitsu.com>" |
@@ -209,1 +209,59 @@ /* | ||
}; | ||
helpers.assertOptionsThrow = function (options, errMsg) { | ||
return function () { | ||
assert.throws( | ||
function () { | ||
try { | ||
new (winston.transports.Console)(options); | ||
} catch (err) { | ||
throw(err); | ||
} | ||
}, | ||
new RegExp('^' + errMsg.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + '$') | ||
); | ||
} | ||
}; | ||
helpers.assertStderrLevels = function (transport, stderrLevels) { | ||
return function () { | ||
assert.equal( | ||
JSON.stringify(Object.keys(transport.stderrLevels).sort()), | ||
JSON.stringify(stderrLevels.sort()) | ||
); | ||
} | ||
}; | ||
helpers.testLoggingToStreams = function (levels, transport, stderrLevels, stdMocks) { | ||
return { | ||
topic: function () { | ||
stdMocks.use(); | ||
transport.showLevel = true; | ||
Object.keys(levels).forEach(function (level) { | ||
transport.log( | ||
level, | ||
level + ' should go to ' + (stderrLevels.indexOf(level) > -1 ? 'stderr' : 'stdout'), | ||
{}, | ||
function () {} | ||
); | ||
}); | ||
var output = stdMocks.flush(); | ||
stdMocks.restore(); | ||
this.callback(null, output, levels); | ||
}, | ||
"output should go to the appropriate streams": function (ign, output, levels) { | ||
var outCount = 0, | ||
errCount = 0; | ||
Object.keys(levels).forEach(function (level) { | ||
var line; | ||
if (stderrLevels.indexOf(level) > -1) { | ||
line = output.stderr[errCount++]; | ||
assert.equal(line, level + ': ' + level + ' should go to stderr\n'); | ||
} else { | ||
line = output.stdout[outCount++]; | ||
assert.equal(line, level + ': ' + level + ' should go to stdout\n'); | ||
} | ||
}); | ||
} | ||
} | ||
}; |
@@ -17,3 +17,19 @@ /* | ||
var npmTransport = new (winston.transports.Console)(), | ||
syslogTransport = new (winston.transports.Console)({ levels: winston.config.syslog.levels }); | ||
syslogTransport = new (winston.transports.Console)({ levels: winston.config.syslog.levels }), | ||
alignTransport = new (winston.transports.Console)({ showLevel: true, align: true }), | ||
defaultTransport = new (winston.transports.Console)(), | ||
debugStdoutTransport = new (winston.transports.Console)({ debugStdout: true }), | ||
stderrLevelsTransport = new (winston.transports.Console)({ stderrLevels: ['info', 'warn'] }), | ||
customLevels = { | ||
alpha: 0, | ||
beta: 1, | ||
gamma: 2, | ||
delta: 3, | ||
epsilon: 4, | ||
}, | ||
customLevelsAndStderrTransport = new (winston.transports.Console)({ | ||
levels: customLevels, | ||
stderrLevels: ['delta', 'epsilon'] | ||
}), | ||
noStderrTransport = new (winston.transports.Console)({ stderrLevels: [] }); | ||
@@ -69,2 +85,85 @@ vows.describe('winston/transports/console').addBatch({ | ||
} | ||
}).export(module); | ||
}).addBatch({ | ||
"An instance of the Console Transport with the align option on": { | ||
topic : function() { | ||
stdMocks.use(); | ||
alignTransport.log('info', ''); | ||
}, | ||
"should have logs aligned": function () { | ||
stdMocks.restore(); | ||
var output = stdMocks.flush(), | ||
line = output.stdout[0]; | ||
assert.equal(line, 'info\011: \n'); | ||
} | ||
} | ||
}).addBatch({ | ||
"with align off": { | ||
topic : function() { | ||
alignTransport.align = false; | ||
stdMocks.use(); | ||
alignTransport.log('info', ''); | ||
}, | ||
"should not have logs aligned": function () { | ||
stdMocks.restore(); | ||
var output = stdMocks.flush(), | ||
line = output.stdout[0]; | ||
assert.equal(line, 'info: \n'); | ||
} | ||
} | ||
}).addBatch({ | ||
"An instance of the Console Transport with no options": { | ||
"should set stderrLevels to 'error' and 'debug' by default": helpers.assertStderrLevels( | ||
defaultTransport, | ||
['error', 'debug'] | ||
), | ||
"should log only 'error' and 'debug' to stderr": helpers.testLoggingToStreams( | ||
winston.config.npm.levels, defaultTransport, ['debug', 'error'], stdMocks | ||
) | ||
} | ||
}).addBatch({ | ||
"An instance of the Console Transport with debugStdout set": { | ||
"should throw an Error if stderrLevels is set": helpers.assertOptionsThrow( | ||
{ debugStdout: true, stderrLevels: ['debug'] }, | ||
"Error: Cannot set debugStdout and stderrLevels together" | ||
), | ||
"should set stderrLevels to 'error' by default": helpers.assertStderrLevels( | ||
debugStdoutTransport, | ||
['error'] | ||
), | ||
"should log only the 'error' level to stderr": helpers.testLoggingToStreams( | ||
winston.config.npm.levels, debugStdoutTransport, ['error'], stdMocks | ||
) | ||
} | ||
}).addBatch({ | ||
"An instance of the Console Transport with stderrLevels set": { | ||
"should throw an Error if stderrLevels is set but not an Array": helpers.assertOptionsThrow( | ||
{ debugStdout: false, stderrLevels: new String('Not an Array') }, | ||
"Error: Cannot set stderrLevels to type other than Array" | ||
), | ||
"should throw an Error if stderrLevels contains non-string elements": helpers.assertOptionsThrow( | ||
{ debugStdout: false, stderrLevels: ["good", /^invalid$/, "valid"] }, | ||
"Error: Cannot have non-string elements in stderrLevels Array" | ||
), | ||
"should correctly set stderrLevels": helpers.assertStderrLevels( | ||
stderrLevelsTransport, | ||
['info', 'warn'] | ||
), | ||
"should log only the levels in stderrLevels to stderr": helpers.testLoggingToStreams( | ||
winston.config.npm.levels, stderrLevelsTransport, ['info', 'warn'], stdMocks | ||
) | ||
} | ||
}).addBatch({ | ||
"An instance of the Console Transport with stderrLevels set to an empty array": { | ||
"should log only to stdout, and not to stderr": helpers.testLoggingToStreams( | ||
winston.config.npm.levels, noStderrTransport, [], stdMocks | ||
) | ||
} | ||
}).addBatch({ | ||
"An instance of the Console Transport with custom levels and stderrLevels set": { | ||
"should log only the levels in stderrLevels to stderr": helpers.testLoggingToStreams( | ||
customLevels, customLevelsAndStderrTransport, ['delta', 'epsilon'], stdMocks | ||
) | ||
} | ||
}).export(module); |
266345
6045