I am using pino for logging, and using pino-pretty as well.
I have come across an issues with pino printing special characters.
ex:
key: "someKeyJson"
value: "\t\t\t\tsomeValueJson\nstring\t\tthat isnt being formatted"
When what I would like is something along the lines of\
key: "someKeyJson"
value: " someValueJson
string that isnt being formatted"
My first attempt was strictly replacing the values in the string being logged
value.replace(/\t/g, ' ').replace(/\n/g, '\n')
Which works fine for the tabs, however it still results in the log looking somethng like
key: "someKeyJson"
value: "someValueJson\nstring that isnt being formatted"
My other replacement attempts include:
value.replace(/\t/g, ' ').replace(/\\n/g, '\n')
value.replace(/[\t]+/g, ' ').replace(/[\n]+/g, '\n')
All of this resulting in the same output, which made me conclude perhaps there is either configuration needed, or it has something to do with either ndjson or pino itself My configuration is as follows
const pinoLogger = pino({
name: logger,
level: LogLevel.DEBUG,
transport: {
target: 'pino-pretty',
options: {
destination: 1,
colorize: true,
translationTime: "SYS:yyyy-mm-dd'T'HH:MM:ss.l"
}
Any help is appreciated as I havent seen much in the pino or pino-pretty docs, so if I missed anything that would also be helpful
So I had forgotten to mention exactly how I am dong the logging An example of a log in my application looked as follows
This would result with any special characters being printed out as the literal character represenataion, rather than an actual tab or newline.
I found if I formatted my json just as a string and printed the string, I was able to get my desired effect.
Ex:
Which would result in the log looking like what I want, so it seemed to be a problem with simly passing the json object directly to the pino logger.
Note It seemed to be passing an object and not a string that was the issue because doing something like
Would not work either