Skip to content

Commit

Permalink
docs: add "logger.debug" and "logger.only"
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Apr 12, 2023
1 parent b7832a1 commit 593c853
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ logger.success('parsed 120 documents!')

- Class: `Logger`
- [`new Logger(name)`](#new-loggername)
- [`logger.debug(message)`](#loggerdebugmessage)
- [`logger.info(message)`](#loggerinfomessage)
- [`logger.success(message)`](#loggersuccessmessage)
- [`logger.warning(message)`](#loggerwarningmessage)
- [`logger.error(message)`](#loggererrormessage)
- [`logger.extend(name)`](#loggerextendprefix)
- [`logger.only(callback)`](#loggeronlycallback)

### `new Logger(name)`

Expand All @@ -48,6 +50,20 @@ const logger = new Logger('parser')

> You can nest loggers via [`logger.extend()`](#loggerextendprefix).
### `logger.debug(message)`

- `message` `string`

Prints a debug message.

```js
logger.debug('no duplicates found, skipping...')
```

```
12:34:56:789 [parser] no duplicates found, skipping...
```

### `logger.info(message)`

- `message` `string`
Expand Down Expand Up @@ -122,3 +138,16 @@ function parseRequest(request) {
```
12:34:56:789 [parser] [GET https://example.com] start parsing...
```

### `logger.only(callback)`

Executes a given callback only when the logging is activated. Useful for computing additional information for logs.

```js
logger.only(() => {
const documentSize = getSizeBytes(document)
logger.debug(`document size: ${documentSize}`)
})
```

> You can nest `logger.*` methods in the callback to `logger.only()`.

0 comments on commit 593c853

Please sign in to comment.