单独的信息和错误日志bunyan

正如我在博客中看到许多日志,我发现bunyan适合于日志logging,但它有问题,它不能根据他们的级别login文件。

下面是我正在关注的代码结构

const RotatingFileStream = require('bunyan-rotating-file-stream'); const bunyan = require('bunyan'); var log = bunyan.createLogger({ name: 'ShotPitch', streams: [{ name: 'info', level: 'info', stream: new RotatingFileStream({ path: 'info.%d-%b-%y.log', period: '1d', // daily rotation totalFiles: 10, // keep 10 back copies rotateExisting: true, // Give ourselves a clean file when we start up, based on period threshold: '10m', // Rotate log files larger than 10 megabytes totalSize: '20m', // Don't keep more than 20mb of archived log files gzip: true // Compress the archive log files to save space }) }, { name: 'error', level: 'error', stream: new RotatingFileStream({ path: 'error.%d-%b-%y.log', period: '1d', // daily rotation totalFiles: 10, // keep 10 back copies rotateExisting: true, // Give ourselves a clean file when we start up, based on period threshold: '10m', // Rotate log files larger than 10 megabytes totalSize: '20m', // Don't keep more than 20mb of archived log files gzip: true // Compress the archive log files to save space }) }] }); log.info('Hello World'); log.error('Hello World error log'); 

o / p:info.log:

{“name”:“ShotPitch”,“pid”:7621,“level”:30,“msg”:“Hello World”,“time”:“2017-09-03T18:29:04.181Z”,“ :0}

{“name”:“ShotPitch”,“pid”:7621,“level”:50,“msg”:“Hello World”,“time”:“2017-09-03T18:29:04.181Z”,“ :0}

o / p:error.log:

{“name”:“ShotPitch”,“pid”:7621,“level”:50,“msg”:“Hello World”,“time”:“2017-09-03T18:29:04.181Z”,“ :0}

结论:

info.log显示信息和错误日志

error.log只显示错误日志

我只想info.log中的信息日志,但无法做到。 有没有人可以帮忙? 另外,如果告诉我如何更改级别:“信息”,而不是级别:30

configurationbunyan时需要指定一个旋转文件stream的日志级别。

默认情况下,日志输出是标准输出和“信息”级别。

将logging器实例(或其中一个stream)设置为特定级别意味着logging了该级别及以上的所有日志logging。 例如,设置为“信息”级别的logging器将logging等级信息及以上的logging(警告,错误,致命)。

错误日志也被收集到信息日志中。