Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[When MESSAGE symbol has a value and { all: true } is set, colorize the entire serialized message. #65

Merged
merged 3 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion colorize.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const colors = require('colors/safe');
const { LEVEL } = require('triple-beam');
const { LEVEL, MESSAGE } = require('triple-beam');

//
// Fix colors not appearing in non-tty environments
Expand Down Expand Up @@ -90,6 +90,10 @@ class Colorizer {
* `logform` info object.
*/
transform(info, opts) {
if (opts.all && typeof info[MESSAGE] === 'string') {
info[MESSAGE] = this.colorize(info[LEVEL], info.level, info[MESSAGE]);
}

if (opts.level || opts.all || !opts.message) {
info.level = this.colorize(info[LEVEL], info.level);
}
Expand Down
70 changes: 35 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion test/colorize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const assume = require('assume');
const colors = require('colors/safe');
const { configs, LEVEL } = require('triple-beam');
const { configs, LEVEL, MESSAGE } = require('triple-beam');
const colorize = require('../colorize');
const Colorizer = colorize.Colorizer;
const {
Expand Down Expand Up @@ -70,6 +70,24 @@ describe('colorize', () => {
}
));

it('colorize({ all: true }) [custom message]', assumeFormatted(
colorize({ all: true }),
{
level: 'info',
[LEVEL]: 'info',
message: 'whatever',
[MESSAGE]: '[info] whatever custom'
},
info => {
assume(info.level).is.a('string');
assume(info.message).is.a('string');
assume(info[LEVEL]).equals('info');
assume(info.level).equals(colors.green('info'));
assume(info.message).equals(colors.green('whatever'));
assume(info[MESSAGE]).equals(colors.green('[info] whatever custom'));
}
));

it('colorizes when LEVEL !== level', assumeFormatted(
colorize(),
{ [LEVEL]: 'info', level: 'INFO', message: 'whatever' },
Expand Down