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

Commit c82db33

Browse files
author
Michal Vlasák
committed
Update changelog and readme
1 parent 79497d1 commit c82db33

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
### Added
1111
- coveralls integration
1212
- automatic logger name in non-pretty loggers
13+
- `options.skip` settings for custom log filtering in Express
1314

1415
## Changed
1516
- refactoring of express handlers

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ app.use(logger.expressError)
113113

114114
All those log messages will contain request and possibly response, error, time from request to response, status code and `user-agent`, `x-deviceid` and `authorization` request headers.
115115

116+
### Request skipping
117+
You might want to omit some requests from logging completely. Right now, there are two ways to do it.
118+
1) Use `options.ignoredHttpMethods` to define an array of HTTP methods you want to omit. By default all `OPTIONS` requests are ommited. See [options](#options) for details
119+
2) Use `options.skip` method to define custom rules for requests skipping. Set it to a function which accepts an Express's `Request` and returns `boolean`. If the return value is `true`, request (and corresponding response) will not be logged. You might want to use `matchPath` helper to ignore requests based on the [`req.path` value](https://expressjs.com/en/4x/api.html#req.path)
120+
121+
```js
122+
const { matchPath } = require('cosmas/utils');
123+
const logger = require('cosmas').default({
124+
skip: matchPath(/heal.h/),
125+
});
126+
```
127+
116128
## Environment-specific behavior
117129
`cosmas` is meant to be used throughout different environments (development, testing, production) and some of its configuration is setup differently based on the environment it runs in.
118130

@@ -132,6 +144,7 @@ Options override both default logger configuration and environment-specific conf
132144
- `streams` - list of stream objects, which will be passed directly to [pino-multistream's multistream function](https://github.com/pinojs/pino-multi-stream#pinomsmultistreamstreams) instead of default `cosmas` stream
133145
- `pretty` - if set to `true`, logger will use [pino pretty human-readable logs](https://github.com/pinojs/pino/blob/master/docs/API.md#pretty). This option can be overriden by `streams`
134146
- `disableStackdriverFormat` - if set to `false`, logger will add `severity` field to all log objects, so that log levels in Google Stackdriver work as expected. Defaults to `false`
147+
- `skip` - Function to be used in express middlewares for filtering request logs. If the function returns `true` for a given request, no message will be logged. No default value.
135148
- `config` - object, which will be passed to underlying logger object. Right now, underlying logger is [pino](https://github.com/pinojs/pino), so for available options see [pino API docs](https://github.com/pinojs/pino/blob/master/docs/API.md#pinooptions-stream)
136149

137150
## Default serializers

0 commit comments

Comments
 (0)