thelicato / pino-rotating-file-stream

A transport for pino that rotates logs
https://www.npmjs.com/package/pino-rotating-file-stream
MIT License
5 stars 1 forks source link
log-rotation logging pino pino-transport

pino-rotating-file-stream

NPM Package Version

Description

This module provides a transport for pino to automatically rotates logs. Under the hood, it uses rotating-file-stream even though some fields have been added to the default Options.

CLI

The current version of this packages has only support for the module usage as described in the Programmatic Integration section. This feature will be added in next versions of the package. For now you can rely on @vrbo/pino-rotating-file for CLI integration.

Programmatic Integration

Install pino-rotating-file-stream alongside pino and set the transport to pino-rotating-file-stream:

const pino = require('pino')
const logger = pino({
  transport: {
    target: 'pino-rotating-file-stream',
    options: {
      filename: 'app.log', // Required
      path: './logs', // Required
    },
  },
})

logger.info('hi')

See also the example in the examples folder.

Options

The options are essentially the same provided by rotating-file-stream except form two new entries. The following list shows all the options with the default values:

{
  filename: string; // Specifies the name of the file. Required.
  path: string // Specifies the base path for files. Required.
  size: string // Specifies the file size to rotate the file. Default: '100M'.
  maxSize: string // Specifies the maximum size of rotated files to keep. Default: '1G'.
  interval: string // Specifies the time interval to rotate the file. Default: '7d'.
  compress: boolean | string | Function // Specifies compression method of rotated files. Default: 'gzip'.
  encoding: string // Specifies the default encoding. Default: 'utf8'.
  history: string // Specifies the history filename. Default: null.
  immutable: boolean // Never mutate file names. Default: null.
  initialRotation: boolean // Initial rotation based on not-rotated file timestamp. Default: null.
  intervalBoundary: boolean // Makes rotated file name with lower boundary of rotation period. Default: null.
  maxFiles: number // Specifies the maximum number of rotated files to keep. Default: null.
  mode: number // Proxied to fs.createWriteStream. Default: 0o666.
  omitExtension: // boolean Omits the .gz extension from compressed rotated files. Default: null.
  rotate: number // Enables the classical UNIX logrotate behaviour. Default: null.
  teeToStdout: boolean // Writes file content to stdout as well. Default: null.
}

License

MIT License © 2023 Angelo Delicato