Reputation: 1211
I want to create separate files for every log levels, and it should store respective files. says,
sails.log.info('Info log');
It should store at info.log file.
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({}),
new (winston.transports.File)({
name: 'info-file',
filename: 'info.log',
level: 'info',
json: false
}),
new (winston.transports.File)({
name: 'error-file',
filename: 'error.log',
level: 'error',
json: false
}),
new (winston.transports.File)({
name: 'debug-file',
filename: 'debug.log',
level: 'debug',
json: false
})
]
});
In config/log.js
custom: logger
My problem is some logs are not shows in terminal, and info.log and debug.log files has not only info and debug log respectively.
How to achieve this?
Upvotes: 2
Views: 639
Reputation: 54
Well, looks like Winston writes to logs based on their numeric levels. So that error messages will be always written to info log, but info never to error log.
So I think it is better to separate to different instances in config/bootstrap.js:
sails.warnLog = new (winston.Logger)({
transports: [
new (winston.transports.Sentry)({
name: 'warn-Sentry',
dsn: '{my account dsn}',
patchGlobal: true
level: 'warn'
})
]});
sails.infLog = new (winston.Logger)({
transports: [
new (winston.transports.Loggly)({
name: 'info-Loggly',
subdomain: '{my subdomain}',
inputToken: '{my input token}'
level: 'info'
})
]});
sails.verbLog = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
name: 'verb-console',
timestamp: true,
prettyPrint: true,
colorize: true,
level: 'verbose'
})
]});
And then you can write to log:
sails.warnLog.warn('Warning');
sails.infLog.info('Information');
sails.verbLog.verbose('Verbose');
Upvotes: 1