pinojs / pino-pretty

🌲Basic prettifier for Pino log lines
MIT License
1.27k stars 150 forks source link

Documentation shows colorization functions, but they don't seem to exist or work #474

Open nsoft opened 1 year ago

nsoft commented 1 year ago

If I define a log target with options that include customPretifiers as shown in Readme.md two problems arise:

1) The functions shown in the example don't seem to exist 2) Even if I define my own version of the function one gets a data clone error...

https://github.com/pinojs/pino-pretty/blob/master/Readme.md#handling-non-serializable-options suggests a possible solution, but it didn't seem to work (at least not for trying to colorize an attribute from the merge object)

stdLogTarget.ts

function colorYellow(script) {
  return "\x1b[33m foo "+ script + "\x1b[0"
}

module.exports = opts => require('pino-pretty')({
  ...opts,
  customPrettifiers: {
    script: (script: any) => colorYellow(script)
  }
})

logger.ts

const stdLogTarget = (level: strig) => ({
  target: './stdLogTarget'

That runs but neither the color nor the "foo" is added. (yes naming of some things needs improvement, not final form)

I think the docs make clear that the functions listed don't exist (or if they do say where to find them), and provide examples that are in working form.

jsumners commented 1 year ago

The linked example is an example of potential user code, not an example of what is provided by the library. Improvements to the documentation are welcome.

As for any error, please provide the text of the error. Also, please provide a minimal reproducible example. Doing so will help us diagnose your issue. It should be the bare minimum code needed to trigger the issue, and easily runnable without any changes or extra code.

You may use a GitHub repository to host the code if it is too much to fit in a code block (or two).