pino icon indicating copy to clipboard operation
pino copied to clipboard

Add raw message template to json payload

Open dstockhammer opened this issue 3 years ago • 1 comments

Hi there, I'd like to be able to add the raw message templates to the json payload in addition to the formatted message. For example, given this log:

logger.info('hello %s', 'world')

I'd like to get this output:

{
  "msg": "hello world",
  "raw_msg": "hello %s",
  // all the other standard properties
  ...
}

Is there a way to achieve this? I've tried using hooks, mixins and formatters, but couldn't manage to find a solution. Basically my idea was to add inputArgs[0] (which is the message) to mergeObject (which gets added to the json payload) but sadly there seems to be no extension point that has access to both inputArgs and mergeObject.

But maybe there's a simpler solution :)

Thank you!

dstockhammer avatar Apr 12 '22 07:04 dstockhammer

You could do something like:

const raw_message = 'hello %s'
logger.info({ raw_message }, raw_message, 'world')

Unfortunately this is not something that can easily work from the hooks.

mcollina avatar Apr 12 '22 08:04 mcollina

@dstockhammer Did you manage to resolve this?

Fdawgs avatar May 29 '23 08:05 Fdawgs

@jsumners just wondering why did you close it, is it no longer an issue/request?

cilerler avatar May 29 '23 12:05 cilerler

@cilerler the original reporter has not responded to the thread in over a year. It can be reopened if someone wants to take up the work, but as it is we do not have a plan to work on this.

jsumners avatar May 29 '23 12:05 jsumners

Thank you for the quick response! I've been searching for this feature for a long time, and it's incredibly helpful, especially for troubleshooting.

For example, let's say you're logging a value based on the date and time, such as 202305290852 message received. Currently, there's no way to filter these specific log entries in Grafana/Loki, Kibana, or other systems. However, if these messages had a template with additional information like {datetimestamp} message received, it would make filtering much easier. This feature is already available in .NET logger, and it would be highly valuable to have it in pinoJS as well. Just wanted to share my thoughts on this matter.

cilerler avatar May 29 '23 12:05 cilerler

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[bot] avatar Jun 29 '23 00:06 github-actions[bot]