constructor(options) { options = options || {}; this._name = options.name; if (options.$parent) { this._logger = options.$parent.child(options.childOptions); } else { this._logger = bunyan.createLogger({ name: this._name, level: options.level || bunyan.INFO, streams: options.streams }); } this._throttledLogs = new Map(); this._onceLogs = new Set(); const logMethods = new Set(['trace', 'debug', 'info', 'warn', 'error', 'fatal']); this._createLogMethods(logMethods); this._createThrottleLogMethods(logMethods); this._createOnceLogMethods(logMethods); }
write(rec) { let msg; if (typeof rec === 'string' || rec instanceof String) { console.log(rec); return; } else if (typeof rec === 'object') { const formattedMsg = this._formatter(rec); if (typeof formattedMsg === 'string' || formattedMsg instanceof String) { msg = formattedMsg; } else { console.error('Unable to format message %j', rec); return; } const logLevel = rec.level; if (logLevel <= bunyan.INFO) { console.info(msg); } else if (logLevel <= bunyan.WARN) { console.warn(msg); } else { // logLevel === bunyan.ERROR || bunyan.FATAL console.error(msg); } } }