Coder Social home page Coder Social logo

winston-redis's Introduction

winston-redis

A capped Redis transport for winston.

Requirements

  • NodeJS 8.11.x
  • Winston 3.x

Usage

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

  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 node-redis 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

Run Tests

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

  npm test

winston-redis's People

Contributors

chjj avatar crisfavero avatar dabh avatar dependabot[bot] avatar farenheith avatar indexzero avatar mgibeau avatar mooski avatar moretti avatar shaharke avatar tolgaakyuz avatar ttrfwork avatar wbt avatar yads avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

winston-redis's Issues

SyntaxError: Unexpected token ...

I'm running the beta version of this module and an bit older version of node
[email protected]
node v7.10.1

in line 84 of lib/winston-redis.js

https://github.com/winstonjs/winston-redis/blob/master/lib/winston-redis.js#L85

    const { level, message, ...winstonMeta } = info
    const meta = Object.assign({}, winstonMeta, this.metadata)

the ... operator is usually used with unpacking the values of an array or skipping over values during the deconstruction of an array.

maybe there's a different use of this operator that I don't know about in a newer version of js?

what's the intended behavior of these two lines?

full stack trace:

/path/node_modules/winston-redis/lib/winston-redis.js:84
    const { level, message, ...winstonMeta } = info
                            ^^^
SyntaxError: Unexpected token ...
    at createScript (vm.js:53:10)
    at Object.runInThisContext (vm.js:95:10)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/path/utils/logger.js:2:1)

Error handling

Is there any support for error handling when a redis instance is not available? Currently the transport will just hang until it crashes. We want to use it as a transport in cases where the redis broker for messages is available and accepting messages, but not have the app crash if its unavailable or goes away while things are running. I can't really find a good solution of allowing this.

Multiple data types / channels support

It looks like the transport doesn't quite fit my requirements of pushing three (at this stage) types of data:

  1. text message
  2. integer message as a %
  3. integer message as a bug count

All of which will be sent on three different channels minimum at different times, in the form of:

{ id: update.timestamp, event: update.event, data: update.data }

which is consumed by subscribbers converting the messages into server sent events (SSE) (AKA EventSource) to be sent to a CLI somewhere on the internet.

Originally posted by @binarymist in #29 (comment)

New release

@indexzero @chjj can you guys take a look at master and see about releasing this to npm? Any thoughts on versioning? It should be backwards compatible with v1.0, however, I've moved winston and redis into peerDependencies. So I'm not sure if that would be considered a breaking change.

Update redis to 0.8.1

Redis 0.8.1 removes the hiredis optional dependency, preventing it from failing to build on SmartOS and causing npm to report a failure. This fixes an issue on Nodejitsu, since we use SmartOS on Joyent. Thanks!

Basic usage

Hi,

I'm trying to use winston with winston-redis. This is the first time I use winston. This is my code:

var winston = require('winston')
require('winston-redis')
winston.add(winston.transports.Redis)
winston.log('info', 'foo')

There is no error. But if I go to redis-cli and type "lrange winston 0 -1" this is the output

1) "undefined: undefined"

I'm using winston 0.5.3 and redis-winston 0.1.0

Thanks.

Node js versions

Hi,

After installing winston-redis via npm I'm receiving the following warning:

npm WARN engine [email protected]: wanted: {"node":"0.8.x || 0.11.x"} (current: {"node":"0.10.33","npm":"2.1.11"})

I know it's not a big issue but perhaps this needs updating. Version 0.8 of node was released nearly 2 years ago. Same issue with npm - some major updates have been included.

Unable to install winston-redis 3.1.0 with redis 3.1.2 (want 2.8.0)

When installing:

$ npm install winston-redis
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/redis
npm ERR!   redis@"^3.1.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer redis@"^2.8.0" from [email protected]
npm ERR! node_modules/winston-redis
npm ERR!   winston-redis@"*" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

After removing redis, I saw the winston-redis package.json use older version of redis (2.8.0) :

{
  "name": "winston-redis",
  "description": "A fixed-length Redis transport for winston",
  "version": "3.1.0",
  "author": "Charlie Robbins <[email protected]>",
  "repository": {
    "type": "git",
    "url": "[email protected]:winstonjs/winston-redis.git"
  },
  "keywords": [
    "logging",
    "sysadmin",
    "tools",
    "winston",
    "redis"
  ],
  "dependencies": {
    "async": "^2.6.1",
    "lodash": "^4.6.1",
    "winston-transport": "^4.2.0"
  },
  "devDependencies": {
    "abstract-winston-transport": "^0.5.1",
    "mocha": "^5.2.0",
    "redis": "^2.8.0"
  },
  "peerDependencies": {
    "redis": "^2.8.0",
    "winston": "^3.0.0"
  },
  "main": "./lib/winston-redis",
  "scripts": {
    "test": "mocha test/*-test.js --exit"
  },
  "engines": {
    "node": ">=8.11.x"
  },
  "license": "MIT"
}

Meta data should be logged at the top level

Given this code:

logger.log({
    level: 'info',
    message: 'My message',
    additional: 'More stuff'
});

Other transports, such as File transport, log this JSON:

{"level":"info","message":"My message","additional":"More stuff"}

Whereas winston-redis logs this JSON:

{"level":"info","message":"My message","meta":{"additional":"More stuff"}}

Is it possible to add an option to log the meta data at the top level rather than as a child property?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.