Socket
Socket
Sign inDemoInstall

pino-pretty

Package Overview
Dependencies
Maintainers
4
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pino-pretty - npm Package Compare versions

Comparing version 4.4.0 to 4.5.0

8

lib/utils.js

@@ -193,3 +193,3 @@ 'use strict'

* message to be prettified.
* @param {string} [input.messageFormat=undefined] A format string that defines how the
* @param {string|function} [input.messageFormat=undefined] A format string or function that defines how the
* logged message should be formatted, e.g. `'{level} - {pid}'`.

@@ -205,3 +205,3 @@ * @param {function} [input.colorizer] A colorizer function that has a

function prettifyMessage ({ log, messageFormat, messageKey = MESSAGE_KEY, colorizer = defaultColorizer, levelLabel = LEVEL_LABEL }) {
if (messageFormat) {
if (messageFormat && typeof messageFormat === 'string') {
const message = String(messageFormat).replace(/{([^{}]+)}/g, function (match, p1) {

@@ -222,2 +222,6 @@ // return log level as string instead of int

}
if (messageFormat && typeof messageFormat === 'function') {
const msg = messageFormat(log, messageKey, levelLabel)
return colorizer.message(msg)
}
if (messageKey in log === false) return undefined

@@ -224,0 +228,0 @@ if (typeof log[messageKey] !== 'string') return undefined

{
"name": "pino-pretty",
"version": "4.4.0",
"version": "4.5.0",
"description": "Prettifier for Pino log lines",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -169,2 +169,18 @@ <a id="intro"></a>

`messageFormat` option allows you to customize the message output. The format can be defined by a template `string` like this:
```js
{
messageFormat: '{levelLabel} - {pid} - url:{request.url}'
}
```
But this option can also be defined as a `function` with this prototype:
```js
{
messageFormat: (log, messageKey, levelLabel) => {
// do some log message customization
return customized_message;
}
}
```
<a id="license"><a>

@@ -171,0 +187,0 @@ ## License

@@ -119,2 +119,14 @@ 'use strict'

t.test('`messageFormat` supports function definition', async t => {
const str = prettifyMessage({
log: { level: 30, request: { url: 'localhost/test' }, msg: 'incoming request' },
messageFormat: (log, messageKey, levelLabel) => {
let msg = log[messageKey]
if (msg === 'incoming request') msg = `--> ${log.request.url}`
return msg
}
})
t.is(str, '--> localhost/test')
})
t.end()

@@ -121,0 +133,0 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc