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

s3-streamlogger-daily

v0.6.0

Published

Stream for logging to s3 with rotated object names. Usable as a wiston-file stream. This fork supports daily logging.

Downloads

530

Readme

s3-streamlogger

NPM version

A Writable Stream object that uploads to s3 objects, periodically rotating to a new object name.

See also tails3 for a script to tail the log files produced by s3-streamlogger.

Installation

npm install --save s3-streamlogger

Basic Usage

var S3StreamLogger = require('s3-streamlogger').S3StreamLogger;

var s3stream = new S3StreamLogger({
             bucket: "mys3bucket",
      access_key_id: "...",
  secret_access_key: "..."
});

s3stream.write("hello S3");

Use with Winston: Log to S3

npm install --save winston
npm install --save s3-streamlogger
var winston        = require('winston');
var S3StreamLogger = require('s3-streamlogger').S3StreamLogger;

var s3_stream = new S3StreamLogger({
             bucket: "mys3bucket",
      access_key_id: "...",
  secret_access_key: "..."
});

var logger = new (winston.Logger)({
  transports: [
    new (winston.transports.File)({
      stream: s3_stream
    })
  ]
});

logger.info('Hello Winston!');

Define subfolder

var S3StreamLogger = require('s3-streamlogger').S3StreamLogger;

var s3stream = new S3StreamLogger({
             bucket: "mys3bucket",
             folder: "my/nested/subfolder",
      access_key_id: "...",
  secret_access_key: "..."
});

s3stream.write("hello S3");

Add hostname information for tails3

tails3 expects messages to be logged as json (the default for the file transport), with hostname and (for critical errors), stack properties to each log object, in addition to the standard timestamp, level and message properties. You can provide these using the third "metadata" option to winston's log method:

logger.log(level, message, {hostname: ... , stack: ...});

Handling logging errors

When there is an error writing to s3, the stream emits an 'error' event with details. You should take care not to log these errors back to the same stream (as that is likely to cause infinite recursion). Instead log them to the console, to a file, or to SNS using winston-sns.

Note that these errors will result in uncaught exceptions unless you have an error event handler registered, for example:

s3_stream.on('error', function(err){
    // there was an error!
    some_other_logging_transport.log('error', 'logging transport error', err)
});

Options

bucket (required)

Name of the S3 bucket to upload data to. Must exist. Can also be provided as the environment variable BUCKET_NAME.

folder

An optional folder to stream log files to. Takes a path string, eg: "my/subfolder" or "nested".

access_key_id

AWS access key ID, must have putObject permission on the specified bucket. Can also be provided as the environment variable AWS_SECRET_ACCESS_KEY, or as any of the other authentication methods supported by the AWS SDK.

secret_access_key

AWS secret key for the access_key_id specified. Can also be provided as the environment variable AWS_SECRET_KEY_ID, or as any of the other authentication methods supported by the AWS SDK.

config

Configuration object for the AWS SDK. The full list of options is available on the AWS SDK Configuration Object page. This is an alternative to using access_key_id and secret_access_key and is overwritten by them if both are used.

name_format

Format of file names to create, accepts strftime specifiers. Defaults to "%Y-%m-%d-%H-%M-%S-%L-unknown-unknown.log". The Date() used to fill the format specifiers is created with the current UTC time, but still has the current timezone, so any specifiers that perform timezone conversion will return incorrect dates.

If you use a format of the form %Y-%m-%d-%H-%M-<stage>-<hostname>.log, then you can use tails3 to tail the log files being generated by S3StreamLogger.

rotate_every

Files will be rotated every rotate_every milliseconds. Defaults to 3600000 (60 minutes).

This fork also specifically supports daily rotation. rotate_every can either be an integer, or a string "day".

max_file_size

Files will be rotated when they reach max_file_size bytes. Defaults to 200 KB.

upload_every

Files will be uploaded every upload_every milliseconds. Defaults to 20 seconds.

buffer_size

Files will be uploaded if the un-uploaded data exceeds buffer_size bytes. Defaults to 10 KB.

server_side_encryption

The server side encryption AES256 algorithm used when storing objects in S3. Defaults to false.

License

ISC: equivalent to 2-clause BSD.