sails: Winston logger incompatibilities: 'self._addDefaultMeta is not a function'
Sails version: 1.1.0 Node version: v11.4.0 NPM version: 6.8.0 DB adapter name: sails-mongo DB adapter version: 1.0.1 Operating system: MacOSX
I currently experiencing some problem with integration of Winston Log library with Sails JS. It seems that since winston 3.2.1 has been released, it is no more possible to use a Winston Logger in a sailsJS application.
log.js:
var winston = require('winston');
require('winston-daily-rotate-file');
// Creating a custom logger based on Winston library
const customLogger = winston.createLogger({
level: 'info',
format: winston.format.simple(),
transports: [
new winston.transports.DailyRotateFile({
level: 'silly',
dirname: 'storage/logs',
filename: 'ctc-%DATE%.log',
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
})
]
});
// If we're not in production then log to the `console` too.
if (process.env.NODE_ENV !== 'production') {
customLogger.add(new winston.transports.Console({
format: winston.format.simple(),
level: 'silly'
}));
}
module.exports.log = {
// Pass in our custom logger, and pass all log levels through.
custom: customLogger,
// Disable captain's log so it doesn't prefix or stringify our meta data.
inspect: false
};
Error that I get on sails lift:
/Users/test/Documents/repositories/aze/node_modules/winston/lib/winston/create-logger.js:80
self._addDefaultMeta(info);
^
TypeError: self._addDefaultMeta is not a function
at Function.DerivedLogger.(anonymous function) (/Users/test/Documents/repositories/aze/node_modules/winston/lib/winston/create-logger.js:80:14)
at Function._writeLogToConsole [as info] (/Users/test/Documents/repositories/aze/node_modules/captains-log/lib/write.js:47:20)
at async.auto._buildOntology (/Users/test/Documents/repositories/aze/node_modules/sails-hook-orm/lib/initialize.js:445:19)
Reference By : https://github.com/winstonjs/winston/issues/1577#issuecomment-458963380
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 20 (13 by maintainers)
A sample project on how I use Winston Logger is here: https://github.com/luislobo/sails-winston-logger-example
Created PR that should fix this. https://github.com/balderdashy/captains-log/pull/25
Until 3.2.0 everything was working fine. Seems to be an incompatibility to use custom logger un sails since Winston version 3.2.1
@johnabrams7 To your question about the docs not working anymore with the latest winston version: yes, that example no longer works.
One configuration that I find appealing and nice, is the one I included in the example project mentioned above, that has
/config/log.jsas:With the version 3.2.0 I have the error too. I need to go into the version 3.1.0 to avoid this error.
I have sails 1.1.0
@johnabrams7 I’ve updated the PR for the docs too.
Thanks @johnabrams7 , doing rm -rf node_modules && npm install didn’t solve the problem but upgrading the captains-log explicitly to v2.0.3 solved the problem.
@abilash1104 Have you tried rebuilding the node_modules folder in sails@1.2.3 with:
rm -rf node_modules && npm installto verify the latest captains-log 2.0.3 is being used?Thanks @luislobo ! Everyone can apply this update by rebuilding their node_modules folder with:
rm -rf node_modules && npm install(run in the project dir)@kierans @Themandunord @wawanopoulos
@rachaelshaw @johnabrams7 a new version of captains-log should be published in npm for this to be fully fixed
https://github.com/balderdashy/sails-docs/pull/1288
@raqem I’ve just submitted another commit in that PR based on @mikermcneil comments. Should be good to go