@marblejs/middleware-logger
HTTP request logger middleware for Marble.js
Simple middleware for request logging inside your console. It displays the outgoing request events using the following format:
1
{HTTP_METHOD} {PATH} {HTTP_STATUS} {TIME}
Copied!
1
POST /api/v1/user 200 1ms
Copied!

Installation

1
$ yarn add @marblejs/middleware-logger
Copied!
Requires @marblejs/core to be installed.

Importing

1
import { logger$ } from '@marblejs/middleware-logger';
Copied!

Type declaration

1
logger$ :: LoggerOptions -> HttpMiddlewareEffect
Copied!

Parameters

parameter
definition
options
<optional> LoggerOptions

LoggerOptions

parameter
definition
silent
<optional> boolean
filter
<optional> HttpRequest -> boolean

Usage

    1.
    Default behavior. Log every response to process.stdout:
1
import { httpListener } from '@marblejs/core';
2
import { logger$ } from '@marblejs/middleware-logger';
3
4
const middlewares = [
5
logger$(),
6
...
7
];
8
9
export const listener = httpListener({
10
middlewares,
11
effects: [],
12
});
Copied!
2. Customized logging behavior:
1
import { httpListener } from '@marblejs/core';
2
import { logger$ } from '@marblejs/middleware-logger';
3
import { isTestEnv } from './util';
4
5
const middlewares = [
6
logger$({
7
silent: isTestEnv(),
8
filter: req => req.res.status >= 400;
9
}),
10
...
11
];
12
13
export const listener = httpListener({
14
middlewares,
15
effects: [],
16
});
Copied!
    silent - When true the logging is turned off (usually useful during testing),
    filter - Filter outgoing responses or incoming requests based on given predicate. For example we can log only HTTP status codes above 400.
Last modified 1yr ago