pinojs / pino

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

missing control over the level format #363

Closed PavelPolyakov closed 6 years ago

PavelPolyakov commented 6 years ago

Hello,

Once again thanks for the module. I met another issue during the attempts to shape it to my needs. For some good reason it was decided that level in the logs is printed as int.

In my case I'd prefer to have it as string.

First I thought that I can overwrite it using serializers:

const pino = require('pino');

const logger = pino({
    serializers: {
        allOk: v => {
            return 444;
        },
        level: v => {
            return pino.levels.labels[v];
        }
    }
})

logger.info({allOk: 333}, 'hello');

Result:

{"level":30,"time":1519227377898,"msg":"hello","pid":16280,"hostname":"PP-MacBook-Pro.local","allOk":444,"v":1}

But this doesn't work, probably because level is "core" log property. And serialisers are only applied to the properties of the objects you log.

Is there an expected way to manipulate the level and how it's displayed?

* it is possible to do it using prettyPrint, but this is not an option, since I log into the custom stream.

Regards,

mcollina commented 6 years ago

No there is not. The format is fixed for good reasons, the tools needs to process things in a consistent way. I don't see this changing in any forseeable future.

PavelPolyakov commented 6 years ago

hi @mcollina, thanks for the quick answer.

The format is fixed for good reasons

I'm sure you have a reason for that.

Here is my use case:

  1. logs => output
  2. output => ElasticSearch
  3. Than I search through the logs using Kibana
  4. in Kibana I'm used to search by AND level:"error"

There are several solutions for this problem, including:

  1. add another key to express the level as string - this leads to changing the key which shows the level
  2. put something in the middle (like logstash) which'll convert number into the string - I see this as overhead

I do not suggest to change something, but to give control over this.

Maybe alike the messageKey there can be an option levelKey ? This will make possible use variant 1. Or something like timestamp function, (but it should receive the number as input).

jsumners commented 6 years ago

Duplicate of #279.

Also see https://github.com/pinojs/pino/issues/271#issuecomment-317545529

PavelPolyakov commented 6 years ago

@jsumners Thanks

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.