pinojs / pino

🌲 super fast, all natural json logger
http://getpino.io
MIT License
14.21k stars 875 forks source link

Feature: `pino.destination(string)` to interpolate env-vars #1332

Closed osher closed 2 years ago

osher commented 2 years ago

I think it would be useful that when pino.destination(..) is provided with a string - to interpolate env-vars if any.

e.g.:, consiuder

LOG_PATH=/builds/lksalEdq/0/my-org/my-repo/logs node node_modules/my-app/bin/svr

then,

const d = pino.destination('${LOG_PATH}/my-app.log');

//resulting with  /builds/lksalEdq/0/my-org/my-repo/logs/my-app.log

Use Case

The use-case is to be able to pass to applications that use pino (e.g. verdaccio) configuration that interpolates. I do not develop verdaccio - I use it, and it in turn uses pino (see here)

So mind that explicitly do not pass to pino.destination(...) a template-expression - but a string that should interpolate once, on load time.

more info - here my nick there is Radagast the Brown.

implementation

I think of something in the sort of:

function normalizeDestFileDescriptor (destination, { env } = process) {
  const fd = Number(destination)
  if (typeof destination === 'string') {
    if (Number.isFinite(fd)) {
      return fd
    }

    destination = destination.replace(/$\{([a-z][a-z0-9_]}+)\}/gi, (expr, envVar) => envVar in env ? env[envVar] : expr);
  }

  return destination
}

would you embrace such a PR? if yes, I'll add this change + tests.

mcollina commented 2 years ago

thanks for opening this issue, however I see quite a few ways this could become a potential security issue. I would recommend to ask to implement this feature to maintainers of Verdaccio.

jsumners commented 2 years ago

This is an application level feature. Pino accepts configuration and it is up to the developer to determine how that configuration is built.

github-actions[bot] commented 2 years ago

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.