diff --git a/index.js b/index.js index d7050a6f..c13a6066 100644 --- a/index.js +++ b/index.js @@ -154,7 +154,8 @@ module.exports = function prettyFactory (options) { errorLikeKeys: errorLikeObjectKeys, eol: EOL, ident: IDENT, - singleLine + singleLine, + colorizer }) line += prettifiedObject } diff --git a/lib/colors.js b/lib/colors.js index 0fcfb088..41018d87 100644 --- a/lib/colors.js +++ b/lib/colors.js @@ -11,7 +11,8 @@ const plain = { 30: nocolor, 20: nocolor, 10: nocolor, - message: nocolor + message: nocolor, + greyMessage: nocolor } const chalk = require('chalk') @@ -24,7 +25,8 @@ const colored = { 30: ctx.green, 20: ctx.blue, 10: ctx.grey, - message: ctx.cyan + message: ctx.cyan, + greyMessage: ctx.grey } function colorizeLevel (level, colorizer) { @@ -41,11 +43,13 @@ function plainColorizer (level) { return colorizeLevel(level, plain) } plainColorizer.message = plain.message +plainColorizer.greyMessage = plain.greyMessage function coloredColorizer (level) { return colorizeLevel(level, colored) } coloredColorizer.message = colored.message +coloredColorizer.greyMessage = colored.greyMessage /** * Factory function get a function to colorized levels. The returned function diff --git a/lib/utils.js b/lib/utils.js index a365ff9b..ac8ac43d 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -307,7 +307,8 @@ function prettifyObject ({ customPrettifiers = {}, errorLikeKeys = ERROR_LIKE_KEYS, excludeLoggerKeys = true, - singleLine = false + singleLine = false, + colorizer = defaultColorizer }) { const keysToIgnore = [].concat(skipKeys) @@ -334,7 +335,7 @@ function prettifyObject ({ if (singleLine) { // Stringify the entire object as a single JSON line if (Object.keys(plain).length > 0) { - result += stringifySafe(plain) + result += colorizer.greyMessage(stringifySafe(plain)) } result += eol } else { diff --git a/test/lib/colors.test.js b/test/lib/colors.test.js index 42674be3..166b8bad 100644 --- a/test/lib/colors.test.js +++ b/test/lib/colors.test.js @@ -34,6 +34,9 @@ test('returns default colorizer', async t => { colorized = colorizer.message('foo') t.is(colorized, 'foo') + + colorized = colorizer.greyMessage('foo') + t.is(colorized, 'foo') }) test('returns colorizing colorizer', async t => { @@ -67,4 +70,7 @@ test('returns colorizing colorizer', async t => { colorized = colorizer.message('foo') t.is(colorized, '\u001B[36mfoo\u001B[39m') + + colorized = colorizer.greyMessage('foo') + t.is(colorized, '\u001B[90mfoo\u001B[39m') })