winston version?_winston@2winston@3 node -v outputs:_ v8.11.1I need to stringify all the logs, so instead of change all the logs in my app i'm trying to write a transform function:
let opts = {
level: level,
format: winston.format.combine(
// I copied this from [WIKI](https://github.com/winstonjs/winston#creating-custom-formats)
winston.format((info, opts) => {
return JSON.stringify(info);;
}),
winston.format.timestamp()
),
transports: [...]
}
return winston.createLogger(opts);
all my logs are in this format:
logger.info({....})
getting this error:
node_modules\logform\combine.js:37
throw new Error([
^
Error: No transform function found on format. Did you create a format instance?
const myFormat = format(formatFn);
const instance = myFormat();
Did I missing something?
format() returns a 'factory' for your format, so to get an instance of it, you need to do format((info, opts) => ...)() (note the extra parens on the end). Double checked with your example and it worked for me. Good luck!
@MHDMAM here is a sample which kept me going (using winston v3.3.3):
const winston = require('winston');
const myFormatter = winston.format((info) => {
const {level, message} = info;
info.level = `${level} with modified label`;
info.message = `${message} with modified message`;
return info;
})();
const logger = winston.createLogger({
format: winston.format.combine(
myFormatter,
winston.format.simple(),
),
transports: [
new winston.transports.Console(),
],
});
logger.info('Test message'); // "info with modified label: Test message with modified message"
Most helpful comment
format()returns a 'factory' for your format, so to get an instance of it, you need to doformat((info, opts) => ...)()(note the extra parens on the end). Double checked with your example and it worked for me. Good luck!