Skip to content

Commit be6066c

Browse files
committedMay 18, 2020
Change how the pretty formatter output its arguments
1 parent cdd572b commit be6066c

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed
 

‎lib/formatters/pretty.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ const intel = require('intel');
88

99
function PrettyFormatter(options) {
1010
options = options || {};
11-
options.format = '%(name)s.%(levelname)s: %(message)s';
11+
options.format = '%(levelname)s %(name)s: %(message)s';
1212
options.colorize = true;
1313
intel.Formatter.call(this, options);
1414
}
1515
util.inherits(PrettyFormatter, intel.Formatter);
1616

1717
PrettyFormatter.prototype.format = function prettyFormat(record) {
18+
var name = record.args[0];
1819
var payload = record.args[1];
20+
record.args = ['%?', payload];
21+
record.name += '.' + name;
1922
if (typeof payload === 'object') {
2023
for (var key in payload) {
2124
if (payload[key] instanceof Error) {

‎test/pretty_formatter.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,30 @@ describe('pretty formatter', function() {
3333
it('should serialize objects to JSON strings', function() {
3434
var obj = { foo: { bar: 'baz' }, quux: 'baz' };
3535
logger.info('json', obj);
36-
assert.equal(lastLog, 'mozlog_pretty.test.pretty.INFO: json {"foo":{"bar":"baz"},"quux":"baz"}\n');
36+
assert.equal(lastLog, 'INFO mozlog_pretty.test.pretty.json: {"foo":{"bar":"baz"},"quux":"baz"}\n');
3737
});
3838

3939
it('should serialize circular objects', function() {
4040
var obj = { foo: {} };
4141
obj.foo.bar = obj;
4242
logger.info('jsoncircles', obj);
43-
assert.equal(lastLog, 'mozlog_pretty.test.pretty.INFO: jsoncircles {"foo":{"bar":"[Circular]"}}\n');
43+
assert.equal(lastLog, 'INFO mozlog_pretty.test.pretty.jsoncircles: {"foo":{"bar":"[Circular]"}}\n');
4444
});
4545

4646
it('should serialize errors', function() {
4747
var err1 = new Error('foo');
4848
logger.error('errors', err1);
49-
assert(lastLog.startsWith('mozlog_pretty.test.pretty.ERROR: errors Error: foo'));
49+
assert(lastLog.startsWith('ERROR mozlog_pretty.test.pretty.errors: Error: foo'));
5050
});
5151

5252
it('should serialize nested errors', function() {
5353
var err1 = new Error('foo');
5454
logger.error('errors', { obj: err1 });
55-
assert.equal(lastLog, 'mozlog_pretty.test.pretty.ERROR: errors {"obj":"Error: foo"}\n');
55+
assert.equal(lastLog, 'ERROR mozlog_pretty.test.pretty.errors: {"obj":"Error: foo"}\n');
5656
});
5757

5858
it('should coerce messages to strings', function() {
5959
var out = logger.warn('message', 42);
60-
assert.equal(lastLog, 'mozlog_pretty.test.pretty.WARN: message 42\n');
60+
assert.equal(lastLog, 'WARN mozlog_pretty.test.pretty.message: 42\n');
6161
});
6262
});

0 commit comments

Comments
 (0)
Please sign in to comment.