Skip to content

Commit

Permalink
Document standalone usage
Browse files Browse the repository at this point in the history
  • Loading branch information
pablosichert committed Oct 30, 2016
1 parent 6c9185b commit 1239f2f
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 @@ -21,7 +21,9 @@ $ npm install concurrency-logger
```

## Usage

### With [koa](https://github.com/koajs/koa)

#### Basic usage
```js
import Koa from 'koa';
Expand All @@ -35,6 +37,7 @@ const logger = createLogger(/* options */);

app.use(logger);
```

#### Log from middleware
```js
// Log something in context to a specific request to trace it back easily -
Expand Down Expand Up @@ -109,6 +112,32 @@ const logger = createLogger({
});
```

### Standalone
```js
import createLogger from 'concurrency-logger';

const logger = createLogger(/* options */);

(async () => {
const context = {
method: 'GET',
originalUrl: '/'
};

const next = async () => {
await new Promise(resolve => setTimeout(resolve, 100));

context.status = 200;
};

try {
await logger(context, next);
} catch (error) {
// Errors are passed through
}
});
```

## API
| Option | Type | Default | Description | Example |
| ---- | ---- | ------- | ----------- | ------- |
Expand Down

0 comments on commit 1239f2f

Please sign in to comment.