-
Notifications
You must be signed in to change notification settings - Fork 61
/
index.test-d.ts
64 lines (57 loc) · 1.99 KB
/
index.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Request, Server, server, ServerApplicationState } from '@hapi/hapi';
import pino from 'pino';
import * as HapiPino from '.';
import { expectType } from 'tsd';
const pinoLogger = pino();
const hapiServer = server();
const options: HapiPino.Options = {
timestamp: () => `,"time":"${new Date(Date.now()).toISOString()}"`,
logQueryParams: false,
logPathParams: false,
logPayload: false,
logRouteTags: false,
logRequestStart: false,
logRequestComplete: true,
stream: process.stdout,
tags: {
trace: 'trace',
debug: 'debug',
info: 'info',
warn: 'warn',
error: 'error',
fatal: 'fatal',
},
allTags: 'info',
wrapSerializers: false,
serializers: {
req: (req: any) => console.log(req),
},
getChildBindings: (req: Request) => ({
'x-request-id': req.headers['x-request-id'],
}),
customRequestStartMessage: (req: Request) => `request start ${req.path}`,
customRequestCompleteMessage: (req: Request, responseTime: number) => `request complete ${req.path} in ${responseTime}ms`,
customRequestErrorMessage: (req: Request, error: Error) => `request failed ${req.path} with error ${error.message}`,
instance: pinoLogger,
logEvents: false,
mergeHapiLogData: false,
ignorePaths: ['/testRoute'],
level: 'debug',
redact: ['test.property'],
ignoreTags: ['healthcheck'],
ignoreFunc: (options, request) => request.path.startsWith('/static'),
ignoredEventTags: [{ log: ['DEBUG', 'TEST'], request: ['DEBUG', 'TEST'] }],
};
expectType<Promise<Server<ServerApplicationState> & void>>(hapiServer.register({ plugin: HapiPino, options }));
const emptyOptions: HapiPino.Options = {};
expectType<Promise<Server<ServerApplicationState> & void>>(hapiServer.register({ plugin: HapiPino, options: emptyOptions }));
hapiServer.logger.info('some message');
hapiServer.logger.error(new Error('some error'));
hapiServer.route({
method: 'GET',
path: '/path',
handler(request) {
request.logger.info('some message');
request.logger.error(new Error('some error'));
}
});