Skip to content

Commit

Permalink
feat(all): replace bunyan library with js-logger library
Browse files Browse the repository at this point in the history
replace bunyan library with js-logger library
  • Loading branch information
GiladShoham committed Oct 11, 2017
1 parent 2c5cc34 commit eafc037
Show file tree
Hide file tree
Showing 7 changed files with 576 additions and 286 deletions.
567 changes: 421 additions & 146 deletions dist/search-index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/search-index.min.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion docs/API.md
Expand Up @@ -46,6 +46,7 @@
* [searchable](#searchable)
* [indexPath](#indexpath)
* [logLevel](#loglevel)
* [logHandler](#logHandler)
* [nGramLength](#ngramlength)
* [separator](#separator)
* [stopwords](#stopwords)
Expand Down Expand Up @@ -598,7 +599,12 @@ The location of the datastore. If `db` is specified, then indexPath is ignored
### logLevel
_string_

A [bunyan](https://github.com/trentm/node-bunyan) log level.
A [js-logger](https://github.com/jonnyreeves/js-logger) log level (can be lower or upper case - 'error' or 'ERROR').

### logHandler
_function_

A [js-logger](https://github.com/jonnyreeves/js-logger) log handler function.

### nGramLength
_number_ or _array_ or _object_
Expand Down
2 changes: 1 addition & 1 deletion docs/demo/search-index.min.js

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions lib/index.js
@@ -1,4 +1,4 @@
const bunyan = require('bunyan')
const Logger = require('js-logger')
const level = require('levelup')
const down = require('leveldown')
const SearchIndexAdder = require('search-index-adder')
Expand Down Expand Up @@ -64,12 +64,16 @@ const getOptions = function (options, done) {
SearchIndex.options = Object.assign({}, {
indexPath: 'si',
keySeparator: '○',
logLevel: 'error'
logLevel: 'ERROR',
logHandler: Logger.createDefaultHandler()
}, options)
options.log = bunyan.createLogger({
name: 'search-index',
level: options.logLevel
})
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',
Expand Down

0 comments on commit eafc037

Please sign in to comment.