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

winston-redis-stream

v0.0.3

Published

A fixed-length Redis transport using streams for winston

Downloads

266

Readme

winston-redis-stream

A capped Redis transport for winston.

About

This package is a clone of winston-redis by Charlie Robbins, modified to use the new Streams feature of Redis included from version 5. It uses ioRedis1 rather than node-redis as the underlying client library because that supports the new stream commands. Otherwise the API is very similar.

The basic log method works.

The query method returns entries from the log selected by time:

const options = {
  from: new Date() - (24 * 60 * 60 * 1000),  // last 24 hrs
  until: new Date(),
  limit: 20,                                 // but only most recent 20 entries
  order: 'asc',                              // order earliest to most recent
  fields: ['level', 'message', 'timestamp']  // fields required
};

The "level" and "message" fields are always present. "timestamp" is a meta field and other meta fields which exist can also be selected.

logger.query(options, function (err, results) {
  if (err) {
    /* TODO: handle me */
    throw err;
  }
  results.redis.map(log => {
    console.log(`${log.timestamp} ${log.level}: ${log.message}` )
  })
});

The stream method has not been tried or tested and may well not work.

An example script "logreader.js" can be used to tail the log stream.

Requirements

  • NodeJS 8.11.x
  • Winston 3.x
  • Redis server version > 5.0.0

Usage

  const winston = require('winston');
  const redisTransport = require('winston-redis-stream');

  const logger = winston.createLogger({
    level: 'info',
    transports: [
      new redisTransport()
    ]
  });

  logger.log({
    level: "info",
    message: "redis is awesome",
    reason: "it's fast" // this will get stored as meta data
  });

This transport accepts the options accepted by the ioredis client:

  • host: (Default localhost) Remote host of the Redis server
  • port: (Default 6379) Port the Redis server is running on.
  • auth: (Default None) Password set on the Redis server

In addition to these, the Redis transport also accepts the following options.

  • redis: Either the redis client or the options for the redis client
  • length: (Default 200) Number of log messages to store.
  • container: (Default winston) Name of the Redis container you wish your logs to be in.
  • channel: (Default None) Name of the Redis channel to stream logs from.
  • meta: (Default {}) Custom fields to add to each log.
  • flatMeta: (Default false) Store meta data at the top level of the object rather than within a child meta object.

Metadata: Logged as JSON literal in Redis

Installation

Installing npm (node package manager)

  $ curl http://npmjs.org/install.sh | sh

Installing winston-redis

  $ npm install winston
  $ npm install winston-redis-stream

Run Tests

Winston-redis tests are written in mocha, using Abstract Winston Transport and designed to be run with npm.

  npm test

Author: Dick Middleton

 Originator: [Charlie Robbins](http://github.com/indexzero)