-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Providing additional functionality to customPrettifiers and messageFo…
…rmat (#495) * feat: Add label and colorized output for level customPrettifier func Same implementation as #493 but using object for extras argument for compatibility with future signature expansion * feat: Provide colorette object to message format function Enables users to use available colors based on `colorize` context of the pino-pretty instance Variant of #494 that provides colors as extras object for compatibility with future customPrettifier extras argument * feat: Provide colorette object to prettifyObject All keys for customPrettifier, other than logs, now provide colors as property on an additional `extras` object for the prettifyObject function signature * feat: Add colors to level prettifier function signature * Modify level prettifier function signature to match other prettifiers * Since only the first argument was documented anyway this shouldn't be a breaking change. * docs: Update docs to showcase colors and standard customPrettifiers function signature * fix: Missing colors on colorizer when custom level colors are provided
- Loading branch information
Showing
14 changed files
with
202 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
|
||
module.exports = getLevelLabelData | ||
const { LEVELS, LEVEL_NAMES } = require('../constants') | ||
|
||
/** | ||
* Given initial settings for custom levels/names and use of only custom props | ||
* get the level label that corresponds with a given level number | ||
* | ||
* @param {boolean} useOnlyCustomProps | ||
* @param {object} customLevels | ||
* @param {object} customLevelNames | ||
* | ||
* @returns {function} A function that takes a number level and returns the level's label string | ||
*/ | ||
function getLevelLabelData (useOnlyCustomProps, customLevels, customLevelNames) { | ||
const levels = useOnlyCustomProps ? customLevels || LEVELS : Object.assign({}, LEVELS, customLevels) | ||
const levelNames = useOnlyCustomProps ? customLevelNames || LEVEL_NAMES : Object.assign({}, LEVEL_NAMES, customLevelNames) | ||
return function (level) { | ||
let levelNum = 'default' | ||
if (Number.isInteger(+level)) { | ||
levelNum = Object.prototype.hasOwnProperty.call(levels, level) ? level : levelNum | ||
} else { | ||
levelNum = Object.prototype.hasOwnProperty.call(levelNames, level.toLowerCase()) ? levelNames[level.toLowerCase()] : levelNum | ||
} | ||
|
||
return [levels[levelNum], levelNum] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.