sfa

stream-file-archive

A Node.js Streams2 log archiver, pipe to stream-file-archive and it will create time-rotated logs.

Showing:

Popularity

Downloads/wk

81

GitHub Stars

9

Maintenance

Last Commit

3yrs ago

Contributors

2

Package

Dependencies

4

Size (min+gzip)

8.1KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

stream-file-archive

NPM

Easy log rotation for Node.js

Supports:

  • Output your logs to time-rotated log files.
  • Optionally gzip the logs once they are no longer current
  • Optionally maintain a symlink to the currently active log file
  • Native Streams2 (0.10.x+) with backwards compatibility

Can directly plug into smart-tee, e.g.:

node foo.js 2>&1 | smart-tee --s stdout --s stream-file-archive --path logs/app-%Y-%m-%d.log

Usage:

var rotator = require("stream-file-archive")({
  path: "logs/app-%Y-%m-%d.log",  // Write logs rotated by the day
  symlink: "logs/current.log",    // Maintain a symlink called current.log
  compress: true,                 // Gzip old log files
})

my_logger_thingy.pipe(rotator)

Options

path

A string file path with any of the below options to define rotation schedule:

e.g. logs/mylog-%Y-%m-%d.log would result in logs like logs/mylog-2013-06-01.log

  • %Y 4-digit year e.g. 2013
  • %y 2-digit year e.g. 13
  • %m month (01..12)
  • %d day of month (01..31)
  • %F iso8601 date portion (e.g. 2012-09-24)
  • %H hour (00..23)
  • %M minute (00..59)
  • %S second (00..61)
  • %T iso8601 time portion to the second (e.g.: 15:12:47)

See strftime documentation for all specifiers.

A path to a symlink that will be maintained to point at the current log file.

compress

Boolean value, whether to gzip the files once they aren't being written to.

Events

Emits a done event when the source stream has finished and all file stream work is complete.

NOTES:

Currently only timestamps files in UTC timezone. Pull requests welcome!

LICENSE

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100