Passed
Push — main ( 238ec8...50243d )
by Lorenzo
03:03
created

src/logging/Logger.ts   A

Complexity

Total Complexity 5
Complexity/F 5

Size

Lines of Code 43
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 33
mnd 4
bc 4
fnc 1
dl 0
loc 43
ccs 14
cts 14
cp 1
rs 10
bpm 4
cpm 5
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B Logger.ts ➔ createLogger 0 40 5
1 11
import pino from 'pino';
2
3 11
export function createLogger(scope?: string) {
4 7
  let options: pino.LoggerOptions = {};
5 7
  if (process.env.NODE_ENV === 'production') {
6 1
    options.redact = {
7
      paths: [
8
        'req.headers.authorization',
9
        'req.headers.cookie',
10
        'req.headers["x-api-key"]',
11
        'req.headers["x-access-token"]',
12
        'res.headers.set-cookie',
13
      ],
14
      censor: '****',
15
    };
16
  } else {
17 6
    options.transport = {
18
      target: 'pino-pretty',
19
      options: {
20
        colorize: true,
21
      },
22
    };
23
  }
24
25 7
  const logger = pino(
26
    {
27
      msgPrefix: `[${scope ?? 'ExpressBeans'}] `,
28
      ...options,
29
    },
30
  );
31 7
  switch (process.env.NODE_ENV) {
32
  case 'production':
33 1
    logger.level = 'info';
34 1
    break;
35
  case 'test':
36 5
    logger.level = 'silent';
37 5
    break;
38
  default:
39 1
    logger.level = 'debug';
40
  }
41 7
  return logger;
42
}
43