winstonjs/winston · error · Error
Logger is required for profiling
Error message
Logger is required for profiling
What it means
Profiler objects time operations and log a duration through their associated Logger. The constructor strictly validates the argument: it must be a real Logger instance (not a plain object or array), otherwise timing results could never be logged, so it throws.
Source
Thrown at lib/winston/profiler.js:25
'use strict';
/**
* TODO: add class description.
* @type {Profiler}
* @private
*/
class Profiler {
/**
* Constructor function for the Profiler instance used by
* `Logger.prototype.startTimer`. When done is called the timer will finish
* and log the duration.
* @param {!Logger} logger - TODO: add param description.
* @private
*/
constructor(logger) {
const Logger = require('./logger');
if (typeof logger !== 'object' || Array.isArray(logger) || !(logger instanceof Logger)) {
throw new Error('Logger is required for profiling');
} else {
this.logger = logger;
this.start = Date.now();
}
}
/**
* Ends the current timer (i.e. Profiler) instance and logs the `msg` along
* with the duration since creation.
* @returns {mixed} - TODO: add return description.
* @private
*/
done(...args) {
if (typeof args[args.length - 1] === 'function') {
// eslint-disable-next-line no-console
console.warn('Callback function no longer supported as of winston@3.0.0');
args.pop();
}View on GitHub (pinned to ff0b79de85)
Solutions
- Use `logger.startTimer()` / `profile()` on a real winston Logger instead of constructing Profiler manually.
- Ensure exactly one winston version is installed (`npm ls winston`) so `instanceof` checks pass.
- Pass the actual Logger instance returned by `winston.createLogger()`, not a stub or plain object.
- In tests, use the real Logger or a class that extends it rather than a duck-typed mock.
Example fix
// before
const profiler = new winston.Profiler({ log: () => {} }); // plain object
// after
const logger = winston.createLogger({ transports: [new winston.transports.Console()] });
const timer = logger.startTimer();
timer.done({ message: 'work finished' }); Defensive patterns
Strategy: type-guard
Validate before calling
const Logger = require('winston/lib/winston/logger');
if (!(maybeLogger instanceof Logger)) {
throw new TypeError('Profiler requires an actual winston Logger instance');
} Type guard
function isRealLogger(x) { return x instanceof require('winston').Logger; } Try / catch
try {
const p = new winston.Profiler(logger);
} catch (err) {
if (err.message === 'Logger is required for profiling') {
const p = logger.startTimer();
} else { throw err; }
} Prevention
- Use `logger.startTimer()` / `logger.profile(id)` instead of constructing Profiler directly
- Avoid plain-object logger mocks in tests; subclass Logger or use the real one
- Deduplicate winston installs (`npm ls winston`) to avoid instanceof mismatches
- Pass the createLogger() return value, never wrappers or stubs
When it happens
Trigger: Calling `new winston.Profiler(...)` (or `logger.startTimer()` internals) with `undefined`, a plain object, an array, or a non-Logger object; also passing something that looks like a logger but was created by another library or an older winston copy (fails the `instanceof Logger` check).
Common situations: Duplicated winston in node_modules (two copies -> instanceof mismatch); mocking a logger in tests with a plain object stub then calling startTimer; calling Profiler directly instead of via `logger.startTimer()`.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Logger is required to handle exceptions
- Logger is required to handle rejections
- ExceptionStream requires a TransportStream instance.
- Transports must WritableStreams in objectMode. Set { objectM
- RejectionStream requires a TransportStream instance.
AI-assisted analysis of winstonjs/winston@ff0b79de85 (2026-08-31).
Data as JSON: /api/errors/71a5e4d2f5351b6e.
Report an issue: GitHub.