Skip to content

Commit

Permalink
Merge 27af376 into 9029b37
Browse files Browse the repository at this point in the history
  • Loading branch information
amitport committed Jun 4, 2014
2 parents 9029b37 + 27af376 commit 4a1a891
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ exports = module.exports = function logger(options) {
// compile format
if ('function' != typeof fmt) fmt = compile(fmt);

// options
var stream = options.stream || process.stdout
// stream
var defaultStream = {
write: function(str) {
process.stdout.write(str + '\n');
}
};
var stream = options.stream || defaultStream
, buffer = options.buffer;

// buffering support
Expand Down Expand Up @@ -92,7 +97,7 @@ exports = module.exports = function logger(options) {
if (skip(req, res)) return;
var line = fmt(exports, req, res);
if (null == line) return;
stream.write(line + '\n');
stream.write(line);
};

// immediate
Expand Down
38 changes: 19 additions & 19 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('logger()', function () {
.set('x-from-string', 'me')
.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal('me\n')
lastLogLine.should.equal('me')
done()
})
})
Expand All @@ -65,7 +65,7 @@ describe('logger()', function () {
.get('/')
.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal('true\n')
lastLogLine.should.equal('true')
done()
})
})
Expand All @@ -81,7 +81,7 @@ describe('logger()', function () {
.get('/')
.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal(res.text + '\n')
lastLogLine.should.equal(res.text)
done()
})
})
Expand All @@ -95,7 +95,7 @@ describe('logger()', function () {
.get('/')
.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal('10.0.0.1\n')
lastLogLine.should.equal('10.0.0.1')
done()
})
})
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('logger()', function () {
req.agent(agent)
req.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal(res.text + '\n')
lastLogLine.should.equal(res.text)
done()
})
})
Expand All @@ -142,7 +142,7 @@ describe('logger()', function () {
.set('Connection', 'close')
.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal(res.text + '\n')
lastLogLine.should.equal(res.text)
done()
})
})
Expand All @@ -157,7 +157,7 @@ describe('logger()', function () {
.set('Connection', 'keep-alive')
.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal(res.text + '\n')
lastLogLine.should.equal(res.text)
done()
})
})
Expand All @@ -173,7 +173,7 @@ describe('logger()', function () {
.set('Connection', 'keep-alive')
.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal(res.text + '\n')
lastLogLine.should.equal(res.text)
done()
})
})
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('logger()', function () {
.get('/')
.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal('-\n')
lastLogLine.should.equal('-')
done()
})
})
Expand All @@ -219,7 +219,7 @@ describe('logger()', function () {
.get('/')
.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal('-\n')
lastLogLine.should.equal('-')
done()
})
})
Expand All @@ -235,7 +235,7 @@ describe('logger()', function () {
.get('/')
.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal(res.statusCode + '\n')
lastLogLine.should.eql(res.statusCode)
done()
})
})
Expand All @@ -250,7 +250,7 @@ describe('logger()', function () {
.get('/')
.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal('-\n')
lastLogLine.should.equal('-')
done()
})
})
Expand Down Expand Up @@ -283,7 +283,7 @@ describe('logger()', function () {
if (err) return done(err)
lastLogLine = lastLogLine.replace(/\x1b\[(\d+)m/g, '_color_$1_')
lastLogLine.should.startWith('_color_90_GET / _color_32_200 _color_90_')
lastLogLine.should.endWith('_color_0_\n')
lastLogLine.should.endWith('_color_0_')
done()
})
})
Expand All @@ -299,7 +299,7 @@ describe('logger()', function () {
if (err) return done(err)
lastLogLine = lastLogLine.replace(/\x1b\[(\d+)m/g, '_color_$1_')
lastLogLine.should.startWith('_color_90_GET / _color_31_500 _color_90_')
lastLogLine.should.endWith('_color_0_\n')
lastLogLine.should.endWith('_color_0_')
done()
})
})
Expand All @@ -315,7 +315,7 @@ describe('logger()', function () {
if (err) return done(err)
lastLogLine = lastLogLine.replace(/\x1b\[(\d+)m/g, '_color_$1_')
lastLogLine.should.startWith('_color_90_GET / _color_33_400 _color_90_')
lastLogLine.should.endWith('_color_0_\n')
lastLogLine.should.endWith('_color_0_')
done()
})
})
Expand All @@ -331,7 +331,7 @@ describe('logger()', function () {
if (err) return done(err)
lastLogLine = lastLogLine.replace(/\x1b\[(\d+)m/g, '_color_$1_')
lastLogLine.should.startWith('_color_90_GET / _color_36_300 _color_90_')
lastLogLine.should.endWith('_color_0_\n')
lastLogLine.should.endWith('_color_0_')
done()
})
})
Expand Down Expand Up @@ -376,7 +376,7 @@ describe('logger()', function () {
})

function writeLog(log) {
log.should.equal('GET /first\nGET /second\n')
log.should.equal('GET /firstGET /second')
server.close()
done()
}
Expand Down Expand Up @@ -405,7 +405,7 @@ describe('logger()', function () {
})

function writeLog(log) {
log.should.equal('GET /first\nGET /second\n')
log.should.equal('GET /firstGET /second')
server.close()
done()
}
Expand Down Expand Up @@ -437,7 +437,7 @@ describe('logger()', function () {
.get('/')
.end(function (err, res) {
if (err) return done(err)
lastLogLine.should.equal('GET / -\n')
lastLogLine.should.equal('GET / -')
done()
})
})
Expand Down

0 comments on commit 4a1a891

Please sign in to comment.