Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pino prefix string to each log line #544

Closed
eran10 opened this issue Nov 15, 2018 · 3 comments
Closed

pino prefix string to each log line #544

eran10 opened this issue Nov 15, 2018 · 3 comments

Comments

@eran10
Copy link

eran10 commented Nov 15, 2018

Hi,
is there any option to add some const string to pino logger so for every log line we use "info" for example so i may add some prefix string that will be added ?

e.g
pino.info(${my prefix} some log line);
pino.info(${my prefix} some other log line);

@mcollina
Copy link
Member

Thanks for reporting! This is currently not possible.

@davidmarkclements
Copy link
Member

I'd suggest creating a little library for this, you could call it pino-prefix or some such,
the following should get you started:

function pinoPrefix(prefix, pinoInstance) {
  const { levels } = pinoInstance
  const { values } = levels
  Object.keys(values).forEach((level) => {
     const LOG = pinoInstance[level].bind(pinoInstance)
     pinoInstance[level] = (msg, ...args) => { 
      return LOG(typeof msg === 'string' ? prefix + msg : msg, ...args)
     }
  })
  return pinoInstance
}

In terms of putting it in core, we're happy to review PR's but it would need to have the following properties

  1. zero overhead when not in use
  2. very low performance impact when in use
  3. clearly defined parameters of what would happen in the case of an object logging
  4. documentation
  5. tests (100%)
  6. benchmarks

@github-actions
Copy link

github-actions bot commented Feb 8, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants