How to use the js-logger.setHandler function in js-logger

To help you get started, we’ve selected a few js-logger 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 fergiemcdowall / search-index / lib / index.js View on Github external
const getOptions = function (options, done) {
  var SearchIndex = {}
  SearchIndex.options = Object.assign({}, {
    indexPath: 'si',
    keySeparator: '○',
    logLevel: 'ERROR',
    logHandler: Logger.createDefaultHandler()
  }, options)
  SearchIndex.options.log = Logger.get('search-index')
  // We pass the log level as string because the Logger[logLevel] returns
  // an object, and Object.assign deosn't make deep assign so it breakes
  // We used toUpperCase() for backward compatibility
  SearchIndex.options.log.setLevel(Logger[SearchIndex.options.logLevel.toUpperCase()])
  // Use the global one because the library doesn't support providing handler to named logger
  Logger.setHandler(SearchIndex.options.logHandler)
  if (!options.indexes) {
    level(SearchIndex.options.indexPath || 'si', {
      valueEncoding: 'json',
      db: down
    }, function (err, db) {
      SearchIndex.options.indexes = db
      return done(err, SearchIndex)
    })
  } else {
    return done(null, SearchIndex)
  }
}
github simplygreatwork / godsend / src / Logging.js View on Github external
initializeHandlers: function() {
		
		this.handlers = {
			'default': Logger.createDefaultHandler(),
			'push': this.push.bind(this)
		};
		Logger.setHandler(function(messages, context) {
			this.handlers['default'](messages, context);
			this.handlers['push'](messages, context);
		}.bind(this));
	},