项目作者: 39Er

项目描述 :
bunyan rotate file stream
高级语言: JavaScript
项目地址: git://github.com/39Er/bunyan-rotate-file-stream.git
创建时间: 2017-06-07T07:46:38Z
项目社区:https://github.com/39Er/bunyan-rotate-file-stream

开源协议:MIT License

下载


bunyan-rotate-file-stream

A stream for bunyan to output log to file,every day create a new file

Installation

  1. npm install bunyan-rotate-file-stream

Example:

  1. let logger = bunyan.createLogger({
  2. name: 'bunyan-rotate',
  3. serializers: bunyan.stdSerializers,
  4. src: false,
  5. streams: [
  6. {
  7. level: 'error',
  8. type: 'raw',
  9. stream: new RotateFileStream('./logs/error.log')),
  10. }
  11. ],
  12. });
  13. logger.error('test bunyan logger');

In your directory,it will make a file named ‘error.log’. On the secode day,it will rename the file like ‘error.log.20170607’,and make a new file named ‘error.log’ to store new logs of the secode day.

You can also add other streams ,like:

  1. let logger = bunyan.createLogger({
  2. name: 'bunyan-rotate',
  3. serializers: bunyan.stdSerializers,
  4. src: false,
  5. streams: [
  6. {
  7. level: 'error',
  8. type: 'raw',
  9. stream: new RotateFileStream(path.join('./logs/error.log')),
  10. }, {
  11. level: 'info',
  12. stream: process.stdout,
  13. },
  14. ],
  15. });
  16. logger.info('test bunyan info');
  17. logger.error('test bunyan logger');

Output:

  1. [2017-06-07T08:21:10.965Z] INFO: bunyan-rotate/13896 on CNBJHQTEC111: test bunyan info
  2. [2017-06-07T08:21:10.967Z] ERROR: bunyan-rotate/13896 on CNBJHQTEC111: test bunyan error

File ‘/logs/error.log’:

  1. {"name":"bunyan-rotate","hostname":"CNBJHQTEC111","pid":13896,"level":50,"msg":"test bunyan error","time":"2017-06-07T08:21:10.967Z","v":0}