Im using this code to stream into a file. But the created file is empty. Is there something wrong with my code?
const fileStream = pinoms.prettyStream(
{
prettyPrint: {
colorize: true,
levelFirst: true,
translateTime: "yyyy-dd-mm, h:MM:ss TT",
},
},
pinoms.destination({
dest: './my-file', // omit for stdout
minLength: 4096, // Buffer before writing
sync: true}) // Asynchronous logging)
)
const streams = [
{stream: fileStream}
]
const logger = pinoms(pinoms.multistream(streams))
logger.info('HELLO %s!', 'World')
In the documentation it says:
const prettyStream = pinoms.prettyStream(
{
prettyPrint:
{ colorize: true,
translateTime: "SYS:standard",
ignore: "hostname,pid" // add 'time' to remove timestamp
},
prettifier: require('pino-pretty') // not required, just an example of setting prettifier
// as well it is possible to set destination option
}
);
So it should be possible.
PS: I know there is the option to put a writestream with fs into it but I want to get the time formatted.
I found a practicable solution for me. Scince v 7 pino provides the multistream function by it selve. Now I can do all I wanted to do. Using destination and also make the timestamp pretty.
const streams = [
{stream: pino.destination('test.log')},
{stream: pretty({
colorize: true,
sync: true,
})}
]
const logger = pino({level: 'info', timestamp: pino.stdTimeFunctions.isoTime}, pino.multistream(streams))
logger.info('HELLO %s!', 'World')