xcally-nest-library 0.0.19 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xcally-nest-library",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,74 +1,74 @@
1
- import { DynamicModule, Global, Module } from '@nestjs/common';
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
- export class LoggerModule {
9
- static forRoot(): DynamicModule {
10
- return {
11
- module: LoggerModule,
12
- providers: [LoggerService],
13
- exports: [LoggerService],
14
- imports: [
15
- LoggerModulePino.forRootAsync({
16
- imports: [ConfigModule],
17
- inject: [ConfigService],
18
- useFactory: async (config: ConfigService) => {
19
- const projectName = process.env.npm_package_name || 'default_project';
20
- return {
21
- pinoHttp: {
22
- level: config.get('LOG_LEVEL') || 'info',
23
- // customErrorMessage?: ((req: IM, res: SR, error: Error) => string) | undefined;
24
- // customErrorMessage: (req, res, error) => {
25
- // return 'Auto generated error' + error?.message;
26
- // },
27
- // customSuccessMessage(req, res, responseTime) {
28
- // return 'Auto generated success';
29
- // },
30
- // autoLogging: true,
31
- // level: config.get('LOG_LEVEL') || 'info',
32
- // stream: pino.destination(`./logs/info.log`),
33
- redact: {
34
- paths: ['req.headers.cookie', 'req.headers.authorization'],
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
- transport: {
37
- targets: [
38
- {
39
- level: 'debug',
40
- target: 'pino-pretty',
41
- options: {
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 {}