{"id":14355,"library":"winston-spy","title":"Winston Spy Logger","description":"winston-spy is a small module that provides a custom Winston transport designed for testing Winston logging interactions using spy functions. It allows developers to intercept log messages and assert their content and calls within test suites. The package is currently at version 0.2.0 and has not seen active development since 2014, indicating it is abandoned. A key design choice is that winston-spy does not list winston as a direct dependency in its package.json, requiring the consuming application to install winston itself. This approach aims to ensure that winston-spy operates on the exact same winston module instance used by the application, mitigating Node.js module caching issues. However, this also means it relies on older winston APIs (winston.add, winston.remove) and is not compatible with modern winston v3.x+ versions.","status":"abandoned","version":"0.2.0","language":"javascript","source_language":"en","source_url":"git@github.com:manuelcabral/winston-sinon","tags":["javascript","winston","testing","test","spies"],"install":[{"cmd":"npm install winston-spy","lang":"bash","label":"npm"},{"cmd":"yarn add winston-spy","lang":"bash","label":"yarn"},{"cmd":"pnpm add winston-spy","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency by the application due to module caching; `winston-spy` relies on the host application's `winston` instance.","package":"winston","optional":false},{"reason":"Used for creating spy functions to intercept log calls, as demonstrated in the package's usage examples.","package":"sinon","optional":false}],"imports":[{"note":"This package is CommonJS-only and relies on `require` for module loading, reflecting its age and lack of ESM support.","wrong":"import SpyLogger from 'winston-spy';","symbol":"SpyLogger","correct":"const SpyLogger = require('winston-spy');"},{"note":"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.","wrong":"logger.add(new SpyLogger({ spy: mySpy }));","symbol":"winston.add (transport method)","correct":"winston.add(winston.transports.SpyLogger, { spy: mySpy });"}],"quickstart":{"code":"const winston = require('winston');\nconst sinon = require('sinon');\nconst SpyLogger = require('winston-spy');\n\n// Create a Sinon spy function to capture log calls\nconst logSpy = sinon.spy();\n\n// Remove the default Console transport (if any) from the global logger.\n// This API is for older Winston versions (pre-v3).\nwinston.remove(winston.transports.Console);\n\n// Add the SpyLogger transport, passing the spy function to capture logs.\nwinston.add(SpyLogger, { spy: logSpy });\n\n// Define test message and metadata\nconst testMessage = 'Hello, test world!';\nconst testMeta = { service: 'test-service', requestId: 'abc-123' };\n\n// Log messages using the Winston global logger\nwinston.log('info', testMessage, testMeta);\nwinston.debug('debug', 'Another message for the spy.');\n\n// Assertions (using Node.js built-in assert for demonstration)\nconst assert = require('assert');\nassert.ok(logSpy.calledTwice, 'Spy should have been called twice.');\nassert.ok(logSpy.calledWith('info', testMessage, testMeta), 'First call should match info log.');\nassert.ok(logSpy.calledWith('debug', 'Another message for the spy.'), 'Second call should match debug log.');\n\nconsole.log('All assertions passed: logSpy successfully captured Winston calls.');","lang":"javascript","description":"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."},"warnings":[{"fix":"Consider 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.","message":"This 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.","severity":"breaking","affected_versions":">=0.2.0 (when used with Winston >=3.0.0)"},{"fix":"Ensure `winston` is explicitly listed and installed as a dependency in your project: `npm install winston` or `yarn add winston`.","message":"The `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.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Evaluate 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.","message":"The `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.","severity":"deprecated","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.2.0':48 '2014':56 'abandon':60 'activ':53 'aim':91 'allow':27 'also':117 'api':124 'applic':84,109 'approach':90 'assert':34 'cach':113 'call':38 'choic':64 'compat':130 'consum':83 'content':36 'current':45 'custom':14 'depend':77 'design':17,63 'develop':28,54 'direct':76 'ensur':93 'exact':101 'function':25 'howev':115 'indic':57 'instal':86 'instanc':105 'interact':22 'intercept':30 'issu':114 'javascript':136 'key':62 'list':72 'log':21,31 'logger':3 'mean':118 'messag':32 'mitig':110 'modern':132 'modul':10,104,112 'node.js':111 'older':122 'oper':98 'packag':43 'package.json':80 'provid':12 'reli':120 'requir':81 'seen':52 'sinc':55 'small':9 'spi':2,6,24,69,97,140 'suit':41 'test':19,40,138,139 'transport':16 'use':23,106 'v3.x':134 'version':47,135 'winston':1,5,15,20,68,73,87,96,103,123,133,137 'winston-spi':4,67,95 'winston.add':125 'winston.remove':126 'within':39","created_at":"2026-04-20T01:59:16.733129+00:00","updated_at":"2026-04-20T01:59:16.733129+00:00","problems":[{"fix":"This 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.","cause":"Attempting to use `winston-spy` with `winston` v3.x or later, which has a different API for transport registration and logger instantiation.","error":"TypeError: winston.transports.SpyLogger is not a constructor"},{"fix":"Install `winston` explicitly in your project: `npm install winston` or `yarn add winston`.","cause":"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.","error":"Cannot find module 'winston'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/winston-spy","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","observability"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}