And*_*ano 5 logging winston sails.js
我正在使用 Winston 登录 Sails 应用程序。这是我的配置:
var customLogger = new winston.Logger({
transports: [
new(winston.transports.File)({
level: 'debug',
filename: 'app.log',
colorize: false,
showLevel: false,
prettyPrint: false,
exitOnError: false,
json: true,
zippedArchive: true,
maxsize: 1000000000,
maxFiles: 30,
tailable: true
}),
new(winston.transports.Console)({
level: 'info',
exitOnError: false,
colorize: false,
showLevel: false
})
],
});
Run Code Online (Sandbox Code Playgroud)
但在输出文件中存在奇怪的字符。
{"level":"info","message":"\u001b[32minfo: \u001b[39m","timestamp":"2016-05-12T17:58:03.281Z"}
Run Code Online (Sandbox Code Playgroud)
Bon*_*nza -1
目前在航行中你不需要使用customLogger温斯顿。您可以安装sails-hook-winston。比你的config/log.js会看起来像这样:
var path = require('path');
var pkgJSON = require(path.resolve('package.json'));
module.exports.log = {
// This options are for Console transport that is used by default
level: 'info', // you are familiar with this value, right?
timestamp: true, // if you want to output the timestamp in the console transport
colors: false,
// Transports
// more information: https://github.com/winstonjs/winston/blob/master/docs/transports.md
transports: [{
module: require('winston-daily-rotate-file'),
config: {
dirname: path.resolve('logs'),
datePattern: '.yyyy-MM-dd.log',
filename: pkgJSON.name,
prettyPrint: true,
timestamp: true,
level: 'info',
json: true,
colors: false
}
}]
};
Run Code Online (Sandbox Code Playgroud)
您可以同时使用几种具有不同日志级别的传输。
| 归档时间: |
|
| 查看次数: |
4039 次 |
| 最近记录: |