better-logs
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -19,8 +19,9 @@ var _ = require('lodash'); | ||
this._visible = {}; // Map section => Map type => Boolean | ||
this._outputs = {}; // Map section => Map type => Writable | ||
this._groups = {}; // Map group => array of sections | ||
this._formats = {}; // Map type => format function | ||
this._modes = {}; // Map mode => mode options | ||
this._display = {}; // Display options | ||
this._morgan = null; // The real morgan object | ||
this._visible = {}; // Map section => Map type => Boolean | ||
this._outputs = {}; // Map section => Map type => Writable | ||
this._groups = {}; // Map group => array of sections | ||
this._formats = {}; // Map type => format function | ||
this._modes = {}; // Map mode => mode options | ||
this._display = {}; // Display options | ||
@@ -141,3 +142,3 @@ if (typeof opts === 'object') { | ||
output = output.replace(/{{message}}/gi, args.join(' ')); | ||
return output + "\n"; | ||
return output; | ||
} | ||
@@ -390,2 +391,5 @@ } | ||
} | ||
if (logTypeName === 'morgan') { | ||
return this._formats[logTypeName] = logFormatter; | ||
} | ||
if (typeof logFormatter === 'string') { | ||
@@ -410,2 +414,5 @@ logFormatter = this._makeFormatter(logFormatter); | ||
self._resolve(sectionOrGroup).forEach(function (section) { | ||
if (section === '_default' && !self._outputs['morgan']) { | ||
self._refreshMorgan(); | ||
} | ||
self._outputs[section] = self._outputs[section] || {}; | ||
@@ -416,4 +423,20 @@ self._outputs[section][type] = outputStream; | ||
Controller.prototype.morgan = morgan; | ||
Controller.prototype._refreshMorgan = function () { | ||
var self = this; | ||
if (!self.format('morgan')) { | ||
self.format('morgan', ':datefmt'.grey + ' '.white + ':method-pad' + ' :url '.white + ':status-code' + ' :response-time ms'.grey); | ||
} | ||
self._morgan = morgan(self.format('morgan'), { | ||
stream: self._getOutputStream('morgan', 'morgan') | ||
}) | ||
} | ||
Controller.prototype.morgan = function (opts) { | ||
var self = this; | ||
self._refreshMorgan(); | ||
return function (req, res, next) { | ||
self._morgan(req, res, next); | ||
} | ||
} | ||
module.exports = Controller; |
17
index.js
@@ -29,7 +29,7 @@ // | ||
formats: { | ||
log: "{{timestamp}}".grey + " info".cyan + " [{{section}}] {{message}}".white + " ({{file}}:{{line}})".grey, | ||
info: "{{timestamp}}".grey + " info".cyan + " [{{section}}] {{message}}".white + " ({{file}}:{{line}})".grey, | ||
warn: "{{timestamp}}".grey + " warn".yellow + " [{{section}}] {{message}}".white + " [{{section}}] ({{file}}:{{line}})".grey, | ||
error: "{{timestamp}}".grey + " err!".red.bold + " [{{ section }}] {{message}}\n {{method}} [{{section}}] ({{file}}:{{line}})\n{{stack}}".red, | ||
debug: "------------------------ debug ------------------------\n({{section}}) {{file}}:{{line}}: {{message}}\n".yellow | ||
log: "{{timestamp}}".grey + " info".cyan + " [{{section}}] {{message}}".white + " ({{file}}:{{line}})".grey + '\n', | ||
info: "{{timestamp}}".grey + " info".cyan + " [{{section}}] {{message}}".white + " ({{file}}:{{line}})".grey + '\n', | ||
warn: "{{timestamp}}".grey + " warn".yellow + " [{{section}}] {{message}}".white + " [{{section}}] ({{file}}:{{line}})".grey + '\n', | ||
error: "{{timestamp}}".grey + " err!".red.bold + " [{{ section }}] {{message}}\n {{method}} [{{section}}] ({{file}}:{{line}})\n{{stack}}".red + '\n', | ||
debug: "------------------------ debug ------------------------\n({{section}}) {{file}}:{{line}}: {{message}}\n".yellow + '\n' | ||
}, | ||
@@ -72,5 +72,10 @@ modes: { | ||
BetterLogs.morgan = morgan; | ||
BetterLogs.morgan = function (opts) { | ||
if (!controller) { | ||
init() | ||
} | ||
return controller.morgan(); | ||
} | ||
module.exports = BetterLogs; | ||
@@ -38,7 +38,2 @@ var morgan = require('morgan'); | ||
module.exports = function (opts) { | ||
opts = opts || {}; | ||
return function () { | ||
morgan(':datefmt'.grey + ' '.white + ':method-pad' + ' :url '.white + ':status-code' + ' :response-time ms'.grey, opts).apply(this, arguments); | ||
} | ||
} | ||
module.exports = morgan; |
{ | ||
"name": "better-logs", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Really flexible and fast logger for web servers, applications and daemons", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -54,3 +54,3 @@ var assert = require('assert'); | ||
logged += new Buffer(msg).toString(); | ||
assert.equal(logged, 'test\n'); | ||
assert.equal(logged, 'test'); | ||
done(); | ||
@@ -106,6 +106,6 @@ }) | ||
if (writes === 1) { | ||
assert.equal(written, 'b\n'); | ||
assert.equal(written, 'b'); | ||
} | ||
if (writes === 2) { | ||
assert.equal(written, 'd\n'); | ||
assert.equal(written, 'd'); | ||
done(); | ||
@@ -112,0 +112,0 @@ } |
@@ -36,3 +36,3 @@ var assert = require('assert'); | ||
var logged = new Buffer(msg).toString(); | ||
assert.equal(logged, 'null\n'); | ||
assert.equal(logged, 'null'); | ||
done(); | ||
@@ -48,3 +48,3 @@ }) | ||
var logged = new Buffer(msg).toString(); | ||
assert.equal(logged, 'NaN\n'); | ||
assert.equal(logged, 'NaN'); | ||
done(); | ||
@@ -60,3 +60,3 @@ }) | ||
var logged = new Buffer(msg).toString(); | ||
assert.equal(logged, 'undefined\n'); | ||
assert.equal(logged, 'undefined'); | ||
done(); | ||
@@ -72,3 +72,3 @@ }) | ||
var logged = new Buffer(msg).toString(); | ||
assert.equal(logged, 'hello\n'); | ||
assert.equal(logged, 'hello'); | ||
done(); | ||
@@ -84,3 +84,3 @@ }) | ||
var logged = new Buffer(msg).toString(); | ||
assert.equal(logged, '12.75\n'); | ||
assert.equal(logged, '12.75'); | ||
done(); | ||
@@ -96,3 +96,3 @@ }) | ||
var logged = new Buffer(msg).toString(); | ||
assert.equal(logged, '{ x: 1, y: [ \'a\', 2, 3 ], z: Infinity }\n'); | ||
assert.equal(logged, '{ x: 1, y: [ \'a\', 2, 3 ], z: Infinity }'); | ||
done(); | ||
@@ -108,3 +108,3 @@ }) | ||
var logged = new Buffer(msg).toString(); | ||
assert.equal(logged, '1: null 2: undefined 3: hello 4: 12 5: {"x":1,"y":["a",2,3]} extra\n'); | ||
assert.equal(logged, '1: null 2: undefined 3: hello 4: 12 5: {"x":1,"y":["a",2,3]} extra'); | ||
done(); | ||
@@ -136,3 +136,3 @@ }) | ||
var logged = new Buffer(msg).toString(); | ||
assert.equal(logged, 'a! [testSectionName] type: testFormatBasic {} {{not_one}}\n'); | ||
assert.equal(logged, 'a! [testSectionName] type: testFormatBasic {} {{not_one}}'); | ||
done(); | ||
@@ -168,3 +168,3 @@ }) | ||
var logged = new Buffer(msg).toString(); | ||
assert.equal(logged, pad(now.getHours(), 2) + ':' + pad(now.getMinutes(), 2) + ' year: ' + now.getFullYear() + '\n'); | ||
assert.equal(logged, pad(now.getHours(), 2) + ':' + pad(now.getMinutes(), 2) + ' year: ' + now.getFullYear()); | ||
done(); | ||
@@ -192,3 +192,3 @@ }) | ||
var written = new Buffer(msg).toString(); | ||
assert.equal(written, 'a\n'); | ||
assert.equal(written, 'a'); | ||
done(); | ||
@@ -206,7 +206,7 @@ }; | ||
var written = new Buffer(msg).toString(); | ||
assert.equal(written, 'a\n'); | ||
assert.equal(written, 'a'); | ||
}; | ||
outputDefault._write = function (msg) { | ||
var written = new Buffer(msg).toString(); | ||
assert.equal(written, 'b\n'); | ||
assert.equal(written, 'b'); | ||
done(); | ||
@@ -241,6 +241,6 @@ }; | ||
if (writes === 1) { | ||
assert.equal(written, 'a\n'); | ||
assert.equal(written, 'a'); | ||
} | ||
if (writes === 2) { | ||
assert.equal(written, 'c\n'); | ||
assert.equal(written, 'c'); | ||
done(); | ||
@@ -263,6 +263,6 @@ } | ||
if (writes === 1) { | ||
assert.equal(written, 'b\n'); | ||
assert.equal(written, 'b'); | ||
} | ||
if (writes === 2) { | ||
assert.equal(written, 'e\n'); | ||
assert.equal(written, 'e'); | ||
done(); | ||
@@ -290,9 +290,9 @@ } | ||
if (writes === 1) { | ||
assert.equal(written, 'd\n'); | ||
assert.equal(written, 'd'); | ||
} | ||
if (writes === 2) { | ||
assert.equal(written, 'f\n'); | ||
assert.equal(written, 'f'); | ||
} | ||
if (writes === 3) { | ||
assert.equal(written, 'e\n'); | ||
assert.equal(written, 'e'); | ||
done(); | ||
@@ -321,9 +321,9 @@ } | ||
if (writes === 1) { | ||
assert.equal(written, 'b\n'); | ||
assert.equal(written, 'b'); | ||
} | ||
if (writes === 2) { | ||
assert.equal(written, 'd\n'); | ||
assert.equal(written, 'd'); | ||
} | ||
if (writes === 3) { | ||
assert.equal(written, 'f\n'); | ||
assert.equal(written, 'f'); | ||
done(); | ||
@@ -369,3 +369,3 @@ } | ||
if (writes === 1) { | ||
assert.equal(written, 'b\n'); | ||
assert.equal(written, 'b'); | ||
done(); | ||
@@ -388,15 +388,15 @@ } | ||
if (writes === 1) { | ||
assert.equal(written, 'c\n'); | ||
assert.equal(written, 'c'); | ||
} | ||
if (writes === 2) { | ||
assert.equal(written, 'd\n'); | ||
assert.equal(written, 'd'); | ||
} | ||
if (writes === 3) { | ||
assert.equal(written, 'f\n'); | ||
assert.equal(written, 'f'); | ||
} | ||
if (writes === 4) { | ||
assert.equal(written, 'i\n'); | ||
assert.equal(written, 'i'); | ||
} | ||
if (writes === 5) { | ||
assert.equal(written, 'k\n'); | ||
assert.equal(written, 'k'); | ||
done(); | ||
@@ -445,6 +445,6 @@ } | ||
if (writes === 1) { | ||
assert.equal(written, 'c\n'); | ||
assert.equal(written, 'c'); | ||
} | ||
if (writes === 2) { | ||
assert.equal(written, 'd\n'); | ||
assert.equal(written, 'd'); | ||
done(); | ||
@@ -451,0 +451,0 @@ } |
43069
1039