npm.io
0.0.13 • Published 15h ago

@tryghost/bunyan-rotating-filestream

Licence
MIT
Version
0.0.13
Deps
1
Size
19 kB
Vulns
0
Weekly
0
Stars
37

Bunyan Rotating Filestream

Install

npm install @tryghost/bunyan-rotating-filestream --save

or

pnpm add @tryghost/bunyan-rotating-filestream

Purpose

A rotating file stream for the bunyan logger, supporting period-based and size-based rotation, gzip compression of archives, and limits on the number and total size of archived files.

Usage

Create a bunyan logger using the stream:

const log = bunyan.createLogger({
    name: 'foo',
    streams: [
        {
            stream: new RotatingFileStream({
                path: '/var/log/foo.log',
                period: '1d', // daily rotation
                totalFiles: 10, // keep up to 10 backup copies
                rotateExisting: true, // Give ourselves a clean file when we start up, based on period
                threshold: '10m', // Rotate log files larger than 10 megabytes
                totalSize: '20m', // Don't keep more than 20mb of archived log files
                gzip: true, // Compress the archive log files to save space
            }),
        },
    ],
});

Other options include startNewFile to always open a new file on start-up.

Develop

This is a mono repository, managed with Nx.

Follow the instructions for the top-level repo.

  1. git clone this repo & cd into it as usual
  2. Run pnpm install to install top-level dependencies.

Run

  • pnpm dev

Test

  • pnpm lint runs oxlint
  • pnpm test runs lint and tests

Credit

Many thanks to @Rcomian for their work on the original bunyan-rotating-file-stream project, this project borrows lots of the code and all of the ideas in the original.

Copyright (c) 2013-2026 Ghost Foundation - Released under the MIT license.