Sail.js - How to create a clean log file?

I am currently using Sails v0.10.0-rc7 and Sails v0.10.0-rc7 trying to forward console logs to a file. Some older threads have described a way to do this by adding the following lines to config/log.js :

 module.exports = { log: { level: 'info', filePath: 'someFile.log' } }; 

But that doesn't work anymore. Sails uses the captains-log subproject that was previously encapsulated by winston. According to README.md, I changed 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, this works, but message messages always have a color prefix in the message body. 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 information tags in green) and the messages in the log file 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 suppresses prefixes, but I still have color coding in the log messages.

So, does anyone have any ideas on how to get rid of prefixes and color encodings in log messages?

+6
source share
1 answer

I was able to complete my task 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 }) ] }) } }; 
+13
source

Source: https://habr.com/ru/post/971653/


All Articles