npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pino-transport-rotating

v1.0.2

Published

Plugin for pino to transport logs to rotating files

Downloads

457

Readme

Pino Plugin - Rotating File Transport

This module provides a custom logging transport for the pino logger that uses rotating file streams to manage log files. It supports log file rotation based on size and time intervals, and it can be configured to include log file compression.

Features

  • File Rotation: Rotates log files based on size and time intervals.
  • Compression: Compresses rotated log files using gzip.
  • Custom Filename: Allows customization of the log file name.
  • Enable/Disable: Option to enable or disable logging.
  • Size Limit: Configurable size limit for log file rotation.
  • Interval: Configurable time interval for log file rotation.
  • Compression Method: Configurable compression method for rotated log files.
  • Immutability: Option to apply immutability to rotated log files.

Usage

To use the plugin, import it and provide the required configuration options:

import path from "node:path";
import { pino, LoggerOptions } from "pino";

const loggerOptions: LoggerOptions = {
  name: "server start",
  level: "trace",
  transport: {
    targets: [
      {
        level: "info",
        target: "pino-pretty",
        options: {
          colorize: true,
        },
      },
      {
        level: "info",
        target: "pino-transport-rotating",
        options: {
          dir: path.join(process.cwd(), "logs"),
          filename: "all",
          enabled: true,
          size: "1M",
          interval: "1d",
          compress: "gzip",
          immutable: true,
        },
      },
      {
        level: "error",
        target: "pino-transport-rotating",
        options: {
          dir: path.join(process.cwd(), "logs"),
          filename: "error",
          enabled: true,
          size: "1M",
          interval: "1d",
          compress: "gzip",
          immutable: true,
        },
      },
    ],
  },
};

const logger = pino(loggerOptions);

logger.info("Server started");
logger.error("An error occurred");

Configuration Options

The plugin accepts the following options:

  • dir (string, required): The directory where the log files will be saved.
  • filename (string, optional): The base name of the log file. Defaults to app.log.
  • enabled (boolean, optional): If false, logging is disabled. Defaults to true.
  • size (string, optional): The size at which to rotate the log files. Defaults to '1M'.
  • interval (string, optional): The interval at which to rotate the log files. Defaults to '1d'.
  • compress (string, optional): The compression method to use for rotated files. Defaults to 'gzip'.
  • immutable (boolean, optional): Whether to apply immutability to the rotated files. Defaults to true.

Example Configuration

{
  dir: '/var/log/app',
  filename: 'app',
  enabled: true,
  size: '1M',
  interval: '1d',
  compress: 'gzip',
  immutable: true,
}

File Rotation

The log files are rotated based on the following parameters:

  • Size: 10 MegaBytes (1M) - Log files are rotated when they reach this size (configurable).
  • Interval: 1 day (1d) - Log files are rotated daily (configurable).
  • Compression: gzip - Rotated files are compressed using gzip (configurable).
  • Filename Pattern: ${filename}-${date}.${index}.log - Log files are named based on the provided filename, date, and index.

Notes

  • Ensure that the directory specified in dir exists and is writable by the application.
  • The enabled option can be used to turn off logging without removing the transport configuration.
  • The compress option accepts various methods, but make sure the chosen method is supported by rotating-file-stream.

License

This project is licensed under the MIT License. See the LICENSE file for details.