xcally-nest-library 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/src/modules/logger/pino/logger.module.d.ts +0 -2
- package/dist/src/modules/logger/pino/logger.module.js +50 -48
- package/dist/src/modules/logger/pino/logger.module.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/modules/logger/pino/logger.module.ts +66 -66
package/package.json
CHANGED
@@ -1,74 +1,74 @@
|
|
1
|
-
import {
|
1
|
+
import { Global, Module } from '@nestjs/common';
|
2
2
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
3
3
|
import { LoggerModule as LoggerModulePino } from 'nestjs-pino';
|
4
4
|
import { LoggerService } from './logger.service';
|
5
5
|
|
6
6
|
@Global()
|
7
|
-
@Module({
|
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
|
-
|
7
|
+
@Module({
|
8
|
+
providers: [LoggerService],
|
9
|
+
exports: [LoggerService],
|
10
|
+
imports: [
|
11
|
+
LoggerModulePino.forRootAsync({
|
12
|
+
imports: [ConfigModule],
|
13
|
+
inject: [ConfigService],
|
14
|
+
useFactory: async (config: ConfigService) => {
|
15
|
+
const projectName = process.env.npm_package_name || 'default_project';
|
16
|
+
return {
|
17
|
+
pinoHttp: {
|
18
|
+
customLogLevel: (req, res) => {
|
19
|
+
if (res.statusCode >= 500) return 'error';
|
20
|
+
if (res.statusCode >= 400) return 'warn';
|
21
|
+
return 'info';
|
22
|
+
},
|
23
|
+
level: config.get('LOG_LEVEL') || 'info',
|
24
|
+
// customErrorMessage?: ((req: IM, res: SR, error: Error) => string) | undefined;
|
25
|
+
// customErrorMessage: (req, res, error) => {
|
26
|
+
// return 'Auto generated error' + error?.message;
|
27
|
+
// },
|
28
|
+
// customSuccessMessage(req, res, responseTime) {
|
29
|
+
// return 'Auto generated success';
|
30
|
+
// },
|
31
|
+
// autoLogging: true,
|
32
|
+
// level: config.get('LOG_LEVEL') || 'info',
|
33
|
+
// stream: pino.destination(`./logs/info.log`),
|
34
|
+
redact: {
|
35
|
+
paths: ['req.headers.cookie', 'req.headers.authorization'],
|
36
|
+
},
|
37
|
+
transport: {
|
38
|
+
targets: [
|
39
|
+
{
|
40
|
+
level: 'debug',
|
41
|
+
target: 'pino-pretty',
|
42
|
+
options: {
|
43
|
+
colorize: true,
|
44
|
+
},
|
35
45
|
},
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
colorize: true,
|
43
|
-
},
|
44
|
-
},
|
45
|
-
// {
|
46
|
-
// level: 'error',
|
47
|
-
// target: 'pino/file',
|
48
|
-
// options: {
|
49
|
-
// destination: './logs/error.log',
|
50
|
-
// },
|
51
|
-
// },
|
52
|
-
{
|
53
|
-
level: 'info',
|
54
|
-
target: 'pino/file',
|
55
|
-
options: {
|
56
|
-
destination: `./logs/${projectName}-info.log`,
|
57
|
-
mkdir: true,
|
58
|
-
append: process.env.NODE_ENV !== 'production' ? false : true,
|
59
|
-
},
|
60
|
-
},
|
61
|
-
],
|
62
|
-
},
|
63
|
-
// genReqId: () => { // Non't needed with pino instrumentation
|
64
|
-
// const activeSpan = api.trace.getSpan(api.context.active());
|
65
|
-
// return activeSpan.spanContext().traceId;
|
46
|
+
// {
|
47
|
+
// level: 'error',
|
48
|
+
// target: 'pino/file',
|
49
|
+
// options: {
|
50
|
+
// destination: './logs/error.log',
|
51
|
+
// },
|
66
52
|
// },
|
67
|
-
|
68
|
-
|
53
|
+
{
|
54
|
+
level: 'info',
|
55
|
+
target: 'pino/file',
|
56
|
+
options: {
|
57
|
+
destination: `./logs/${projectName}-info.log`,
|
58
|
+
mkdir: true,
|
59
|
+
append: process.env.NODE_ENV !== 'production' ? false : true,
|
60
|
+
},
|
61
|
+
},
|
62
|
+
],
|
63
|
+
},
|
64
|
+
// genReqId: () => { // Non't needed with pino instrumentation
|
65
|
+
// const activeSpan = api.trace.getSpan(api.context.active());
|
66
|
+
// return activeSpan.spanContext().traceId;
|
67
|
+
// },
|
69
68
|
},
|
70
|
-
}
|
71
|
-
|
72
|
-
}
|
73
|
-
|
74
|
-
}
|
69
|
+
};
|
70
|
+
},
|
71
|
+
}),
|
72
|
+
],
|
73
|
+
})
|
74
|
+
export class LoggerModule {}
|