8000 Merge pull request #364 from demmer/add-stderr-appender · mKoder/log4js-node@0007623 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0007623

Browse files
committed
Merge pull request log4js-node#364 from demmer/add-stderr-appender
add a stderr appender
2 parents 451f79a + 929c206 commit 0007623

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ framework to work with [node](http://nodejs.org). I've mainly stripped out the b
77

88
Out of the box it supports the following features:
99

10-
* coloured console logging
10+
* coloured console logging to stdout or stderr
1111
* replacement of node's console.log functions (optional)
1212
* file appender, with log rolling based on file size
1313
* SMTP appender

lib/appenders/stderr.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict";
2+
3+
var layouts = require('../layouts')
4+
5+
function stderrAppender(layout, timezoneOffset) {
6+
layout = layout || layouts.colouredLayout;
7+
return function(loggingEvent) {
8+
process.stderr.write(layout(loggingEvent, timezoneOffset) + '\n');
9+
};
10+
}
11+
12+
function configure(config) {
13+
var layout;
14+
if (config.layout) {
15+
layout = layouts.layout(config.layout.type, config.layout);
16+
}
17+
return stderrAppender(layout, config.timezoneOffset);
18+
}
19+
20+
exports.appender = stderrAppender;
21+
exports.configure = configure;

test/stderrAppender-test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
var assert = require('assert')
3+
, vows = require('vows')
4+
, layouts = require('../lib/layouts')
5+
, sandbox = require('sandboxed-module');
6+
7+
vows.describe('../lib/appenders/stderr').addBatch({
8+
'appender': {
9+
topic: function() {
10+
var messages = []
11+
, fakeProcess = {
12+
stderr: {
13+
write: function(msg) { messages.push(msg); }
14+
}
15+
}
16+
, appenderModule = sandbox.require(
17+
'../lib/appenders/stderr',
18+
{
19+
globals: {
20+
'process': fakeProcess
21+
}
22+
}
23+
)
24+
, appender = appenderModule.appender(layouts.messagePassThroughLayout);
25+
26+
appender({ data: ["blah"] });
27+
return messages;
28+
},
29+
30+
'should output to stderr': function(messages) {
31+
assert.equal(messages[0], 'blah\n');
32+
}
33+
}
34+
35+
}).exportTo(module);

0 commit comments

Comments
 (0)
0