@edirect/logger 11.0.62 → 11.0.63
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/dist/README.md +260 -0
- package/dist/package.json +26 -0
- package/dist/src/context/async-context.d.ts +16 -0
- package/dist/src/context/async-context.d.ts.map +1 -0
- package/dist/src/context/async-context.js +18 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/logger/interfaces/logger-module-options.interface.d.ts +14 -0
- package/dist/src/logger/interfaces/logger-module-options.interface.d.ts.map +1 -0
- package/dist/src/logger/interfaces/logger-module-options.interface.js +2 -0
- package/dist/src/logger/log.d.ts +29 -0
- package/dist/src/logger/log.d.ts.map +1 -0
- package/dist/src/logger/log.js +127 -0
- package/dist/src/logger/logger.class.d.ts +17 -0
- package/dist/src/logger/logger.class.d.ts.map +1 -0
- package/dist/src/logger/logger.class.js +32 -0
- package/dist/src/logger/logger.module.d.ts +7 -0
- package/dist/src/logger/logger.module.d.ts.map +1 -0
- package/dist/src/logger/logger.module.definition.d.ts +3 -0
- package/dist/src/logger/logger.module.definition.d.ts.map +1 -0
- package/dist/src/logger/logger.module.definition.js +6 -0
- package/dist/src/logger/logger.module.js +30 -0
- package/dist/src/logger/logger.service.d.ts +18 -0
- package/dist/src/logger/logger.service.d.ts.map +1 -0
- package/dist/src/logger/logger.service.js +47 -0
- package/dist/src/middleware/logger-context.middleware.d.ts +7 -0
- package/dist/src/middleware/logger-context.middleware.d.ts.map +1 -0
- package/dist/src/middleware/logger-context.middleware.js +29 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +20 -3
package/dist/README.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# @edirect/logger
|
|
2
|
+
|
|
3
|
+
Structured logging module for eDirect NestJS applications. Built on top of [Pino](https://github.com/pinojs/pino), providing high-performance JSON logging with AsyncLocalStorage support for automatic context propagation, file output, and seamless integration with NestJS.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ **Pino-based** - High-performance structured JSON logging
|
|
8
|
+
- ✅ **AsyncLocalStorage** - Automatic context propagation (sessionId, quoteId, correlationId, traceId, userId)
|
|
9
|
+
- ✅ **SINGLETON Architecture** - Better performance
|
|
10
|
+
- ✅ **Multi-level logging** - log, info, warn, error, debug, verbose
|
|
11
|
+
- ✅ **Enhanced error logging** - Multiple overloads with trace support
|
|
12
|
+
- ✅ **File and console output** - Flexible output configuration (stdout/stderr or files)
|
|
13
|
+
- ✅ **Datadog compatible** - ISO 8601 timestamps and structured logs
|
|
14
|
+
- ✅ **NestJS integration** - Native support with middleware
|
|
15
|
+
- ✅ **Global module** - Register once, inject LoggerService anywhere
|
|
16
|
+
- ✅ **Async configuration** - Supports both sync (register) and async (registerAsync) setup
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pnpm add @edirect/logger
|
|
22
|
+
# or
|
|
23
|
+
npm install @edirect/logger
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### Basic Usage (Without Middleware)
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { Module } from '@nestjs/common';
|
|
32
|
+
import { LoggerModule } from '@edirect/logger';
|
|
33
|
+
|
|
34
|
+
@Module({
|
|
35
|
+
imports: [LoggerModule],
|
|
36
|
+
})
|
|
37
|
+
export class AppModule {}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { Injectable } from '@nestjs/common';
|
|
42
|
+
import { LoggerService } from '@edirect/logger';
|
|
43
|
+
|
|
44
|
+
@Injectable()
|
|
45
|
+
export class MyService {
|
|
46
|
+
constructor(private logger: LoggerService) {}
|
|
47
|
+
|
|
48
|
+
doSomething() {
|
|
49
|
+
this.logger.info('Operation started', { userId: '123' });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### With Middleware (Automatic Context from HTTP Headers)
|
|
55
|
+
|
|
56
|
+
If you want automatic context extraction from HTTP headers, add the middleware:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { Module, MiddlewareConsumer, NestModule } from '@nestjs/common';
|
|
60
|
+
import { LoggerModule, LoggerContextMiddleware } from '@edirect/logger';
|
|
61
|
+
|
|
62
|
+
@Module({
|
|
63
|
+
imports: [LoggerModule],
|
|
64
|
+
})
|
|
65
|
+
export class AppModule implements NestModule {
|
|
66
|
+
configure(consumer: MiddlewareConsumer) {
|
|
67
|
+
consumer
|
|
68
|
+
.apply(LoggerContextMiddleware)
|
|
69
|
+
.forRoutes('*'); // Apply to all routes
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Manual Context Setting
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { Injectable } from '@nestjs/common';
|
|
78
|
+
import { LoggerService } from '@edirect/logger';
|
|
79
|
+
|
|
80
|
+
@Injectable()
|
|
81
|
+
export class MyService {
|
|
82
|
+
constructor(private logger: LoggerService) {}
|
|
83
|
+
|
|
84
|
+
doSomething() {
|
|
85
|
+
this.logger.info('Operation started', { userId: '123' });
|
|
86
|
+
// sessionId and quoteId automatically included from request context!
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Configuration
|
|
92
|
+
|
|
93
|
+
### Basic Configuration
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { Module } from '@nestjs/common';
|
|
97
|
+
import { LoggerModule } from '@edirect/logger';
|
|
98
|
+
|
|
99
|
+
@Module({
|
|
100
|
+
imports: [
|
|
101
|
+
LoggerModule.register({
|
|
102
|
+
output: 'console', // 'console' | 'file' | 'both'
|
|
103
|
+
level: 'info',
|
|
104
|
+
logs: {
|
|
105
|
+
infoFile: './logs/info.log',
|
|
106
|
+
warningFile: './logs/warning.log',
|
|
107
|
+
errorFile: './logs/error.log',
|
|
108
|
+
exceptionsFile: './logs/exceptions.log',
|
|
109
|
+
},
|
|
110
|
+
name: 'my-service',
|
|
111
|
+
version: '1.0.0',
|
|
112
|
+
}),
|
|
113
|
+
],
|
|
114
|
+
})
|
|
115
|
+
export class AppModule {}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Async Configuration
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { ConfigService } from '@edirect/config';
|
|
122
|
+
import { LoggerModule } from '@edirect/logger';
|
|
123
|
+
|
|
124
|
+
@Module({
|
|
125
|
+
imports: [
|
|
126
|
+
ConfigModule,
|
|
127
|
+
LoggerModule.registerAsync({
|
|
128
|
+
imports: [ConfigModule],
|
|
129
|
+
useFactory: async (configService: ConfigService) => ({
|
|
130
|
+
output: configService.get('LOGS_OUTPUT'),
|
|
131
|
+
level: configService.get('LOGS_LEVEL'),
|
|
132
|
+
logs: {
|
|
133
|
+
infoFile: configService.get('LOGS_INFO_FILE'),
|
|
134
|
+
warningFile: configService.get('LOGS_WARNING_FILE'),
|
|
135
|
+
errorFile: configService.get('LOGS_ERROR_FILE'),
|
|
136
|
+
exceptionsFile: configService.get('LOGS_EXCEPTIONS_FILE'),
|
|
137
|
+
},
|
|
138
|
+
name: configService.get('APP_NAME'),
|
|
139
|
+
version: configService.get('APP_VERSION'),
|
|
140
|
+
}),
|
|
141
|
+
inject: [ConfigService],
|
|
142
|
+
}),
|
|
143
|
+
],
|
|
144
|
+
})
|
|
145
|
+
export class AppModule {}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## API Reference
|
|
149
|
+
|
|
150
|
+
### Logging Methods
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
// Info logging
|
|
154
|
+
logger.log(message: string, payload?: any);
|
|
155
|
+
logger.info(message: string, payload?: any);
|
|
156
|
+
|
|
157
|
+
// Warning logging
|
|
158
|
+
logger.warn(message: string, payload?: any);
|
|
159
|
+
|
|
160
|
+
// Debug logging
|
|
161
|
+
logger.debug(message: string, payload?: any);
|
|
162
|
+
logger.verbose(message: string, payload?: any);
|
|
163
|
+
|
|
164
|
+
// Error logging (multiple overloads)
|
|
165
|
+
logger.error(message: string); // Just message
|
|
166
|
+
logger.error(message: string, payload: any); // Message + payload to enrich
|
|
167
|
+
logger.error(message: string, trace: string); // Message + stack trace
|
|
168
|
+
logger.error(message: string, error: Error); // Message + Error object
|
|
169
|
+
logger.error(message: string, payload: any, trace: string); // Full context
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Context Management
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
// Set context manually (useful for background jobs)
|
|
176
|
+
logger.setContext('sessionId', 'session-123');
|
|
177
|
+
logger.setContext('quoteId', 'quote-456');
|
|
178
|
+
logger.setContext('correlationId', 'corr-789');
|
|
179
|
+
logger.setContext('traceId', 'trace-abc');
|
|
180
|
+
logger.setContext('userId', 'user-xyz');
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### AsyncLocalStorage for Background Jobs
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { AsyncContextManager } from '@edirect/logger';
|
|
187
|
+
|
|
188
|
+
@Cron('0 0 * * *')
|
|
189
|
+
handleCron() {
|
|
190
|
+
AsyncContextManager.run({ sessionId: 'cron-job', quoteId: 'batch-001' }, () => {
|
|
191
|
+
this.logger.info('Cron job started');
|
|
192
|
+
// Context automatically propagates through all async calls
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Context Headers
|
|
198
|
+
|
|
199
|
+
The `LoggerContextMiddleware` automatically extracts context from these HTTP headers:
|
|
200
|
+
|
|
201
|
+
- `x-session-id` → `sessionId`
|
|
202
|
+
- `x-quote-id` → `quoteId`
|
|
203
|
+
- `x-trace-id` → `traceId`
|
|
204
|
+
- `x-correlation-id` → `correlationId`
|
|
205
|
+
- `req.user.id` → `userId`
|
|
206
|
+
|
|
207
|
+
## Log Format
|
|
208
|
+
|
|
209
|
+
All logs are structured JSON with the following fields:
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"timestamp": "2024-03-06T14:30:00.123Z",
|
|
214
|
+
"level": "info",
|
|
215
|
+
"message": "Operation completed",
|
|
216
|
+
"name": "my-service",
|
|
217
|
+
"version": "1.0.0",
|
|
218
|
+
"host": "localhost",
|
|
219
|
+
"protocol": "http",
|
|
220
|
+
"sessionId": "session-123",
|
|
221
|
+
"quoteId": "quote-456",
|
|
222
|
+
"correlationId": "corr-789",
|
|
223
|
+
"traceId": "trace-abc",
|
|
224
|
+
"userId": "user-xyz",
|
|
225
|
+
"remote-address": "192.168.1.1",
|
|
226
|
+
"details": { "custom": "data" },
|
|
227
|
+
"trace": "Error stack trace" // Only in error logs
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Error Logging Examples
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
// Simple error
|
|
235
|
+
logger.error('Something went wrong');
|
|
236
|
+
|
|
237
|
+
// Error with enrichment details
|
|
238
|
+
logger.error('User not found', { userId: '123', action: 'login' });
|
|
239
|
+
|
|
240
|
+
// Error with stack trace
|
|
241
|
+
logger.error('Database error', 'Error: Connection timeout\n at db.connect...');
|
|
242
|
+
|
|
243
|
+
// Error with Error object (auto-extracts stack)
|
|
244
|
+
try {
|
|
245
|
+
throw new Error('Failed to process');
|
|
246
|
+
} catch (error) {
|
|
247
|
+
logger.error('Processing failed', error);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Full context error
|
|
251
|
+
logger.error(
|
|
252
|
+
'Complex error',
|
|
253
|
+
{ context: 'payment', orderId: '456' },
|
|
254
|
+
'Error stack trace here'
|
|
255
|
+
);
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
260
|
+
MIT
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edirect/logger",
|
|
3
|
+
"version": "11.0.63",
|
|
4
|
+
"main": "./dist/src/index.js",
|
|
5
|
+
"types": "./dist/src/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/src/index.js",
|
|
9
|
+
"default": "./dist/src/index.js",
|
|
10
|
+
"require": "./dist/src/index.js",
|
|
11
|
+
"types": "./dist/src/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@edirect/config": "^11.0.63",
|
|
20
|
+
"@nestjs/common": "^11.2.1",
|
|
21
|
+
"pino": "10.3.1",
|
|
22
|
+
"supertest": "7.2.2",
|
|
23
|
+
"tslib": "^2.8.1"
|
|
24
|
+
},
|
|
25
|
+
"type": "commonjs"
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
export interface LoggerContext {
|
|
3
|
+
sessionId?: string;
|
|
4
|
+
quoteId?: string;
|
|
5
|
+
userId?: string;
|
|
6
|
+
traceId?: string;
|
|
7
|
+
correlationId?: string;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
export declare const loggerAsyncStorage: AsyncLocalStorage<LoggerContext>;
|
|
11
|
+
export declare class AsyncContextManager {
|
|
12
|
+
static getContext(): LoggerContext | undefined;
|
|
13
|
+
static setContext(context: LoggerContext): void;
|
|
14
|
+
static run<T>(context: LoggerContext, callback: () => T): T;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=async-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context.d.ts","sourceRoot":"","sources":["../../../src/context/async-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,eAAO,MAAM,kBAAkB,kCAAyC,CAAC;AAEzE,qBAAa,mBAAmB;IAC9B,MAAM,CAAC,UAAU,IAAI,aAAa,GAAG,SAAS;IAI9C,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;IAK/C,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC;CAG5D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsyncContextManager = exports.loggerAsyncStorage = void 0;
|
|
4
|
+
const async_hooks_1 = require("async_hooks");
|
|
5
|
+
exports.loggerAsyncStorage = new async_hooks_1.AsyncLocalStorage();
|
|
6
|
+
class AsyncContextManager {
|
|
7
|
+
static getContext() {
|
|
8
|
+
return exports.loggerAsyncStorage.getStore();
|
|
9
|
+
}
|
|
10
|
+
static setContext(context) {
|
|
11
|
+
const current = exports.loggerAsyncStorage.getStore() || {};
|
|
12
|
+
exports.loggerAsyncStorage.enterWith({ ...current, ...context });
|
|
13
|
+
}
|
|
14
|
+
static run(context, callback) {
|
|
15
|
+
return exports.loggerAsyncStorage.run(context, callback);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.AsyncContextManager = AsyncContextManager;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './context/async-context';
|
|
2
|
+
export * from './logger/interfaces/logger-module-options.interface';
|
|
3
|
+
export * from './logger/logger.class';
|
|
4
|
+
export * from './logger/logger.module';
|
|
5
|
+
export * from './logger/logger.service';
|
|
6
|
+
export * from './middleware/logger-context.middleware';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,qDAAqD,CAAC;AACpE,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wCAAwC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./context/async-context"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./logger/interfaces/logger-module-options.interface"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./logger/logger.class"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./logger/logger.module"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./logger/logger.service"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./middleware/logger-context.middleware"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Level, LoggerOptions } from 'pino';
|
|
2
|
+
export interface LoggerModuleOptions {
|
|
3
|
+
output?: 'console';
|
|
4
|
+
name?: string;
|
|
5
|
+
host?: string;
|
|
6
|
+
protocol?: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
level?: Level;
|
|
9
|
+
payloadFieldName?: 'details' | 'payload';
|
|
10
|
+
mixin?: () => Record<string, unknown>;
|
|
11
|
+
baseExtension?: Record<string, unknown>;
|
|
12
|
+
pinoOptions?: Omit<LoggerOptions, 'level' | 'timestamp' | 'messageKey' | 'errorKey' | 'formatters' | 'base' | 'mixin'>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=logger-module-options.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-module-options.interface.d.ts","sourceRoot":"","sources":["../../../../src/logger/interfaces/logger-module-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAE5C,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,gBAAgB,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IACzC,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,WAAW,CAAC,EAAE,IAAI,CAChB,aAAa,EACb,OAAO,GAAG,WAAW,GAAG,YAAY,GAAG,UAAU,GAAG,YAAY,GAAG,MAAM,GAAG,OAAO,CACpF,CAAC;CACH"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LoggerContext } from '../context/async-context';
|
|
2
|
+
import { LoggerModuleOptions } from './interfaces/logger-module-options.interface';
|
|
3
|
+
export interface LogMetadata {
|
|
4
|
+
'remote-address'?: string;
|
|
5
|
+
sessionId?: string;
|
|
6
|
+
quoteId?: string;
|
|
7
|
+
correlationId?: string;
|
|
8
|
+
traceId?: string;
|
|
9
|
+
userId?: string;
|
|
10
|
+
details?: any;
|
|
11
|
+
payload?: any;
|
|
12
|
+
trace?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class Logger {
|
|
15
|
+
private configs;
|
|
16
|
+
private logger;
|
|
17
|
+
constructor(env: Record<string, string>, options?: LoggerModuleOptions);
|
|
18
|
+
debug(message: string, payload?: any, remoteAddress?: string): void;
|
|
19
|
+
info(message: string, payload?: any, remoteAddress?: string): void;
|
|
20
|
+
warning(message: string, payload?: any, remoteAddress?: string): void;
|
|
21
|
+
warn(message: string, payload?: any, remoteAddress?: string): void;
|
|
22
|
+
error(message: string, trace?: string, remoteAddress?: string): void;
|
|
23
|
+
error(message: string, error: Error, remoteAddress?: string): void;
|
|
24
|
+
error(message: string, payload: any, trace?: string, remoteAddress?: string): void;
|
|
25
|
+
verbose(message: string, payload?: any, remoteAddress?: string): void;
|
|
26
|
+
setContext(key: keyof LoggerContext, value: string): void;
|
|
27
|
+
private buildLog;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../../src/logger/log.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AAEnF,MAAM,WAAW,WAAW;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,MAAM;IACjB,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,MAAM,CAAe;gBAEjB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,mBAAmB;IAkCtE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAInE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAIlE,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAIrE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAIlE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IACpE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAClE,KAAK,CACH,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,GAAG,EACZ,KAAK,CAAC,EAAE,MAAM,EACd,aAAa,CAAC,EAAE,MAAM,GACrB,IAAI;IA+CP,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAIrE,UAAU,CAAC,GAAG,EAAE,MAAM,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIzD,OAAO,CAAC,QAAQ;CAmCjB"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pino_1 = tslib_1.__importDefault(require("pino"));
|
|
6
|
+
const async_context_1 = require("../context/async-context");
|
|
7
|
+
class Logger {
|
|
8
|
+
configs;
|
|
9
|
+
logger;
|
|
10
|
+
constructor(env, options) {
|
|
11
|
+
const defaults = {
|
|
12
|
+
level: env.LOGS_LEVEL?.toLowerCase() || 'info',
|
|
13
|
+
name: env.npm_package_name ?? env.APP_NAME ?? 'app',
|
|
14
|
+
version: env.npm_package_version ?? env.APP_VERSION ?? '0.0.0',
|
|
15
|
+
host: env.LOGS_HOST ?? '0.0.0.0',
|
|
16
|
+
protocol: env.LOGS_PROTOCOL ?? 'http',
|
|
17
|
+
payloadFieldName: env.LOGS_PAYLOAD_FIELD_NAME ??
|
|
18
|
+
'payload',
|
|
19
|
+
};
|
|
20
|
+
this.configs = { ...defaults, ...options };
|
|
21
|
+
this.logger = (0, pino_1.default)({
|
|
22
|
+
...(this.configs.pinoOptions ?? {}),
|
|
23
|
+
level: this.configs.level,
|
|
24
|
+
timestamp: () => `,"timestamp":"${new Date().toISOString()}"`,
|
|
25
|
+
messageKey: 'message',
|
|
26
|
+
errorKey: 'error',
|
|
27
|
+
base: {
|
|
28
|
+
name: this.configs.name,
|
|
29
|
+
version: this.configs.version,
|
|
30
|
+
host: this.configs.host,
|
|
31
|
+
protocol: this.configs.protocol,
|
|
32
|
+
...this.configs.baseExtension,
|
|
33
|
+
},
|
|
34
|
+
formatters: {
|
|
35
|
+
level: label => ({ level: label }),
|
|
36
|
+
},
|
|
37
|
+
...(this.configs.mixin ? { mixin: this.configs.mixin } : {}),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
debug(message, payload, remoteAddress) {
|
|
41
|
+
this.logger.debug(this.buildLog(payload, remoteAddress), message);
|
|
42
|
+
}
|
|
43
|
+
info(message, payload, remoteAddress) {
|
|
44
|
+
this.logger.info(this.buildLog(payload, remoteAddress), message);
|
|
45
|
+
}
|
|
46
|
+
warning(message, payload, remoteAddress) {
|
|
47
|
+
this.logger.warn(this.buildLog(payload, remoteAddress), message);
|
|
48
|
+
}
|
|
49
|
+
warn(message, payload, remoteAddress) {
|
|
50
|
+
this.warning(message, payload, remoteAddress);
|
|
51
|
+
}
|
|
52
|
+
error(message, traceOrErrorOrPayload, traceOrRemoteAddress, remoteAddress) {
|
|
53
|
+
let finalTrace;
|
|
54
|
+
let finalPayload;
|
|
55
|
+
let finalRemoteAddress = '';
|
|
56
|
+
let finalMessage = message;
|
|
57
|
+
if (typeof message !== 'string') {
|
|
58
|
+
finalPayload = message;
|
|
59
|
+
finalMessage = message?.message || 'Error';
|
|
60
|
+
}
|
|
61
|
+
if (traceOrErrorOrPayload instanceof Error) {
|
|
62
|
+
finalTrace = traceOrErrorOrPayload.stack || traceOrErrorOrPayload.message;
|
|
63
|
+
finalRemoteAddress = traceOrRemoteAddress || '';
|
|
64
|
+
}
|
|
65
|
+
else if (typeof traceOrErrorOrPayload === 'string') {
|
|
66
|
+
finalTrace = traceOrErrorOrPayload;
|
|
67
|
+
finalRemoteAddress = traceOrRemoteAddress || '';
|
|
68
|
+
}
|
|
69
|
+
else if (traceOrErrorOrPayload !== undefined &&
|
|
70
|
+
typeof traceOrRemoteAddress === 'string' &&
|
|
71
|
+
remoteAddress !== undefined) {
|
|
72
|
+
finalPayload = finalPayload || traceOrErrorOrPayload;
|
|
73
|
+
finalTrace = traceOrRemoteAddress;
|
|
74
|
+
finalRemoteAddress = remoteAddress;
|
|
75
|
+
}
|
|
76
|
+
else if (traceOrErrorOrPayload !== undefined &&
|
|
77
|
+
typeof traceOrRemoteAddress === 'string') {
|
|
78
|
+
finalPayload = finalPayload || traceOrErrorOrPayload;
|
|
79
|
+
finalTrace = traceOrRemoteAddress;
|
|
80
|
+
}
|
|
81
|
+
else if (traceOrErrorOrPayload !== undefined) {
|
|
82
|
+
finalPayload = finalPayload || traceOrErrorOrPayload;
|
|
83
|
+
}
|
|
84
|
+
this.logger.error(this.buildLog(finalPayload, finalRemoteAddress, finalTrace), finalMessage);
|
|
85
|
+
}
|
|
86
|
+
verbose(message, payload, remoteAddress) {
|
|
87
|
+
this.info(message, payload, remoteAddress);
|
|
88
|
+
}
|
|
89
|
+
setContext(key, value) {
|
|
90
|
+
async_context_1.AsyncContextManager.setContext({ [key]: value });
|
|
91
|
+
}
|
|
92
|
+
buildLog(payload, remoteAddress = '', trace) {
|
|
93
|
+
const context = async_context_1.AsyncContextManager.getContext();
|
|
94
|
+
const metadata = {};
|
|
95
|
+
if (context?.sessionId)
|
|
96
|
+
metadata.sessionId = context.sessionId;
|
|
97
|
+
if (context?.quoteId)
|
|
98
|
+
metadata.quoteId = context.quoteId;
|
|
99
|
+
if (context?.correlationId)
|
|
100
|
+
metadata.correlationId = context.correlationId;
|
|
101
|
+
if (context?.traceId)
|
|
102
|
+
metadata.traceId = context.traceId;
|
|
103
|
+
if (context?.userId)
|
|
104
|
+
metadata.userId = context.userId;
|
|
105
|
+
if (remoteAddress)
|
|
106
|
+
metadata['remote-address'] = remoteAddress;
|
|
107
|
+
if (payload !== undefined) {
|
|
108
|
+
const fieldName = this.configs.payloadFieldName ?? 'payload';
|
|
109
|
+
if (typeof payload === 'string' &&
|
|
110
|
+
(payload.startsWith('{') || payload.startsWith('['))) {
|
|
111
|
+
try {
|
|
112
|
+
metadata[fieldName] = JSON.parse(payload);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
metadata[fieldName] = payload;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
metadata[fieldName] = payload;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (trace)
|
|
123
|
+
metadata.trace = trace;
|
|
124
|
+
return metadata;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LoggerService } from '@nestjs/common';
|
|
2
|
+
import { LoggerModuleOptions } from './interfaces/logger-module-options.interface';
|
|
3
|
+
import { Logger as LoggerImpl } from './log';
|
|
4
|
+
export declare class Logger implements LoggerService {
|
|
5
|
+
private logger;
|
|
6
|
+
constructor(env: Record<string, string>, clientConfigs?: LoggerModuleOptions, logger?: LoggerImpl);
|
|
7
|
+
setContext(key: string, value: string): void;
|
|
8
|
+
log(message: string, payload?: any): void;
|
|
9
|
+
info(message: string, payload?: any): void;
|
|
10
|
+
error(message: string, trace?: string, remoteAddress?: string): void;
|
|
11
|
+
error(message: string, error: Error, remoteAddress?: string): void;
|
|
12
|
+
error(message: string, payload: any, trace?: string, remoteAddress?: string): void;
|
|
13
|
+
warn(message: string, payload?: any): void;
|
|
14
|
+
debug(message: string, payload?: any): void;
|
|
15
|
+
verbose(message: string, payload?: any): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=logger.class.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.class.d.ts","sourceRoot":"","sources":["../../../src/logger/logger.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,OAAO,CAAC;AAE7C,qBAAa,MAAO,YAAW,aAAa;IAIxC,OAAO,CAAC,MAAM;gBAFd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC3B,aAAa,CAAC,EAAE,mBAAmB,EAC3B,MAAM,aAAqC;IAGrD,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAI5C,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;IAIzC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;IAI1C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IACpE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAClE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAKlF,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;IAI1C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;IAI3C,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;CAG9C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
const log_1 = require("./log");
|
|
5
|
+
class Logger {
|
|
6
|
+
logger;
|
|
7
|
+
constructor(env, clientConfigs, logger = new log_1.Logger(env, clientConfigs)) {
|
|
8
|
+
this.logger = logger;
|
|
9
|
+
}
|
|
10
|
+
setContext(key, value) {
|
|
11
|
+
this.logger.setContext(key, value);
|
|
12
|
+
}
|
|
13
|
+
log(message, payload) {
|
|
14
|
+
this.logger.info(message, payload);
|
|
15
|
+
}
|
|
16
|
+
info(message, payload) {
|
|
17
|
+
this.logger.info(message, payload);
|
|
18
|
+
}
|
|
19
|
+
error(message, traceOrErrorOrPayload, traceOrRemoteAddress, remoteAddress) {
|
|
20
|
+
this.logger.error(message, traceOrErrorOrPayload, traceOrRemoteAddress, remoteAddress);
|
|
21
|
+
}
|
|
22
|
+
warn(message, payload) {
|
|
23
|
+
this.logger.warn(message, payload);
|
|
24
|
+
}
|
|
25
|
+
debug(message, payload) {
|
|
26
|
+
this.logger.debug(message, payload);
|
|
27
|
+
}
|
|
28
|
+
verbose(message, payload) {
|
|
29
|
+
this.logger.verbose(message, payload);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { ConfigurableModuleClass, ASYNC_OPTIONS_TYPE, OPTIONS_TYPE } from './logger.module.definition';
|
|
3
|
+
export declare class LoggerModule extends ConfigurableModuleClass {
|
|
4
|
+
static register(options: typeof OPTIONS_TYPE): DynamicModule;
|
|
5
|
+
static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=logger.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.module.d.ts","sourceRoot":"","sources":["../../../src/logger/logger.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkB,MAAM,gBAAgB,CAAC;AAK/D,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACb,MAAM,4BAA4B,CAAC;AAGpC,qBAKa,YAAa,SAAQ,uBAAuB;IACvD,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,YAAY,GAAG,aAAa;IAM5D,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,kBAAkB,GAAG,aAAa;CAKxE"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { LoggerModuleOptions } from './interfaces/logger-module-options.interface';
|
|
2
|
+
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<LoggerModuleOptions, "register", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: LoggerModuleOptions & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<LoggerModuleOptions, "create"> & Partial<{}>;
|
|
3
|
+
//# sourceMappingURL=logger.module.definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.module.definition.d.ts","sourceRoot":"","sources":["../../../src/logger/logger.module.definition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AAEnF,eAAO,MACL,uBAAuB,iGACvB,oBAAoB,mBACpB,YAAY,qCACZ,kBAAkB,sGAC4C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = void 0;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
_a = new common_1.ConfigurableModuleBuilder().build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggerModule = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const config_1 = require("@edirect/config");
|
|
7
|
+
const logger_context_middleware_1 = require("../middleware/logger-context.middleware");
|
|
8
|
+
const logger_service_1 = require("./logger.service");
|
|
9
|
+
const logger_module_definition_1 = require("./logger.module.definition");
|
|
10
|
+
// TODO For TODO changes check the documentation: https://docs.nestjs.com/fundamentals/dynamic-modules
|
|
11
|
+
let LoggerModule = class LoggerModule extends logger_module_definition_1.ConfigurableModuleClass {
|
|
12
|
+
static register(options) {
|
|
13
|
+
return {
|
|
14
|
+
...super.register(options),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
static registerAsync(options) {
|
|
18
|
+
return {
|
|
19
|
+
...super.registerAsync(options),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.LoggerModule = LoggerModule;
|
|
24
|
+
exports.LoggerModule = LoggerModule = tslib_1.__decorate([
|
|
25
|
+
(0, common_1.Global)(),
|
|
26
|
+
(0, common_1.Module)({
|
|
27
|
+
providers: [logger_service_1.LoggerService, config_1.ConfigService, logger_context_middleware_1.LoggerContextMiddleware],
|
|
28
|
+
exports: [logger_service_1.LoggerService, logger_context_middleware_1.LoggerContextMiddleware],
|
|
29
|
+
})
|
|
30
|
+
], LoggerModule);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ConfigService } from '@edirect/config';
|
|
2
|
+
import type { LoggerModuleOptions } from './interfaces/logger-module-options.interface';
|
|
3
|
+
export declare class LoggerService {
|
|
4
|
+
private readonly configService;
|
|
5
|
+
private options?;
|
|
6
|
+
private readonly logger;
|
|
7
|
+
constructor(configService: ConfigService, options?: LoggerModuleOptions | undefined);
|
|
8
|
+
setContext(key: string, value: string): void;
|
|
9
|
+
log(message: string, payload?: any): void;
|
|
10
|
+
info(message: string, payload?: any): void;
|
|
11
|
+
error(message: string, trace?: string, remoteAddress?: string): void;
|
|
12
|
+
error(message: string, error: Error, remoteAddress?: string): void;
|
|
13
|
+
error(message: string, payload: any, trace?: string, remoteAddress?: string): void;
|
|
14
|
+
warn(message: string, payload?: any): void;
|
|
15
|
+
debug(message: string, payload?: any): void;
|
|
16
|
+
verbose(message: string, payload?: any): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=logger.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.service.d.ts","sourceRoot":"","sources":["../../../src/logger/logger.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AAIxF,qBACa,aAAa;IAIC,OAAO,CAAC,QAAQ,CAAC,aAAa;IAGrD,OAAO,CAAC,OAAO,CAAC;IANlB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAGU,aAAa,EAAE,aAAa,EAG5D,OAAO,CAAC,EAAE,mBAAmB,YAAA;IAKvC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAI5C,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;IAIzC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;IAI1C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IACpE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAClE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAKlF,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;IAI1C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;IAI3C,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;CAG9C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggerService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const config_1 = require("@edirect/config");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const logger_class_1 = require("./logger.class");
|
|
8
|
+
const logger_module_definition_1 = require("./logger.module.definition");
|
|
9
|
+
let LoggerService = class LoggerService {
|
|
10
|
+
configService;
|
|
11
|
+
options;
|
|
12
|
+
logger;
|
|
13
|
+
constructor(configService, options) {
|
|
14
|
+
this.configService = configService;
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.logger = new logger_class_1.Logger(this.configService.getConfig(), this.options);
|
|
17
|
+
}
|
|
18
|
+
setContext(key, value) {
|
|
19
|
+
this.logger.setContext(key, value);
|
|
20
|
+
}
|
|
21
|
+
log(message, payload) {
|
|
22
|
+
this.logger.log(message, payload);
|
|
23
|
+
}
|
|
24
|
+
info(message, payload) {
|
|
25
|
+
this.logger.info(message, payload);
|
|
26
|
+
}
|
|
27
|
+
error(message, traceOrErrorOrPayload, traceOrRemoteAddress, remoteAddress) {
|
|
28
|
+
this.logger.error(message, traceOrErrorOrPayload, traceOrRemoteAddress, remoteAddress);
|
|
29
|
+
}
|
|
30
|
+
warn(message, payload) {
|
|
31
|
+
this.logger.warn(message, payload);
|
|
32
|
+
}
|
|
33
|
+
debug(message, payload) {
|
|
34
|
+
this.logger.debug(message, payload);
|
|
35
|
+
}
|
|
36
|
+
verbose(message, payload) {
|
|
37
|
+
this.logger.verbose(message, payload);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.LoggerService = LoggerService;
|
|
41
|
+
exports.LoggerService = LoggerService = tslib_1.__decorate([
|
|
42
|
+
(0, common_1.Injectable)(),
|
|
43
|
+
tslib_1.__param(0, (0, common_1.Inject)(config_1.ConfigService)),
|
|
44
|
+
tslib_1.__param(1, (0, common_1.Optional)()),
|
|
45
|
+
tslib_1.__param(1, (0, common_1.Inject)(logger_module_definition_1.MODULE_OPTIONS_TOKEN)),
|
|
46
|
+
tslib_1.__metadata("design:paramtypes", [config_1.ConfigService, Object])
|
|
47
|
+
], LoggerService);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NestMiddleware } from '@nestjs/common';
|
|
2
|
+
import { Request, Response, NextFunction } from 'express';
|
|
3
|
+
export declare class LoggerContextMiddleware implements NestMiddleware {
|
|
4
|
+
private generateId;
|
|
5
|
+
use(req: Request, _res: Response, next: NextFunction): void;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=logger-context.middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-context.middleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/logger-context.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI1D,qBACa,uBAAwB,YAAW,cAAc;IAC5D,OAAO,CAAC,UAAU;IAKlB,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY;CAarD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggerContextMiddleware = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const async_context_1 = require("../context/async-context");
|
|
8
|
+
let LoggerContextMiddleware = class LoggerContextMiddleware {
|
|
9
|
+
generateId() {
|
|
10
|
+
const appName = process.env.APP_TITLE?.replace(/\s+/g, '-').toLowerCase();
|
|
11
|
+
return appName ? `${appName}-${(0, crypto_1.randomUUID)()}` : (0, crypto_1.randomUUID)();
|
|
12
|
+
}
|
|
13
|
+
use(req, _res, next) {
|
|
14
|
+
const context = {
|
|
15
|
+
sessionId: req.headers['x-session-id'],
|
|
16
|
+
quoteId: req.headers['x-quote-id'],
|
|
17
|
+
traceId: req.headers['x-trace-id'],
|
|
18
|
+
correlationId: req.headers['x-correlation-id'] || this.generateId(),
|
|
19
|
+
userId: req.user?.id,
|
|
20
|
+
};
|
|
21
|
+
async_context_1.loggerAsyncStorage.run(context, () => {
|
|
22
|
+
next();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.LoggerContextMiddleware = LoggerContextMiddleware;
|
|
27
|
+
exports.LoggerContextMiddleware = LoggerContextMiddleware = tslib_1.__decorate([
|
|
28
|
+
(0, common_1.Injectable)()
|
|
29
|
+
], LoggerContextMiddleware);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"5.9.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/logger",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.63",
|
|
4
|
+
"packageScope": "@edirect",
|
|
4
5
|
"main": "./dist/src/index.js",
|
|
5
6
|
"types": "./dist/src/index.d.ts",
|
|
6
7
|
"exports": {
|
|
@@ -16,11 +17,27 @@
|
|
|
16
17
|
"dist"
|
|
17
18
|
],
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"@edirect/config": "
|
|
20
|
+
"@edirect/config": "workspace:*",
|
|
20
21
|
"@nestjs/common": "^11.2.1",
|
|
21
22
|
"pino": "10.3.1",
|
|
22
23
|
"supertest": "7.2.2",
|
|
23
24
|
"tslib": "^2.8.1"
|
|
24
25
|
},
|
|
25
|
-
"
|
|
26
|
+
"nx": {
|
|
27
|
+
"name": "@edirect/logger",
|
|
28
|
+
"targets": {
|
|
29
|
+
"build": {
|
|
30
|
+
"executor": "@nx/js:tsc",
|
|
31
|
+
"options": {
|
|
32
|
+
"main": "{workspaceRoot}/packages/edirect-logger/src/index.ts",
|
|
33
|
+
"tsConfig": "{workspaceRoot}/packages/edirect-logger/tsconfig.lib.json",
|
|
34
|
+
"outputPath": "{workspaceRoot}/packages/edirect-logger/dist",
|
|
35
|
+
"assets": [
|
|
36
|
+
"{workspaceRoot}/packages/edirect-logger/package.json",
|
|
37
|
+
"{workspaceRoot}/packages/edirect-logger/README.md"
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
26
43
|
}
|