Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
}
}
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));
},