Skip to content

Commit

Permalink
[doc] Add example regarding "arguments to custom token formats"
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Oct 7, 2016
1 parent 4a93c83 commit 907011a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,25 @@ function assignId (req, res, next) {
}
```

### arguments to custom token formats

Example of a custom token format that uses an argument. It will output the
property from `process` related to the argument passed to the token. If that property
is a function then it will return the value returned from that function.

```js
var express = require('express')
var morgan = require('morgan')

morgan.token('process', function getId (req, res, arg) {
if (typeof process[arg] === 'function') {
return String(process[arg]());
} else if (process[arg]) {
return String(process[arg]);
}
};
```
### output JSON logs
``` js
Expand Down

0 comments on commit 907011a

Please sign in to comment.