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 9b80917
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,24 @@ 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 9b80917

Please sign in to comment.