xcally-nest-library 0.0.18 → 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.18",
3
+ "version": "0.0.20",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -39,13 +39,11 @@
39
39
  "class-transformer": "^0.5.1",
40
40
  "class-validator": "^0.14.1",
41
41
  "datadog-winston": "^1.6.0",
42
- "dotenv": "^16.4.5",
43
42
  "nest-winston": "^1.9.4",
44
43
  "nestjs-grpc-exceptions": "^0.2.2",
45
44
  "nestjs-paginate": "^8.6.2",
46
45
  "nestjs-pino": "^4.1.0",
47
46
  "pino": "^9.4.0",
48
- "pino-opentelemetry-transport": "^1.0.1",
49
47
  "pino-pretty": "^11.2.2",
50
48
  "reflect-metadata": "^0.2.2",
51
49
  "rxjs": "^7.8.1",
@@ -1,111 +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
- import 'dotenv/config';
6
- import type { Options } from 'pino-opentelemetry-transport';
7
- const options: Options = {
8
- resourceAttributes: {
9
- 'service.name': process.env.npm_package_name || 'unknown',
10
- // 'service.version': process.env.npm_package_version || '1.0.0',
11
- },
12
- logRecordProcessorOptions: [
13
- {
14
- recordProcessorType: 'batch',
15
- exporterOptions: {
16
- protocol: 'http',
17
- httpExporterOptions: {
18
- url: new URL('v1/logs', process.env.OTLP_HTTP_URL || 'http://localhost:4318/').toString(),
19
- },
20
- },
21
- },
22
- // {
23
- // recordProcessorType: 'batch',
24
- // exporterOptions: {
25
- // protocol: 'grpc',
26
- // grpcExporterOptions: {
27
- // headers: { foo: 'some custom header' },
28
- // },
29
- // },
30
- // },
31
- // {
32
- // recordProcessorType: 'simple',
33
- // exporterOptions: { protocol: 'console' },
34
- // },
35
- ],
36
- loggerName: (process.env.npm_package_name || 'unknown') + '-logger',
37
- serviceVersion: process.env.npm_package_version || 'unknown',
38
- };
5
+
39
6
  @Global()
40
- @Module({})
41
- export class LoggerModule {
42
- static forRoot(): DynamicModule {
43
- return {
44
- module: LoggerModule,
45
- providers: [LoggerService],
46
- exports: [LoggerService],
47
- imports: [
48
- LoggerModulePino.forRootAsync({
49
- imports: [ConfigModule],
50
- inject: [ConfigService],
51
- useFactory: async (config: ConfigService) => {
52
- const projectName = process.env.npm_package_name || 'default_project';
53
- return {
54
- pinoHttp: {
55
- level: config.get('LOG_LEVEL') || 'info',
56
- // customErrorMessage?: ((req: IM, res: SR, error: Error) => string) | undefined;
57
- // customErrorMessage: (req, res, error) => {
58
- // return 'Auto generated error' + error?.message;
59
- // },
60
- // customSuccessMessage(req, res, responseTime) {
61
- // return 'Auto generated success';
62
- // },
63
- // autoLogging: true,
64
- // level: config.get('LOG_LEVEL') || 'info',
65
- // stream: pino.destination(`./logs/info.log`),
66
- redact: {
67
- 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
+ },
68
45
  },
69
- transport: {
70
- targets: [
71
- {
72
- target: 'pino-opentelemetry-transport',
73
- options,
74
- },
75
- {
76
- level: 'debug',
77
- target: 'pino-pretty',
78
- options: {
79
- colorize: true,
80
- },
81
- },
82
- // {
83
- // level: 'error',
84
- // target: 'pino/file',
85
- // options: {
86
- // destination: './logs/error.log',
87
- // },
88
- // },
89
- {
90
- level: 'info',
91
- target: 'pino/file',
92
- options: {
93
- destination: `./logs/${projectName}-info.log`,
94
- mkdir: true,
95
- append: process.env.NODE_ENV !== 'production' ? false : true,
96
- },
97
- },
98
- ],
99
- },
100
- // genReqId: () => { // Non't needed with pino instrumentation
101
- // const activeSpan = api.trace.getSpan(api.context.active());
102
- // return activeSpan.spanContext().traceId;
46
+ // {
47
+ // level: 'error',
48
+ // target: 'pino/file',
49
+ // options: {
50
+ // destination: './logs/error.log',
51
+ // },
103
52
  // },
104
- },
105
- };
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
+ // },
106
68
  },
107
- }),
108
- ],
109
- };
110
- }
111
- }
69
+ };
70
+ },
71
+ }),
72
+ ],
73
+ })
74
+ export class LoggerModule {}