Skip to content

Commit

Permalink
feat: setReporters, withDefaults and withTag
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 18, 2018
1 parent d7e1805 commit 912446f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,24 @@ Remove a registered reporter.

If no arguments are passed all reporters will be removed.

#### `setReporters(reporter|reporter[])`

- Type: `Object` or `Array`

Replace all reporters.

#### `create(options)`

Create a new `Consola` instance and inherit all parent options for defaults.

#### `withDefaults(defaults)`

Create a new `Consola` instance with provided defaults. (Shortcut to `create({ defaults })`)

#### `withTag(tag)`

Create a new `Consola` instance with that tag. (Shortcut to `withDefaults({ tag })`)

## Fields

#### `reporters`
Expand Down Expand Up @@ -233,7 +247,7 @@ const logger = consola.create({
### With jest

```js
consola.removeReporter().addReporter({
consola.setReporters({
log: jest.fn()
})
```
Expand Down
24 changes: 16 additions & 8 deletions src/consola.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ export default class Consola {
return this
}

setReporters (reporters) {
this._reporters = Array.isArray(reporters)
? reporters
: [reporters]
}

withDefaults (defaults) {
return this.create({ defaults })
}

withTag (tag) {
return this.withDefaults({ tag })
}

_createLogFn (defaults) {
function fnLog () {
if (defaults.level > this._level) {
Expand Down Expand Up @@ -170,16 +184,10 @@ export default class Consola {
})
}

// DEPRECATED
withDefaults (defaults) {
this._deprecated('consola.withDefaults()', 'consola.create({ defaults })')
return this.create({ defaults })
}

// DEPRECATED
withScope (scope) {
this._deprecated('consola.withScope', 'consola.create({ defaults: { tag: scope } })')
return this.create({ defaults: { tag: scope } })
this._deprecated('consola.withScope', 'consola.withTag')
return this.withTag(scope)
}

// DEPRECATED
Expand Down

0 comments on commit 912446f

Please sign in to comment.