mcollina / pino-roll

A Pino transport that automatically rolls your log files
MIT License
45 stars 11 forks source link

How to set log filename like log4js yyyy-MM-dd.log? #87

Closed jinwyp closed 1 month ago

jinwyp commented 4 months ago

When set options to frequency: 'daily' The log filename is error.log.1 error.log.2

How to set log filename like error-yyyy-MM-dd.log? ex error-20240623.log

Is it possible to customize filename like log4js ?
"pattern" : "-yyyy-MM-dd.log",

mcollina commented 4 months ago

Thanks for reporting! Currently it's not possible to customize the file name in that way. Would you like to send a Pull Request to address this issue? Remember to add unit tests.

subahanumanth commented 1 month ago

@mcollina May I help you on this?

mcollina commented 1 month ago

@subahanumanth go ahead and do it!

subahanumanth commented 1 month ago

@mcollina This problem can be solved by adding a dateFormat option, which accepts a format string such as:

If the dateFormat option is provided, we can append the current date in the specified format to the end of the file name. For example: error-2024-09-24.log.1. However this will not be applicable for custom frequency.

I believe this approach should work well. Any other suggestions are welcome!