Skip to content

Commit

Permalink
docs: injecting custom logger
Browse files Browse the repository at this point in the history
  • Loading branch information
bacebu4 committed Feb 16, 2024
1 parent 0395b32 commit d3f27f7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ closeWithGrace({ delay: 500 }, async function ({ signal, err, manual }) {
})
```

### Injecting custom logger

```js
const closeWithGrace = require('close-with-grace')

// delay is the number of milliseconds for the graceful close to
// finish.
closeWithGrace(
{
delay: 500,
logger: { error: (m) => console.error(`[close-with-grace] ${m}`) }
},
async function ({ signal, err, manual }) {
if (err) {
console.error(err)
}
await closeYourServer()
})
```

## API

### `closeWithGrace([opts], fn({ err, signal, manual }))`
Expand All @@ -42,6 +62,8 @@ If it is emitted again, it will terminate the process abruptly.
* `delay`: the numbers of milliseconds before abruptly close the
process. Default: `10000`.

* `logger`: instance of logger which will be used internally. Default: `10000`.

#### fn({ err, signal, manual } [, cb])

Execute the given function to perform a graceful close.
Expand Down

0 comments on commit d3f27f7

Please sign in to comment.