[Bug]: Document that format: customFormatter()
won't work and/or provide a more informative error when the mistake is made
#2428
Labels
🔎 Search Terms
logform, custom formats, createLogger
The problem
The Creating custom formats section implies that you can assign your custom format to the
createLogger.format
key, but this is not the case. This is the entire code example given:This does not show how to use
scream
orwhisper
withcreateLogger
, so this would be the natural expectation:Not only does this fail to work, it prints
undefined
for every log message, making it difficult to troubleshoot. Here's my guess for why this is wrong: winston requires a "base" format of some kind—e.g.,format.simple()
,format.json()
, etc.—to beformat.combine
d with the custom format. So while the above will printundefined
for every log, this will print the log as expected:This should be mentioned somewhere in the documentation so users can troubleshoot this mistake without looking at the source code.
What version of Winston presents the issue?
v3.12.0
What version of Node are you using?
v20.10.0
If this worked in a previous version of Winston, which was it?
No response
Minimum Working Example
import { createLogger, Logger, format, transports } from 'winston';
const logPrefix = format((info, opts) => {
return info;
});
const logger = createLogger({
level: 'debug',
format: logPrefix(), // compare to this line instead: format: format.combine(logPrefix(), format.simple()),
transports: new transports.Console(),
exceptionHandlers: new transports.Console(),
rejectionHandlers: new transports.Console(),
exitOnError: false,
});
logger.debug(
foobar
);Additional information
No response
The text was updated successfully, but these errors were encountered: