How to use the bunyan.RingBuffer 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 koajs / bunyan-logger / test / index.js View on Github external
beforeEach(async () => {
    app = new Koa();
    app.on('error', () => {}); // suppress errors

    ringBuffer = new bunyan.RingBuffer({limit: 100});
    ringLogger = bunyan.createLogger({
      name: 'test',
      streams: [{
        type: 'raw',
        stream: ringBuffer,
        level: 'trace'
      }]
    });
  });
github joola / joola / lib / common / logger.js View on Github external
*  Licensed under MIT License.
 *  See LICENSE, AUTHORS.
 *
 *  @license MIT 
 **/

'use strict';

var
  joola = require('../joola'),
  fs = require('fs'),
  bunyan = require('bunyan'),
  Bunyan2Loggly = require('bunyan-loggly').Bunyan2Loggly,
  bformat = require('bunyan-format'),
  formatOut = bformat({ outputMode: 'short' }),
  ringbuffer = new bunyan.RingBuffer({ limit: 10000 });

//our basic logger with stderr and ringBuffer
var logger = bunyan.createLogger({
  name: 'joola',
  serializers: bunyan.stdSerializers,
  streams: [
    {
      stream: process.stderr,
      level: "error"
    },
    {
      level: 'trace',
      type: 'raw',    // use 'raw' to get raw log record objects
      stream: ringbuffer
    }
  ]
github restify / node-restify / lib / bunyan_helper.js View on Github external
RequestCaptureStream.prototype.write = function write(record) {
    var req_id = record.req_id || DEFAULT_REQ_ID;
    var ring;
    var self = this;

    if (!(ring = this.requestMap.get(req_id))) {
        if (++this._offset > this.maxRequestIds) {
            this._offset = 0;
        }

        if (this._rings.length <= this._offset) {
            this._rings.push(
                new bunyan.RingBuffer({
                    limit: self.limit
                })
            );
        }

        ring = this._rings[this._offset];
        ring.records.length = 0;
        this.requestMap.set(req_id, ring);
    }

    assert.ok(ring, 'no ring found');

    // write the record to the ring.
    ring.write(record);
    // triger dumping of all the records
    if (record.level >= this.level) {
github science / openthermo / server / node_modules / restify / lib / bunyan_helper.js View on Github external
RequestCaptureStream.prototype.write = function write(record) {
        var req_id = record.req_id || DEFAULT_REQ_ID;
        var ring;
        var self = this;

        if (!(ring = this.requestMap.get(req_id))) {
                if (++this._offset > this.maxRequestIds)
                        this._offset = 0;

                if (this._rings.length <= this._offset) {
                        this._rings.push(new bunyan.RingBuffer({
                                limit: self.limit
                        }));
                }

                ring = this._rings[this._offset];
                ring.records.length = 0;
                this.requestMap.set(req_id, ring);
        }

        assert.ok(ring, 'no ring found');

        if (record.level >= this.level) {
                ring.records.forEach(function (r) {
                        var ser = JSON.stringify(r, bunyan.safeCycles()) + '\n';
                        self.streams.forEach(function (s) {
                                s.stream.write(s.raw ? r : ser);
github joyent / manatee-state-machine / lib / sim.js View on Github external
function Simulator(args)
{
	var self = this;

	mod_assertplus.object(args, 'args');
	mod_assertplus.string(args.progName, 'args.progName');
	mod_assertplus.string(args.logLevel, 'args.logLevel');
	mod_assertplus.object(args.input, 'args.input');
	mod_assertplus.object(args.output, 'args.output');
	mod_assertplus.object(args.error, 'args.error');

	mod_events.EventEmitter.call(this);

	this.ms_logbuffer = new mod_bunyan.RingBuffer({ 'limit': 100000 });
	this.ms_log = new mod_bunyan({
	    'name': args.progName,
	    'level': args.logLevel,
	    'streams': [ {
		'type': 'raw',
		'stream': this.ms_logbuffer
	    } ]
	});

	this.ms_arg0 = args.progName;
	this.ms_input = args.input;
	this.ms_output = args.output;
	this.ms_error = args.error;

	this.ms_zk = createSimZkState({
	    'log': this.ms_log.child({ 'component': 'zk' })
github particles / particles / lib / logger.js View on Github external
} else if(stream.stream === 'process.stderr') {
      streamOptions = streamOptions || {prettyPrint: true};
      if(streamOptions.prettyPrint) {
        var prettyStderrStream = new bunyanPrettystream(streamOptions);
        prettyStderrStream.pipe(process.stderr);
        stream.stream = prettyStderrStream;
        stream.type = 'raw';
      } else {
        stream.stream = process.stderr;
      }

     
    } else if(stream.stream === 'ringBuffer') {
      streamOptions = streamOptions || {limit: 100};
      stream.stream = new bunyan.RingBuffer(streamOptions);
      stream.type = 'raw';
    } else {
      //just load the specified file
      stream.stream = require(stream.stream);
    }
    //clean unneeded options
    delete stream.streamOptions;
  });
github Automattic / dserve / src / logger.ts View on Github external
import * as bunyan from 'bunyan';
import * as _ from 'lodash';
import { Writable } from 'stream';

import { CommitHash, getImageName } from './api';
import { getLogPath } from './builder';
import { config } from './config';

export const ringbuffer = new bunyan.RingBuffer( { limit: 1000 } );

const dserveLogger = bunyan.createLogger( {
	name: 'dserve',
	streams: [
		{
			type: 'rotating-file',
			path: './logs/log.txt',
			period: '1d',
			count: 7,
		},
		{
			level: bunyan.DEBUG,
			type: 'raw',
			stream: ringbuffer,
		},
		{
github restify / clients / lib / helpers / bunyan.js View on Github external
RequestCaptureStream.prototype.write = function write(record) {
    var reqId = record.reqId || DEFAULT_REQ_ID;
    var ring;
    var self = this;

    if (!(ring = this.requestMap.get(reqId))) {
        if (++this._offset > this.maxRequestIds) {
            this._offset = 0;
        }

        if (this._rings.length <= this._offset) {
            this._rings.push(new bunyan.RingBuffer({
                limit: self.limit
            }));
        }

        ring = this._rings[this._offset];
        ring.records.length = 0;
        this.requestMap.set(reqId, ring);
    }

    assert.ok(ring, 'no ring found');

    if (record.level >= this.level) {
        var i, r, ser;

        for (i = 0; i < ring.records.length; i++) {
            r = ring.records[i];