Reputation:
I'm currently using Sails v0.10.0-rc7
and tried to forward the console logs into a file.
Some older threads described a way to do this by adding the following lines to the config/log.js
:
module.exports = {
log: {
level: 'info',
filePath: 'someFile.log'
}
};
But this doesn't seem to work anymore.
Sails uses the subproject captains-log which formerly encapsulated winston. According to the README.md I changed the config/log.js
to:
var winston = require('winston');
module.exports = {
'log': {
'custom': new (winston.Logger)({
'transports': [
new (winston.transports.Console)({
'level': 'info',
'colorize': true,
'timestamp': false,
'json': false
}),
new winston.transports.File({
'level': 'debug',
'colorize': false,
'timestamp': true,
'json': true,
'filename': './logs/test.log',
'maxsize': 5120000,
'maxFiles': 3
})
]
})
}
};
Well, that works, but the logged messages always have a colored prefix within the message text. So the output in the console looks like
info: info:
info: info:
info: info: Sails <|
info: info: v0.10.0-rc7 |\
info: info: /|.\
info: info: / || \
info: info: ,' |' \
info: info: .-'.-==|/_--'
info: info: `--'-------'
info: info: __---___--___---___--___---___--___
info: info: ____---___--___---___--___---___--___-__
info: info:
(with both info tags colored in green) and the log file messages look like
{"level":"info","message":"\u001b[32minfo: \u001b[39m","timestamp":"2014-07-02T10:51:13.517Z"}
{"level":"info","message":"\u001b[32minfo: \u001b[39m","timestamp":"2014-07-02T10:51:13.517Z"}
{"level":"info","message":"\u001b[32minfo: \u001b[39m Sails <|","timestamp":"2014-07-02T10:51:13.517Z"}
{"level":"info","message":"\u001b[32minfo: \u001b[39m v0.10.0-rc7 |\\","timestamp":"2014-07-02T10:51:13.517Z"}
{"level":"info","message":"\u001b[32minfo: \u001b[39m /|.\\","timestamp":"2014-07-02T10:51:13.517Z"}
{"level":"info","message":"\u001b[32minfo: \u001b[39m / || \\","timestamp":"2014-07-02T10:51:13.517Z"}
{"level":"info","message":"\u001b[32minfo: \u001b[39m ,' |' \\","timestamp":"2014-07-02T10:51:13.527Z"}
{"level":"info","message":"\u001b[32minfo: \u001b[39m .-'.-==|/_--'","timestamp":"2014-07-02T10:51:13.527Z"}
{"level":"info","message":"\u001b[32minfo: \u001b[39m `--'-------' ","timestamp":"2014-07-02T10:51:13.527Z"}
{"level":"info","message":"\u001b[32minfo: \u001b[39m __---___--___---___--___---___--___","timestamp":"2014-07-02T10:51:13.527Z"}
{"level":"info","message":"\u001b[32minfo: \u001b[39m ____---___--___---___--___---___--___-__","timestamp":"2014-07-02T10:51:13.527Z"}
{"level":"info","message":"\u001b[32minfo: \u001b[39m","timestamp":"2014-07-02T10:51:13.527Z"}
Working in production mode supresses the prefixes, but I still have some color codings in the log messages.
So, does anybody have an idea how to get rid of the prefixes and color codings in the log messages?
Upvotes: 6
Views: 1740
Reputation:
I was able to accomplish my goal by adding colors: false
:
var winston = require('winston');
module.exports = {
'log': {
'colors': false,
'custom': new (winston.Logger)({
'transports': [
new (winston.transports.Console)({
'level': 'info',
'colorize': true,
'timestamp': false,
'json': false
}),
new winston.transports.File({
'level': 'debug',
'colorize': false,
'timestamp': true,
'json': true,
'filename': './logs/test.log',
'maxsize': 5120000,
'maxFiles': 3
})
]
})
}
};
Upvotes: 13