How to use bunyan

Comprehensive bunyan code examples:

How to use bunyan.prototype:

74
75
76
77
78
79
80
81
82
83
// log arguments.
this._emit = function (record, noemit) {
  // No need to call CategoryLogger's _emit here because we already know
  // that we want to log (we have already checked our category against
  // the config) and we will attach category to the record.
  return Logger.prototype._emit.call(
    this,
    {
      ...record,
      category,

How to use bunyan.default:

88
89
90
91
92
93
94
95
96
97
}
else {
    // Never log anything when testing online
    // streams.push({ stream: process.stdout, level: 'error' });
}
return (loggerInstance = bunyan_1.default.createLogger({
    // The JSON payload of the log as it appears in Cloud Logging
    // will contain "name": "s2sWebApi"
    name: 's2sWebApi',
    streams

How to use bunyan.info:

216
217
218
219
220
221
222
223
224
225

  // // submit to blockchain
  let tx = {};
  tx = client.submitAndWait(signed.tx_blob)

  log.info({ hash: signed.hash }, "hash of the executed transaction");
  return signed.hash;
} catch (e) {
  throw new Error('Something went wrong when sigining the transaction')
}

How to use bunyan.error:

166
167
168
169
170
171
172
173
174
175
  // // submit to blockchain
  let tx = {};
  try {
    tx = await client.submitAndWait(signed.tx_blob)
  } catch (err) {
    log.error(err, "failed to send tokens");
  }
  return tx;
}
/**

How to use bunyan.fields:

4
5
6
7
8
9
10
11
12
13
14
15
const { createHash } = require("crypto");
const { default: BigNumber } = require('bignumber.js');
const { transactionMockHandler } = require('../mock/transaction')


const log = require('bunyan').createLogger({ name: 'ripple_methods' })
delete log.fields.hostname;


const estimate_fee_query = {
  "id": "EstimateFee",
  "command": "fee"

How to use bunyan.child:

628
629
630
631
632
633
634
635
636
637
638
639
640
});


// External Bunyan logger
const logger = require("bunyan").createLogger({ name: "moleculer", level: "info" });
const broker = new ServiceBroker({
    logger: bindings => logger.child(bindings)
});




/* *******************************************************************************************

How to use bunyan.stdSerializers:

24
25
26
27
28
29
30
31
32
33
34
35
    streams: [{


        path: "./logs/error.log",
        level: "error",
    }],
    serializers: bunyan.stdSerializers
});


require("mongoose-pagination");

How to use bunyan.createLogger:

102
103
104
105
106
107
108
109
110
111
112
113
  Object.keys(error).forEach((key) => (result[key] = error[key]));


  return result;
}


const log = bunyan.createLogger({
  name: 'snyk-broker',
  serializers: {
    token: sanitise,
    result: sanitise,