项目作者: khezen

项目描述 :
extend bunyan logger integrating useful streams
高级语言: JavaScript
项目地址: git://github.com/khezen/bunyancat.git
创建时间: 2017-03-18T15:02:43Z
项目社区:https://github.com/khezen/bunyancat

开源协议:MIT License

下载


NPM Version

get started

Instanciate a logger

  • We are using default values in the example below:
  1. const bunyan = require("bunyancat");
  2. let log = bunyan.createLogger({
  3. name: "helloworld",
  4. stdout:{
  5. level: "debug",
  6. },
  7. rotatingFile: {
  8. path: "/var/logs/helloworld",
  9. period: "1d",
  10. count: 7,
  11. level: "info"
  12. },
  13. logstash: {
  14. host: "localhost",
  15. port: 5000,
  16. level: "info",
  17. tags: null
  18. },
  19. rollbar: {
  20. token: "rollback access token",
  21. rollbarOptions: {} // Options to pass to rollbar.init()
  22. },
  23. kafka: {
  24. host: "localhost",
  25. port: 2181,
  26. level: "info",
  27. topic: "log-helloworld-topic"
  28. },
  29. slack: {
  30. webhook: "slack webhook url",
  31. channel: "slack channel",
  32. username: "bunyancat",
  33. level: "error"
  34. }
  35. });
  36. log.info('hi');
  37. log.warn({lang: 'fr'}, 'au revoir');
  • Bunyan will have stdout stream only in the example below:
  1. const bunyan = require("bunyancat");
  2. let log = bunyan.createLogger({
  3. name: "helloworld"
  4. });
  5. log.info('hi');
  6. log.warn({lang: 'fr'}, 'au revoir');

Inheritence

Bunyan has a concept of a child logger to specialize a logger for a sub-component of your application, i.e. to create a new logger with additional bound fields that will be included in its log records. A child logger is created with log.child(...).

  1. const bunyan = require("bunyancat");
  2. let log = bunyan.createLogger({
  3. name: "helloworld"
  4. });
  5. function Wuzzle(options) {
  6. this.log = options.log.child({widget_type: 'wuzzle'});
  7. this.log.info('creating a wuzzle')
  8. }
  9. Wuzzle.prototype.woos = function () {
  10. this.log.warn('This wuzzle is woosey.')
  11. }
  12. log.info('start');
  13. var wuzzle = new Wuzzle({log: log});
  14. wuzzle.woos();
  15. log.info('done');