Skip to content
This repository was archived by the owner on Aug 17, 2023. It is now read-only.

Commit

Permalink
improve defaultConsume and document.
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Jul 13, 2017
1 parent 635df31 commit 243b9c6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const logging = require('toa-logging')
const app = new Toa()
app.use(logging())
app.use(function () {
this.body = 'Hello!'
// logging middleware will add a Log instance to context.state
this.body = this.state.log
})

app.listen(3000)
Expand All @@ -31,7 +32,7 @@ const logging = require('toa-logging')

### logging([options])

Create a new logging middleware function with `options`.
Create a new logging middleware function with `options`. logging middleware will add a Log instance to `context.state`, you can append key/value to the log like `this.state.log.someKey = someValue`.

#### options.skipper

Expand All @@ -48,18 +49,21 @@ logging({

#### options.init

Set a init function that will run at the begin, default to:
Set a init function that will run at the begin. This function
will be called as `init.call(context, context.state.log)`. Default to:

```js
function defaultInit (log) {} // do nothing~
```

#### options.consume

Set a consume function that will run at the end, default to:
Set a consume function that will run at the end. This function
will be called as `consume.call(context, context.state.log)`. Default to:

```js
function defaultConsume (log) {
log.status = this.status
ilog.info(log) // write the log by ilog.info
}
```
Expand Down
3 changes: 2 additions & 1 deletion examples/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const logging = require('../index')
const app = new Toa()
app.use(logging())
app.use(function () {
this.body = 'Hello!'
// logging middleware will add a Log instance to context.state
this.body = this.state.log
})

app.listen(3000)
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function noOp () { return false }
function defaultInit (log) {} // do nothing~

function defaultConsume (log) {
log.status = this.status
ilog.info(log) // write the log by ilog.info
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"authors": [
"Yan Qing <[email protected]>"
],
"version": "1.0.0",
"version": "1.0.1",
"main": "index.js",
"repository": {
"type": "git",
Expand Down

0 comments on commit 243b9c6

Please sign in to comment.