Search code examples
nestpino

How can I rotate log files with nestjs-pino?


I'm developing server with nestjs and I wanna rotate log files with nestjs-pino like winston-daily-rotate-file. I chose nest-pino for logger beacause of its simplicity and being much more comfortable than winston. However, I don't know how to rotate log files with nest-pino and cannot find the way. Does anyone know how to rotate file with nest-pino?

I searched the way for very long time but I couldn't find it. I'm considering using logrotate if there isn't package for rotating files with nest-pino. BUT, I want to use package for more simplicity.


Solution

  • You can use rotating-file-stream (https://www.npmjs.com/package/rotating-file-stream) . This module is fully compatible with pino. For transport of logs to file we have default transport 'pino/file' in pino ,instead we need to use this module.This module will create file and write in that file , so it will watch this file and rotate it. But log rotation has performance overhead with this module. Instead use 'log-rotate' if it meets your use case.