balderdashy / balderdashy/sails
Winston logger incompatibilities: 'self._addDefaultMeta is not a function'
- Dominant language
- JavaScript
- Stars
- 22.8k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
**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
Contributor guide
Research direction
Start with the logger configuration in log.js and reproduce the failure during sails lift using Sails 1.1.0, Node 11.4.0, and Winston 3.2.1. Read winston/lib/winston/create-logger.js, captains-log/lib/write.js, and sails-hook-orm/lib/initialize.js around the reported stack frames. Done means the application lifts successfully with the custom Winston logger and no self._addDefaultMeta error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100