@adatechnology/logger 0.0.8 → 0.0.10
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/README.md +2 -17
- package/agents/skills/SKILL.md +15 -5
- package/dist/index.d.ts +36 -8
- package/dist/index.js +272 -173
- package/package.json +1 -1
- package/src/context/async-context.service.ts +1 -1
- package/src/implementations/winston/winston.logger.module.ts +231 -176
- package/src/implementations/winston/winston.logger.provider.ts +47 -48
- package/src/index.ts +14 -2
- package/src/interceptors/exclude-http-logging.decorator.ts +6 -0
- package/src/interceptors/http-logging.interceptor.ts +40 -4
- package/src/logger.config.ts +6 -0
- package/src/logger.interface.ts +24 -8
- package/src/logger.module.ts +13 -4
- package/src/logger.provider.ts +19 -30
- package/src/logger.token.ts +1 -0
package/README.md
CHANGED
|
@@ -107,9 +107,7 @@ Ao realizar um log, você pode passar as seguintes propriedades para enriquecer
|
|
|
107
107
|
- `libMethod`: O método interno da biblioteca sendo executado. Ex: `get`.
|
|
108
108
|
- `meta`: Objeto com metadados adicionais (será exibido em uma única linha compacta).
|
|
109
109
|
|
|
110
|
-
> ✅ **Padrão
|
|
111
|
-
>
|
|
112
|
-
> ⚠️ **Compatibilidade legada:** payload em `params` ainda é aceito e promovido para `meta` internamente para não quebrar serviços antigos.
|
|
110
|
+
> ✅ **Padrão obrigatório:** enviar payload estruturado em `meta`.
|
|
113
111
|
|
|
114
112
|
### `meta` vs `params` (recomendação)
|
|
115
113
|
|
|
@@ -130,20 +128,7 @@ this.logger.error({
|
|
|
130
128
|
});
|
|
131
129
|
```
|
|
132
130
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
```ts
|
|
136
|
-
this.logger.error({
|
|
137
|
-
message: "Exception caught in filter",
|
|
138
|
-
context: "HttpExceptionFilter.logResponse",
|
|
139
|
-
requestId,
|
|
140
|
-
params: {
|
|
141
|
-
request: { path, method, headers, params, query, body },
|
|
142
|
-
response: { status, headers, messages },
|
|
143
|
-
error: { type, message, status, body, details },
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
```
|
|
131
|
+
Campos fora do contrato (`message`, `context`, `meta`) não são recomendados na API pública.
|
|
147
132
|
|
|
148
133
|
### Exemplo de Log de Biblioteca
|
|
149
134
|
|
package/agents/skills/SKILL.md
CHANGED
|
@@ -6,42 +6,52 @@ description: Patterns for @adatechnology/logger. Use when configuring Winston lo
|
|
|
6
6
|
# 📝 Logger Standards
|
|
7
7
|
|
|
8
8
|
## 🚀 Setup Example
|
|
9
|
+
|
|
9
10
|
```typescript
|
|
10
11
|
@Module({
|
|
11
12
|
imports: [
|
|
12
13
|
LoggerModule.forRoot({
|
|
13
|
-
level:
|
|
14
|
-
sensitiveKeys: [
|
|
14
|
+
level: "info",
|
|
15
|
+
sensitiveKeys: ["password", "token", "clientSecret"],
|
|
15
16
|
}),
|
|
16
17
|
],
|
|
17
18
|
})
|
|
18
19
|
export class AppModule implements NestModule {
|
|
19
20
|
configure(consumer: MiddlewareConsumer) {
|
|
20
21
|
// Required to enable Request-ID tracking across async calls
|
|
21
|
-
consumer.apply(RequestContextMiddleware).forRoutes(
|
|
22
|
+
consumer.apply(RequestContextMiddleware).forRoutes("*");
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
```
|
|
25
26
|
|
|
26
27
|
## 🏗️ Usage Pattern
|
|
28
|
+
|
|
27
29
|
```typescript
|
|
28
30
|
@Injectable()
|
|
29
31
|
export class MyService {
|
|
30
32
|
constructor(
|
|
31
|
-
@Inject(LOGGER_PROVIDER) private readonly logger: LoggerProviderInterface
|
|
33
|
+
@Inject(LOGGER_PROVIDER) private readonly logger: LoggerProviderInterface,
|
|
32
34
|
) {}
|
|
33
35
|
|
|
34
36
|
doWork() {
|
|
35
|
-
this.logger.info(
|
|
37
|
+
this.logger.info({
|
|
38
|
+
message: "Action performed",
|
|
39
|
+
context: MyService.name,
|
|
40
|
+
meta: { userId: "123" },
|
|
41
|
+
});
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
```
|
|
39
45
|
|
|
40
46
|
## 🔐 Obfuscation
|
|
47
|
+
|
|
41
48
|
The logger automatically hides values for keys defined in `sensitiveKeys`.
|
|
49
|
+
|
|
42
50
|
- **Default Keys**: `password`, `token`, `authorization`, `cookie`, `secret`.
|
|
43
51
|
- **Custom Keys**: Add via `LoggerModule.forRoot()`.
|
|
44
52
|
|
|
45
53
|
## 🛠️ Internal Mechanics
|
|
54
|
+
|
|
46
55
|
- **Async Context**: Uses `AsyncLocalStorage` to store the Request-ID.
|
|
47
56
|
- **Context Access**: Use `getContext()` to retrieve the current request state anywhere in the call stack.
|
|
57
|
+
- **Type naming**: aliases de tipagem com sufixo `Params`/`Result` devem usar **PascalCase** (ex.: `InfoParams`, `InfoResult`).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import * as _nestjs_common from '@nestjs/common';
|
|
1
2
|
import { DynamicModule, NestMiddleware, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
3
|
import { LoggerOptions } from 'winston';
|
|
4
|
+
import { Reflector } from '@nestjs/core';
|
|
3
5
|
import { Observable } from 'rxjs';
|
|
4
6
|
|
|
5
7
|
interface ObfuscatorKey {
|
|
@@ -19,18 +21,32 @@ declare enum LoggerLevel {
|
|
|
19
21
|
WARN = "warn",
|
|
20
22
|
ERROR = "error"
|
|
21
23
|
}
|
|
22
|
-
|
|
24
|
+
type LogParams = {
|
|
23
25
|
message: string;
|
|
24
26
|
context?: string;
|
|
25
27
|
meta?: Record<string, unknown>;
|
|
26
|
-
}
|
|
28
|
+
};
|
|
29
|
+
type LogResult = void;
|
|
30
|
+
type DebugParams = LogParams;
|
|
31
|
+
type DebugResult = LogResult;
|
|
32
|
+
type InfoParams = LogParams;
|
|
33
|
+
type InfoResult = LogResult;
|
|
34
|
+
type WarnParams = LogParams;
|
|
35
|
+
type WarnResult = LogResult;
|
|
36
|
+
type ErrorParams = LogParams;
|
|
37
|
+
type ErrorResult = LogResult;
|
|
27
38
|
interface LoggerProviderInterface {
|
|
28
|
-
debug(
|
|
29
|
-
info(
|
|
30
|
-
warn(
|
|
31
|
-
error(
|
|
39
|
+
debug(params: DebugParams): DebugResult;
|
|
40
|
+
info(params: InfoParams): InfoResult;
|
|
41
|
+
warn(params: WarnParams): WarnResult;
|
|
42
|
+
error(params: ErrorParams): ErrorResult;
|
|
32
43
|
setContext?(context: string): void;
|
|
33
44
|
}
|
|
45
|
+
type WriteLogParams = {
|
|
46
|
+
level: LoggerLevel;
|
|
47
|
+
payload: LogParams;
|
|
48
|
+
};
|
|
49
|
+
type WriteLogResult = LogResult;
|
|
34
50
|
|
|
35
51
|
interface LoggerConfig extends WinstonModuleConfig {
|
|
36
52
|
/**
|
|
@@ -69,10 +85,16 @@ interface LoggerConfig extends WinstonModuleConfig {
|
|
|
69
85
|
* Versão da biblioteca/módulo que está gerando o log
|
|
70
86
|
*/
|
|
71
87
|
libVersion?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Rotas excluídas do HttpLoggingInterceptor (ex.: ['/health'])
|
|
90
|
+
* Suporta prefixo exato ou parcial via startsWith
|
|
91
|
+
*/
|
|
92
|
+
interceptorExcludedPaths?: string[];
|
|
72
93
|
}
|
|
73
94
|
declare const DEFAULT_LOGGER_CONFIG: LoggerConfig;
|
|
74
95
|
|
|
75
96
|
declare const LOGGER_PROVIDER = "LOGGER_PROVIDER";
|
|
97
|
+
declare const LOGGER_CONFIG = "LOGGER_CONFIG";
|
|
76
98
|
declare const HTTP_LOGGING_INTERCEPTOR = "HTTP_LOGGING_INTERCEPTOR";
|
|
77
99
|
|
|
78
100
|
declare class LoggerModule {
|
|
@@ -99,7 +121,11 @@ declare class RequestContextMiddleware implements NestMiddleware {
|
|
|
99
121
|
|
|
100
122
|
declare class HttpLoggingInterceptor implements NestInterceptor {
|
|
101
123
|
private readonly logger;
|
|
102
|
-
|
|
124
|
+
private readonly reflector;
|
|
125
|
+
private readonly excludedPaths;
|
|
126
|
+
private toErrorMessage;
|
|
127
|
+
constructor(logger: LoggerProviderInterface, reflector: Reflector, config?: LoggerConfig);
|
|
128
|
+
private isExcluded;
|
|
103
129
|
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
104
130
|
}
|
|
105
131
|
|
|
@@ -109,9 +135,11 @@ declare const HTTP_LOGGING_INTERCEPTOR_CONTEXT: {
|
|
|
109
135
|
readonly ON_ERROR: "HttpLoggingInterceptor.onError";
|
|
110
136
|
};
|
|
111
137
|
|
|
138
|
+
declare const ExcludeHttpLogging: () => _nestjs_common.CustomDecorator<string>;
|
|
139
|
+
|
|
112
140
|
type RequestContext = Record<string, unknown> | undefined;
|
|
113
141
|
|
|
114
142
|
declare function getContext(): RequestContext;
|
|
115
143
|
declare function runWithContext<T>(ctx: Record<string, unknown>, fn: () => T): T;
|
|
116
144
|
|
|
117
|
-
export { DEFAULT_LOGGER_CONFIG, HTTP_LOGGING_INTERCEPTOR, HTTP_LOGGING_INTERCEPTOR_CONTEXT, HttpLoggingInterceptor, LOGGER_PROVIDER, type
|
|
145
|
+
export { DEFAULT_LOGGER_CONFIG, type DebugParams, type DebugResult, type ErrorParams, type ErrorResult, ExcludeHttpLogging, HTTP_LOGGING_INTERCEPTOR, HTTP_LOGGING_INTERCEPTOR_CONTEXT, HttpLoggingInterceptor, type InfoParams, type InfoResult, LOGGER_CONFIG, LOGGER_PROVIDER, type LogParams, type LogResult, type LoggerConfig, LoggerLevel, LoggerModule, type LoggerProviderInterface, RequestContextMiddleware, type WarnParams, type WarnResult, type WriteLogParams, type WriteLogResult, getContext, runWithContext };
|