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

winston-log-rotate-transport

v0.0.2

Published

A Transport for Winston which logs to a rotating file.

Downloads

7

Readme

winston-log-rotate-transport

A Winston transport for rotating log files. By default, the transport will rotate logs daily, however log rotation can be configured based on date, time, file size, etc.

winston-log-rotate-transport uses file-stream-rotator, and all options can be passed through.

Usage

Install

npm install winston-log-rotate

Add to your winston logger

import winston from "winston";
import { LogRotateTransport } from "winston-log-rotate-transport";

const logger = winston.createLogger({
  transports: [
    new LogRotateTransport({
      filename: "app-%DATE%",
      frequency: "daily", // Default
      datePattern: "YYYY-MM-DD", // Default
    }),
  ],
});

Options

All options from file-stream-rotator are accepted, as well as all options from winston's TransportStream class.

The filename, extension, frequency, and date_format option defaults are specific to this transport. (Not set by file-stream-rotator).

| Option | Description | Default | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | | filename | The base filename to log to. Full path can be included. If the path is omitted it will default to cwd. Accepts '%DATE'% placeholder. | 'winston-%DATE%' | | extension | File extension to be appended to the filename. This is separate from the filename. This is useful when using size restrictions or manual log rotation as the library will add a count (e.g. '.1' to the end of the filename.) | '.log' | | frequency | How often to rotate the log file. Options are 'daily' for daily rotation, 'date' based on date_format, '[1-12]h' to rotate every 1-12 hours, '[1-30m]' to rotate every 1-30 minutes. | 'daily' | | date_format | The date format to use when rotating logs based on the date. When the string representation of changes, the log file will be rotated. This is also substituted into the '%DATE%' placeholder in the filename. | 'YYYY-MM-DD' | | | | | | | All options from file-stream-rotator are accepted https://github.com/rogerc/file-stream-rotator/?tab=readme-ov-file#options | | | | All options from winston's TransportStream class are accepted. https://github.com/winstonjs/winston-transport/blob/master/index.d.ts#L25 | |

FAQ

Why this plugin?

Use this plugin if you use Winston and you want to rotate your logs.

winston-log-rotate-transport vs winston-daily-rotate-file

winston-daily-rotate-file is a popular choice for rotating logs with Winston. winston-log-rotate-transport is a similar transport, which also uses file-stream-rotator under the hood. The main difference is that winston-log-rotate-transport allows for more flexibility in log rotation, and is less opinionated. Additionally, winston-log-rotate-transport is a newer package, and uses v1 of file-stream-rotator. This is especially useful if you'd like to rotate log files manually at any point.

Can I manually rotate log files?

Yes! file-stream-rotator v1 offers this method and it is also available via a convenience method on the transport.

import { LogRotateTransport } from "winston-log-rotate-transport";

const transport = new LogRotateTransport({
  filename: "app-%DATE%",
  frequency: "daily",
  datePattern: "YYYY-MM-DD",
});

// Rotate the log file
transport.rotate();

Prior art

This plugin was inspired by winston-daily-rotate-file.

Contributing

Contributions are super welcome.

Developing

Clone the repo

git clone https://github.com/sebtoombs/vite-resolve-tsconfig-paths.git

Install dependencies

npm install

Write some code!

Build

npm run build

Don't forget, to pass CI, your code will need to pass npm run lint, npm run format:check npm test & npm run build

Share your contribution

To make a contribution;

  • Fork this repo
  • Create a branch for your change, branch naming is not important
  • Open a Pull Request against the main branch of this repo
    • PR title, labels etc are (at this stage) not important
  • Wait for a review
  • If approved, squash and merge
  • Your change will be included in the next release!