You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there,
I'm new to pino so sorry if my question is very basic.
I'm trying to use a custom transport to log to a file with this format: application-<year>-<month>-<date>.log
I want it to switch files when the day ends / transfers.
Currently I have this in my custom transport:
import{createWriteStream}from"fs";constpad=num=>(num>9) ? num : `0${num}`;exportdefault(options)=>{constfilename=generateFileName(options.filename);returncreateWriteStream(filename,{flags: 'a'});}functiongenerateFileName(filenameParams){constcurrentDate=newDate();constfilename=filenameParams.replace('<year>',currentDate.getFullYear()).replace('<month>',pad(currentDate.getMonth()+1)).replace('<date>',pad(currentDate.getDate()))returnfilename;}
This works for the first file but not for subsequent dates.
I understand this is because the custom transport is only called once on initialization and not each time the write functionality is called.
I've been scouring the net for examples for my use case to no avail. Help would be much appreciated.
The text was updated successfully, but these errors were encountered:
Hey guys,
thanks for the replies. I'm trying out using my system tools for now using a VM, but I'll take a look at the pino-roll module too.
Thanks a bunch!
Hi there,
I'm new to pino so sorry if my question is very basic.
I'm trying to use a custom transport to log to a file with this format:
application-<year>-<month>-<date>.log
I want it to switch files when the day ends / transfers.
Currently I have this in my custom transport:
My logger:
This works for the first file but not for subsequent dates.
I understand this is because the custom transport is only called once on initialization and not each time the write functionality is called.
I've been scouring the net for examples for my use case to no avail. Help would be much appreciated.
The text was updated successfully, but these errors were encountered: