pino
pino copied to clipboard
Add raw message template to json payload
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!
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.
@dstockhammer Did you manage to resolve this?
@jsumners just wondering why did you close it, is it no longer an issue/request?
@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.
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.
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.