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

logrotate-stream

v0.2.9

Published

Pipe log data to a stream, fuggetabout rotation

Downloads

35,849

Readme

logrotate-stream

A Writable Stream that supports linux logrotate style options

Build Status Donate
NPM

example

On the command line:

  node app.js 2>&1 | logrotate-stream app.log --keep 3 --size '50m' --compress

As a module:

var stream = require('logrotate-stream')
  , toLogFile = stream({ file: './test.log', size: '100k', keep: 3 });

someStream.pipe(toLogFile);

the problem

Rotating logs that are being written to with stdio redirection sucks. Using a utility like logrotate doesn't automagically update your processes log file descriptor and you end up with several empty logs and one mega rotated log.

There's a couple ways to try and deal with this, but they all fall short:

1. Use winston's log rotation feature for nodejs apps

This requires adding a new dependency and possibly code changes around logging logic.

2. Restart your app on a process signal

Often times, production apps can't be restarted willy-nilly

3. Use the copytruncate feature of logrotate

This only works if you don't need to guarantee that all of your log lines are persisted. copytruncate performs a non-atomic copy before truncating the original log, which means you can lose data in the process if the copy is slow.

logrotate-stream tries to remedy this situation by acting as an intermediary between the application and the file system, piping stdin to log files and rotating those logfiles when necessary.

upstart woes

If you find yourself using logrotate-stream with upstart, there's a few things to consider. Piping to logrotate-stream in your exec line will cause upstart to track the pid of the logrotate process rather than your app. While stopping will still work (most likely emitting an EPIPE error on your app before exiting), it would be better if you used a named pipe to redirect your apps output:

chdir /path/to/app

pre-start script
  # create a named pipe
  mkfifo logpipe
  # create a backgrounded logrotate-stream process and
  # redirect the named pipe data to it
  logrotate-stream app.log --keep 3 --size 50m < logpipe &
end script

# start the app, redirecting stdout & stderr to the named pipe
exec /usr/local/bin/node index.js > logpipe 2>&1

This setup will register the correct pid with upstart, make sure your stdio is forwarded to logrotate-stream, and will properly kill the logrotate-stream process when your app is stopped.

options

file

The file log file to write data to.

size

The max file size of a log before rotation occurs. Supports 1024, 1k, 1m, 1g

keep

The number of rotated log files to keep (including the primary log file). Additional logs are deleted no rotation.

compress

Optionally compress rotated files with gzip.

install

With npm do:

npm install logrotate-stream