xcally-nest-library 0.0.15 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -71
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/src/modules/logger/pino/logger.default.d.ts +1 -0
- package/dist/src/modules/logger/pino/logger.default.js +6 -0
- package/dist/src/modules/logger/pino/logger.default.js.map +1 -0
- package/dist/src/modules/logger/pino/logger.module.d.ts +2 -0
- package/dist/src/modules/logger/pino/logger.module.js +51 -21
- package/dist/src/modules/logger/pino/logger.module.js.map +1 -1
- package/dist/src/modules/logger/pino/logger.service.d.ts +6 -11
- package/dist/src/modules/logger/pino/logger.service.js +15 -27
- package/dist/src/modules/logger/pino/logger.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.ts +1 -0
- package/package.json +2 -1
- package/src/modules/logger/pino/logger.default.ts +1 -0
- package/src/modules/logger/pino/logger.module.ts +72 -21
- package/src/modules/logger/pino/logger.service.ts +17 -32
package/index.ts
CHANGED
@@ -9,3 +9,4 @@ export * from './src/decorators/utils.decorators';
|
|
9
9
|
export * from './src/config/env.validation';
|
10
10
|
export * from './src/modules/logger/pino/logger.service';
|
11
11
|
export * from './src/modules/logger/pino/logger.module';
|
12
|
+
export * from './src/modules/logger/pino/logger.default';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "xcally-nest-library",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.17",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -44,6 +44,7 @@
|
|
44
44
|
"nestjs-paginate": "^8.6.2",
|
45
45
|
"nestjs-pino": "^4.1.0",
|
46
46
|
"pino": "^9.4.0",
|
47
|
+
"pino-pretty": "^11.2.2",
|
47
48
|
"reflect-metadata": "^0.2.2",
|
48
49
|
"rxjs": "^7.8.1",
|
49
50
|
"typeorm": "^0.3.20",
|
@@ -0,0 +1 @@
|
|
1
|
+
export { Logger } from 'nestjs-pino';
|
@@ -1,23 +1,74 @@
|
|
1
|
-
import { Module } from '@nestjs/common';
|
2
|
-
import {
|
1
|
+
import { DynamicModule, Global, Module } from '@nestjs/common';
|
2
|
+
import { ConfigModule, ConfigService } from '@nestjs/config';
|
3
3
|
import { LoggerModule as LoggerModulePino } from 'nestjs-pino';
|
4
|
-
import
|
4
|
+
import { LoggerService } from './logger.service';
|
5
5
|
|
6
|
-
@
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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'],
|
35
|
+
},
|
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;
|
66
|
+
// },
|
67
|
+
},
|
68
|
+
};
|
69
|
+
},
|
70
|
+
}),
|
71
|
+
],
|
72
|
+
};
|
73
|
+
}
|
74
|
+
}
|
@@ -1,43 +1,36 @@
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
2
2
|
import { PinoLogger } from 'nestjs-pino';
|
3
|
-
import pino from 'pino';
|
4
3
|
import api from '@opentelemetry/api';
|
5
4
|
|
6
|
-
type PinoMethods = Pick<pino.Logger, 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'>;
|
7
|
-
|
8
5
|
@Injectable()
|
9
|
-
export class LoggerService
|
6
|
+
export class LoggerService {
|
10
7
|
constructor(private readonly logger: PinoLogger) {}
|
11
|
-
|
12
|
-
|
13
|
-
activeSpan.addEvent(msg, ...args);
|
14
|
-
this.logger.trace(msg, ...args);
|
15
|
-
}
|
16
|
-
debug(msg: string, ...args: any[]): void {
|
8
|
+
|
9
|
+
debug(msg: string, meta?: any): void {
|
17
10
|
const activeSpan = api.trace.getSpan(api.context.active());
|
18
|
-
activeSpan.addEvent(msg
|
19
|
-
this.logger.debug(
|
11
|
+
activeSpan.addEvent(msg);
|
12
|
+
this.logger.debug({ meta }, msg);
|
20
13
|
}
|
21
|
-
warn(msg: string,
|
14
|
+
warn(msg: string, meta?: any): void {
|
22
15
|
const activeSpan = api.trace.getSpan(api.context.active());
|
23
|
-
activeSpan.addEvent(msg
|
24
|
-
this.logger.warn(
|
16
|
+
activeSpan.addEvent(msg);
|
17
|
+
this.logger.warn({ meta }, msg);
|
25
18
|
}
|
26
|
-
error(msg: string,
|
19
|
+
error(msg: string, meta?: any): void {
|
27
20
|
const activeSpan = api.trace.getSpan(api.context.active());
|
28
|
-
activeSpan.addEvent(msg
|
29
|
-
this.logger.error(
|
21
|
+
activeSpan.addEvent(msg);
|
22
|
+
this.logger.error({ meta }, msg);
|
30
23
|
}
|
31
|
-
fatal(msg: string,
|
24
|
+
fatal(msg: string, meta?: any): void {
|
32
25
|
const activeSpan = api.trace.getSpan(api.context.active());
|
33
|
-
activeSpan.addEvent(msg
|
34
|
-
this.logger.fatal(
|
26
|
+
activeSpan.addEvent(msg);
|
27
|
+
this.logger.fatal({ meta }, msg);
|
35
28
|
}
|
36
29
|
|
37
|
-
info(msg: string,
|
30
|
+
info(msg: string, meta?: any): void {
|
38
31
|
// LOG EVENTS
|
39
32
|
const activeSpan = api.trace.getSpan(api.context.active());
|
40
|
-
activeSpan.addEvent(msg
|
33
|
+
activeSpan.addEvent(msg);
|
41
34
|
|
42
35
|
// // LOG CORRELATION -- You can see correlation between spans and logs
|
43
36
|
// const tracer = api.trace.getTracer(process.env.npm_package_name, process.env.npm_package_version);
|
@@ -46,14 +39,6 @@ export class LoggerService implements PinoMethods {
|
|
46
39
|
// span.end();
|
47
40
|
// });
|
48
41
|
|
49
|
-
this.logger.info(
|
50
|
-
}
|
51
|
-
|
52
|
-
log(msg: string, ...args: any[]): void {
|
53
|
-
const activeSpan = api.trace.getSpan(api.context.active());
|
54
|
-
if (activeSpan) {
|
55
|
-
activeSpan.addEvent(msg, ...args);
|
56
|
-
}
|
57
|
-
this.logger.info(msg, ...args);
|
42
|
+
this.logger.info({ meta }, msg);
|
58
43
|
}
|
59
44
|
}
|