Registry / logging / winston-redis-stream

winston-redis-stream

JSON →
library0.0.3jsnpmunverified

A fixed-length Redis transport for winston using Redis Streams (Redis 5.0+). Current version 0.0.3, last updated on npm. This is a fork of the original winston-redis, rewritten to use ioredis and Redis Streams for capped log storage. Unlike the original, it does not support Redis Pub/Sub for logging. The query method filters by time range and supports field selection. Requires Node >=8.11, winston ^3.0.0, and Redis server >=5.0.0. Lightweight, no external dependencies beyond winston and ioredis.

npm install winston-redis-stream
INSTALL
IMPORT
SIG · WINSTON-REDIS-STRE
W
winston-redis-stream
loggingjavascriptv0.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default import
import RedisTransport from 'winston-redis-stream'
const RedisTransport = require('winston-redis-stream').default
The package uses CommonJS, but default import works in ESM environments via interop. Avoid using .default with require.
require (CommonJS)
const RedisTransport = require('winston-redis-stream')
const RedisTransport = require('winston-redis-stream').RedisTransport
No named export; the transport is the default export.
winston.add
const winston = require('winston'); const RedisTransport = require('winston-redis-stream'); winston.add(new RedisTransport({...}))
winston.add(RedisTransport)
Must instantiate the transport with 'new'. Passing the class directly will fail.

Shows how to create a winston logger with the Redis transport, log a message, and query recent logs from Redis.

const winston = require('winston'); const RedisTransport = require('winston-redis-stream'); const logger = winston.createLogger({ level: 'info', transports: [ new RedisTransport({ host: process.env.REDIS_HOST || 'localhost', port: parseInt(process.env.REDIS_PORT || '6379'), auth: process.env.REDIS_PASSWORD || '', length: 200, container: 'winston', flatMeta: false }) ] }); logger.info('Hello Redis Streams!', { extra: 'metadata' }); setTimeout(() => { logger.query({ from: new Date() - 3600000, until: new Date(), limit: 10, order: 'desc', fields: ['level', 'message', 'timestamp', 'extra'] }, (err, results) => { if (err) throw err; results.redis.forEach(log => console.log(`${log.timestamp} ${log.level}: ${log.message}`)); }); }, 1000);
Debug
Known issues
breakingRequires Redis server >=5.0.0 for Redis Streams. Earlier versions are not supported.
fix
Upgrade Redis server to version 5.0.0 or later.
affects: >=0.0.0
breakingUses ioredis instead of node-redis. Existing code expecting the 'node-redis' client API will not work.
fix
Adjust any custom Redis client configuration to be compatible with ioredis options.
affects: >=0.0.0
breakingNo support for Redis Pub/Sub (stream method not tested). Only Redis Streams (XADD, XRANGE) are used.
fix
Use the original winston-redis if Pub/Sub logging is required.
affects: >=0.0.0
gotchaQuery method uses the 'redis' property in results, not a transport name.
fix
Access results.redis (array of logs) when using logger.query()
affects: >=0.0.0
gotchaThe 'meta' option stores metadata as a nested object by default. Set flatMeta: true to flatten.
fix
Add flatMeta: true to transport options if you want meta fields at top level.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Redis connection refused - connect ECONNREFUSED 127.0.0.1:6379
Redis server is not running or not accessible at default host/port.
fix
Start Redis server, or specify correct host/port in transport options.
TypeError: RedisTransport is not a constructor
Importing the transport incorrectly, e.g., using require('winston-redis-stream').default in CJS.
fix
Use const RedisTransport = require('winston-redis-stream'); without .default.
ERR wrong number of arguments for 'xadd' command
Using an older Redis version (<5.0) that does not support Streams.
fix
Upgrade Redis server to version 5.0 or higher.
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies
winstonrequiredpeer dependency — required for creating logger and using transport
Agent activity
29 hits · last 30 days
node
28
Resources
winston-redis-stream — npm install winston-redis-stream · libregistry