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

mongo-log-rotator

v0.2.1

Published

Rotates MongoDB logs using cron-like scheduling.

Downloads

6

Readme

mongo-log-rotator

Library for rotating MongoDB logs on a cron-like schedule. Includes support for compression and S3 uploading.

Rotator can be used both locally on the same machine as mongo, or remotely. Most of the features are only available when running locally because it needs access to Mongo's log files.

Installation

npm install mongo-log-rotator

Usage

var Rotator = require('mongo-log-rotator');

// Every 30 seconds.
var schedule = '30 * * * * *';

var rotator = new Rotator(schedule, { 
  mongoURL: 'mongodb://user:pass@localhost:27017', 
  /* other options */ 
});

rotator.on('rotate', function(newFile) {
  // A rotation has been completed.
  // newFile is the path to the rotated log file.
});

rotator.start();

Schedule

Cron scheduling is implemented using the node-cron module. The pattern documentation can be found at crontab.org.

Examples:

  • 30 * * * * * every 30 seconds.
  • 0 0 * * * * ever hour.
  • 0 0 0 15 * * the 15th of every month.

Options

  • mongoURL (required): The fully qualified mongo URL. For example: mongodb://user:pass@localhost:27017. Rotator requires admin privileges on the database to issue the logRotate command.
  • mongoLog: If running locally (recommended), this is the full path to the mongo log file. This is required if using the compression or s3 uploading features.
  • autoStart: Defaults to false. Whether or not to automatically start rotating. If false, you must call start() to begin the cron task.
  • compress: Defaults to false. Whether or not to compress logs once they've been rotated. If enabled, the original, uncompressed log file will be deleted once compressed.
  • s3Upload: Defaults to false. Whether or not to upload rotated logs to s3.
  • s3Bucket: The S3 bucket to upload log files. Required if s3Upload is enabled.
  • awsAccessKeyID: AWS access key for uploading data to s3. Required if s3Upload is enabled.
  • awsSecretAccessKey: AWS secret key for uploading data to s3. Required if s3Upload is enabled.
  • autoDelete: Defaults to false. Whether or not to automatically delete rotated log files. Should be used on conjunction with s3Upload. If the upload to S3 fails, the log file will not be deleted.

start()

Starts the Rotator cron schedule. This can be skipped if the autoStart option is enabled.

rotator.start();

stop()

Stops the Rotator cron schedule. If a rotation is currently in process, it will not be interrupted.

rotator.stop();

Events

Event: 'rotate'

Occurs whenever the mongo log is rotated.

  • newFile (string) The path to the rotated log file.

Event: 'error'

Emitted whenever an error occurs at any stage of the rotation process. Errors will not stop the rotator schedule.

  • err (Error) The error that occurred.

Event: 'debug'

Prints information about what is occurring. Useful for debugging why something may not be working.

  • msg (string) The debug message.