Skip to content

Commit

Permalink
WIP colorizer.greyMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Mar 3, 2021
1 parent ced61ec commit 2d7ca36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const plain = {
30: nocolor,
20: nocolor,
10: nocolor,
message: nocolor
message: nocolor,
greyMessage: nocolor
}

const chalk = require('chalk')
Expand All @@ -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) {
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const dateformat = require('dateformat')
const stringifySafe = require('fast-safe-stringify')
const defaultColorizer = require('./colors')()
const chalk = require('chalk')
const {
DATE_FORMAT,
ERROR_LIKE_KEYS,
Expand Down Expand Up @@ -308,7 +307,8 @@ function prettifyObject ({
customPrettifiers = {},
errorLikeKeys = ERROR_LIKE_KEYS,
excludeLoggerKeys = true,
singleLine = false
singleLine = false,
colorizer = defaultColorizer
}) {
const keysToIgnore = [].concat(skipKeys)

Expand All @@ -335,7 +335,7 @@ function prettifyObject ({
if (singleLine) {
// Stringify the entire object as a single JSON line
if (Object.keys(plain).length > 0) {
result += chalk.grey(stringifySafe(plain))
result += colorizer.greyMessage(stringifySafe(plain))
}
result += eol
} else {
Expand Down

0 comments on commit 2d7ca36

Please sign in to comment.