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

rolling-file

v1.1.0

Published

Write to a file until limits you define are reached, after which a new file is created to and written to until its limits are reached, and so on.

Downloads

300

Readme

rolling-file

Write to a file until limits you've defined are reached, after which a new file is created and written to until its limits are reached, and so on. Writing is done using write streams.

Installation

npm install rolling-file

Examples

Roll by File Size

var rollingFile = require('rolling-file');
var f = rollingFile('./logs', { fileName: 'foo', byteLimit: '500 MB' });
f.write('Hello, World!');

...

f.end();

Roll by Time Interval

var rollingFile = require('rolling-file');
var f = rollingFile('./logs', { fileName: 'foo', interval: '1 day' });
f.write('Hello, World!');

...

f.end();

Roll by File Size and Time Interval

var rollingFile = require('rolling-file');
var f = rollingFile('./logs', { fileName: 'foo', byteLimit: '500 MB', interval: '1 day' });
f.write('Hello, World!');

...

f.end();

API

rollingFile ( directory, [, configuration ] )

Parameters:

  • directory - A required string that gives the directory path of where log files should be deposited.
  • configuration - A optional object that defines how the file rolling should occur.

Returns: An object with properties for writing to the data stream:

  • end ( [ content [ , callback ] ] ) - End the rolling file stream, optionally proving content and a callback function that will be called when the content has been written.
  • write ( content [ , callback ] ) - Write content to the rolling file stream, optionally proving a callback function that will be called when the content has been written.

Configuration

The configuration parameter has the following options:

  • byteLimit - The maximum size for a file in bytes before output will be put into a new file. The value must be a number, optionally followed by a metric prefix '(kilo, mega, giga, tera, peta, exa, zetta, yotta). For example: 2000000, 2G, 2 giga, 2 gigabytes, 2GB, 2000KB. The default value is 2 GB.
  • delimiter - The character to use to separate entries into the rolling file. The default value is '\n'.
  • fileEncoding - The encoding type to use on the file. All of NodeJS' encoding types are acceptable values. Defaults to 'utf8'.
  • fileName - The file name prefix to add to the start of the file.
  • fileExtension - The extension to add to the end of the file name. By default this value is '.log'.
  • interval - The size of the time interval for each file.
  • startOfDay - The time to consider as the start of the day. This does nothing unless an interval is specified.

File Naming

The naming of files is an automated process through which you have some control. You can provide a file name prefix and the file extension. A timestamp and an index are also added to the file name automatically.

The timestamp is formatted as YYYY-MM-DD-HHMMSS and it will contain the time stamp for when it was first written to if no interval is provided. If an interval is provided then the time stamp will reflect that time that lines up with that interval.

The index is added after the timestamp and is used to split multiple files that fit the same timestamp.

See below for some configurations and their potential output:

config = { fileName: 'foo', fileExtension: 'bar', byteLimit: '2 GB' };
possible_outputs = [
    'foo.2000-01-01-102345.0.bar',
    'foo.2000-01-01-102345.1.bar'
    'foo.2000-01-01-180200.0.bar'
]
config = { fileName: '', interval: '1 day', byteLimit: '500 MB' };
possible_outputs = [
    '2000-01-01-000000.0.log',
    '2000-01-01-000000.1.log',
    '2000-01-02-000000.0.log',
    '2000-01-03-000000.0.log'
];