pinojs / pino

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

Include instance UID #302

Closed gajus closed 6 years ago

gajus commented 7 years ago

It would be useful if log included a UID value that uniquely identifies service initialisation instance.

UID could container either UUID value or ULID.

Use case: When running many (100s) replications of the exact same service, it is often required to trace log of a particular instance during its lifetime. For that, each initialization of a program must be assigned a unique identifier. "pid" is the closest thing that exists at the moment, though it hardly guarantees uniqueness.

There is no performance cost associated with the feature. UID would be generated at the bootstrap time.

mcollina commented 7 years ago

This is very easy to achieve with child loggers. just create one adding a uuid  property.

gajus commented 7 years ago

This is very easy to achieve with child loggers. just create one adding a uuid property.

Thats what I did locally. I am just raising an issue in case you'd think this is something that should be in the core.

If not – just close it. :-)

mcollina commented 7 years ago

Maybe identifying a bit of "best practices" somewhere in the docs. I don't know exactly where. A process is also identified by the combo host-pid, but it's not easy to read.

jsumners commented 7 years ago

Maybe we need a FAQ section.

davidmarkclements commented 7 years ago

yah, a bit of time spent going through all issues would make a great basis for the FAQ, another recent one #296 among many others could come the FAQ, as could the "how we do transports" thing

jsumners commented 6 years ago

Closing because I believe it has been addressed and the FAQ discussion has been moved to another issue. Please re-open if you have further questions.

Jokero commented 6 years ago

Is child also recommended for case when I want to add some field with static value to every log message depending on log level? For example pino.error(...) adds additional severity:ERROR and so on for other levels. So I can create my own logger module this way:

var pino = require('pino')()
module.exports = {
   error(...args) { return piano.child({ severity: 'ERROR' }).error(...args); },
   ... // the same way for other levels
}

Or maybe there is more elegant way?

jsumners commented 6 years ago

I'm confused. Is the "severity: error" just an example? The log line already includes the level.

But, yes, a child would be the answer.

Jokero commented 6 years ago

Not just an example :smile: I want to use logs with Google Kubernetes Engine (stackdriver). And log entry may have field severity with level. So it's the same as level but called differently. What I wrote before is just simple workaround, but maybe better way is to use some transport like node index.js | pino-stackdriver

jsumners commented 6 years ago

Either method would get the job done.

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.