Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
SpyLogger
✓ const SpyLogger = require('winston-spy');
✗ import SpyLogger from 'winston-spy';
This package is CommonJS-only and relies on `require` for module loading, reflecting its age and lack of ESM support.
winston.add (transport method)
✓ winston.add(winston.transports.SpyLogger, { spy: mySpy });
✗ logger.add(new SpyLogger({ spy: mySpy }));
The `winston-spy` package uses the old global `winston.add` and `winston.remove` API to attach transports. This API is deprecated in Winston v3+ which uses `winston.createLogger` with a `transports` array.
Demonstrates how to integrate `winston-spy` with `sinon` to intercept and assert Winston global logger calls in a test environment, reflecting the package's intended usage with older Winston APIs.
const winston = require('winston');
const sinon = require('sinon');
const SpyLogger = require('winston-spy');
// Create a Sinon spy function to capture log calls
const logSpy = sinon.spy();
// Remove the default Console transport (if any) from the global logger.
// This API is for older Winston versions (pre-v3).
winston.remove(winston.transports.Console);
// Add the SpyLogger transport, passing the spy function to capture logs.
winston.add(SpyLogger, { spy: logSpy });
// Define test message and metadata
const testMessage = 'Hello, test world!';
const testMeta = { service: 'test-service', requestId: 'abc-123' };
// Log messages using the Winston global logger
winston.log('info', testMessage, testMeta);
winston.debug('debug', 'Another message for the spy.');
// Assertions (using Node.js built-in assert for demonstration)
const assert = require('assert');
assert.ok(logSpy.calledTwice, 'Spy should have been called twice.');
assert.ok(logSpy.calledWith('info', testMessage, testMeta), 'First call should match info log.');
assert.ok(logSpy.calledWith('debug', 'Another message for the spy.'), 'Second call should match debug log.');
console.log('All assertions passed: logSpy successfully captured Winston calls.');
Debug
Known issues
breakingThis package is incompatible with Winston v3.x and newer versions. It relies on the global `winston.add()` and `winston.remove()` API for transport management, which was deprecated and replaced by `winston.createLogger()` and transport arrays in v3.x.fixConsider using a different testing strategy for modern Winston versions, such as directly mocking the `winston` logger instance or implementing a simple in-memory custom transport. If `winston-spy` is strictly required, downgrade `winston` to a 2.x version or earlier.
affects: >=0.2.0 (when used with Winston >=3.0.0)
gotchaThe `winston-spy` package does not list `winston` as a direct dependency in its `package.json`. You *must* explicitly include `winston` in your application's `package.json` dependencies for `winston-spy` to work correctly due to Node.js module caching behavior.fixEnsure `winston` is explicitly listed and installed as a dependency in your project: `npm install winston` or `yarn add winston`.
affects: >=0.1.0
deprecatedThe `winston-spy` package has not been updated since October 2014 and is considered abandoned. It uses old JavaScript syntax (`var`) and relies on an outdated `winston` API. While a fork exists, it also appears to be inactive for several years.fixEvaluate modern alternatives for testing Winston logging, such as directly mocking logger instances or implementing a custom in-memory transport that is compatible with current Winston versions.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: winston.transports.SpyLogger is not a constructor
Attempting to use `winston-spy` with `winston` v3.x or later, which has a different API for transport registration and logger instantiation.
fixThis package is incompatible with Winston v3+. You need to either downgrade Winston to v2.x or earlier, or refactor your tests to directly mock logger instances or use a modern custom transport, as `winston-spy` does not support the `winston.createLogger` API.
Cannot find module 'winston'
The `winston` package is not installed as a direct dependency in your project, which `winston-spy` expects as a peer dependency for correct module resolution.
fixInstall `winston` explicitly in your project: `npm install winston` or `yarn add winston`.
Audit
Dependencies
winstonrequiredRequired as a peer dependency by the application due to module caching; `winston-spy` relies on the host application's `winston` instance.
sinonrequiredUsed for creating spy functions to intercept log calls, as demonstrated in the package's usage examples.