How to use the bunyan.prototype function in bunyan

To help you get started, we’ve selected a few bunyan examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ericelliott / bunyan-request-logger / test / index.js View on Github external
before(function () {
    infoSpy = sinon.spy(bunyan.prototype, 'info');
    errorSpy = sinon.spy(bunyan.prototype, 'error');

    // hide console errors while running the tests
    sinon.stub(console, 'error');
  });
github ericelliott / bunyan-request-logger / test / index.js View on Github external
before(function () {
    infoSpy = sinon.spy(bunyan.prototype, 'info');
    errorSpy = sinon.spy(bunyan.prototype, 'error');

    // hide console errors while running the tests
    sinon.stub(console, 'error');
  });
github probot / probot / lib / logger.js View on Github external
* robot.log.warn("Woah there");
 * robot.log.error("ETOOMANYLOGS");
 * robot.log.fatal("Goodbye, cruel world!");
 */

const Logger = require('bunyan')
const bunyanFormat = require('bunyan-format')
const serializers = require('./serializers')

// Return a function that defaults to "info" level, and has properties for
// other levels:
//
//     robot.log("info")
//     robot.log.trace("verbose details");
//
Logger.prototype.wrap = function () {
  const fn = this.info.bind(this);

  // Add level methods on the logger
  ['trace', 'debug', 'info', 'warn', 'error', 'fatal'].forEach(level => {
    fn[level] = this[level].bind(this)
  })

  // Expose `child` method for creating new wrapped loggers
  fn.child = (attrs) => {
    // Bunyan doesn't allow you to overwrite name…
    const name = attrs.name
    delete attrs.name
    const log = this.child(attrs, true)

    // …Sorry, bunyan, doing it anwyway
    if (name) log.fields.name = name
github pact-foundation / pact-node / src / logger.ts View on Github external
// eslint-disable-next-line @typescript-eslint/no-var-requires
const bunyan = require('bunyan');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const PrettyStream = require('bunyan-prettystream');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../package.json');

const prettyStdOut = new PrettyStream();
prettyStdOut.pipe(process.stdout);

// TODO: replace bunyan with something that actually works with typescript
// Extend bunyan
bunyan.prototype.time = (action: string, startTime: number): void => {
  let time = Date.now() - startTime;
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
  // @ts-ignore
  this.info(
    {
      duration: time,
      action: action,
      type: 'TIMER',
    },
    `TIMER: ${action} completed in ${time} milliseconds`,
  );
};

export type LogLevels = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';

const Logger = new bunyan({
github wework / we-js-logger / test / specs / logger.spec.js View on Github external
it('calls child on the logger bunyan instance', () => {
        sinon.spy(bunyan.prototype, 'child');
        log.child();

        expect(bunyan.prototype.child).to.have.been.calledOnce;
      });
github wework / we-js-logger / test / specs / logger.spec.js View on Github external
it('instantiates a new logger with the new child', () => {
        const stubChild = {};
        sinon.stub(bunyan.prototype, 'child').returns(stubChild);
        const child = log.child();

        expect(child).not.to.eql(log);
        expect(child._logger).to.eql(stubChild);
      });
github ericelliott / bunyan-request-logger / test / log.route.js View on Github external
before(function () {
    infoSpy = sinon.spy(bunyan.prototype, 'info');
  });