@nest-boot/logger 8.0.0-beta.0 → 8.0.0-beta.1
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/logger-module-options.interface.d.ts +1 -2
- package/dist/logger.d.ts +1 -49
- package/dist/logger.js +11 -54
- package/dist/logger.js.map +1 -1
- package/dist/logger.module-definition.d.ts +1 -0
- package/dist/logger.module-definition.js +1 -0
- package/dist/logger.module-definition.js.map +1 -1
- package/dist/logger.module.d.ts +2 -22
- package/dist/logger.module.js +38 -41
- package/dist/logger.module.js.map +1 -1
- package/dist/pino-http.d.ts +3 -2
- package/dist/pino-http.js +2 -3
- package/dist/pino-http.js.map +1 -1
- package/package.json +35 -22
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import { type Options } from "pino-http";
|
|
2
|
-
|
|
3
|
-
export type LoggerModuleOptions = Options;
|
|
2
|
+
export type LoggerModuleOptions = Pick<Options, "autoLogging" | "enabled" | "formatters" | "genReqId" | "redact" | "serializers" | "stream" | "timestamp">;
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,67 +1,19 @@
|
|
|
1
1
|
import { type LoggerService } from "@nestjs/common";
|
|
2
2
|
import { type Bindings } from "pino";
|
|
3
|
-
/**
|
|
4
|
-
* Request-scoped structured logger built on top of pino.
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
7
|
-
* Implements the NestJS {@link LoggerService} interface. Each request
|
|
8
|
-
* gets its own logger context via {@link RequestContext}, supporting
|
|
9
|
-
* request-scoped bindings and automatic context propagation.
|
|
10
|
-
*/
|
|
11
3
|
export declare class Logger implements LoggerService {
|
|
12
4
|
private parentClass;
|
|
13
|
-
|
|
5
|
+
private readonly loggerMiddleware?;
|
|
14
6
|
private context?;
|
|
15
|
-
/** Fallback pino logger when no request context is active. @internal */
|
|
16
7
|
private globalLogger?;
|
|
17
|
-
/** Creates a new Logger instance.
|
|
18
|
-
* @param parentClass - The parent class that owns this logger instance
|
|
19
|
-
*/
|
|
20
8
|
constructor(parentClass: object);
|
|
21
|
-
/** Returns the current logger context name. */
|
|
22
9
|
getContext(): string | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* Sets the context name for this logger instance.
|
|
25
|
-
* @param context - The context name (typically the class name)
|
|
26
|
-
*/
|
|
27
10
|
setContext(context: string): void;
|
|
28
|
-
/**
|
|
29
|
-
* Logs a message at the `trace` level.
|
|
30
|
-
* @param message - Log message
|
|
31
|
-
* @param optionalParams - Additional structured data or context override
|
|
32
|
-
*/
|
|
33
11
|
verbose(message: string, ...optionalParams: unknown[]): void;
|
|
34
|
-
/**
|
|
35
|
-
* Logs a message at the `debug` level.
|
|
36
|
-
* @param message - Log message
|
|
37
|
-
* @param optionalParams - Additional structured data or context override
|
|
38
|
-
*/
|
|
39
12
|
debug(message: string, ...optionalParams: unknown[]): void;
|
|
40
|
-
/**
|
|
41
|
-
* Logs a message at the `info` level.
|
|
42
|
-
* @param message - Log message
|
|
43
|
-
* @param optionalParams - Additional structured data or context override
|
|
44
|
-
*/
|
|
45
13
|
log(message: string, ...optionalParams: unknown[]): void;
|
|
46
|
-
/**
|
|
47
|
-
* Logs a message at the `warn` level.
|
|
48
|
-
* @param message - Log message
|
|
49
|
-
* @param optionalParams - Additional structured data or context override
|
|
50
|
-
*/
|
|
51
14
|
warn(message: string, ...optionalParams: unknown[]): void;
|
|
52
|
-
/**
|
|
53
|
-
* Logs a message at the `error` level.
|
|
54
|
-
* @param message - Log message
|
|
55
|
-
* @param optionalParams - Additional structured data or context override
|
|
56
|
-
*/
|
|
57
15
|
error(message: string, ...optionalParams: unknown[]): void;
|
|
58
|
-
/**
|
|
59
|
-
* Merges additional bindings into the current request's log context.
|
|
60
|
-
* @param bindings - Key-value pairs to add to log output
|
|
61
|
-
*/
|
|
62
16
|
assign(bindings: Bindings): void;
|
|
63
|
-
/** Gets the current pino logger from request context or falls back to global. @internal */
|
|
64
17
|
private get pinoLogger();
|
|
65
|
-
/** Dispatches a log message at the given level. @internal */
|
|
66
18
|
private call;
|
|
67
19
|
}
|
package/dist/logger.js
CHANGED
|
@@ -11,114 +11,66 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
13
|
import { RequestContext } from "@nest-boot/request-context";
|
|
14
|
-
import { Inject, Injectable, Scope } from "@nestjs/common";
|
|
14
|
+
import { Inject, Injectable, Optional, Scope, } from "@nestjs/common";
|
|
15
15
|
import { INQUIRER } from "@nestjs/core";
|
|
16
16
|
import pino from "pino";
|
|
17
|
-
import { BINDINGS, PINO_LOGGER } from "./logger.module-definition.js";
|
|
18
|
-
/**
|
|
19
|
-
* Request-scoped structured logger built on top of pino.
|
|
20
|
-
*
|
|
21
|
-
* @remarks
|
|
22
|
-
* Implements the NestJS {@link LoggerService} interface. Each request
|
|
23
|
-
* gets its own logger context via {@link RequestContext}, supporting
|
|
24
|
-
* request-scoped bindings and automatic context propagation.
|
|
25
|
-
*/
|
|
17
|
+
import { BINDINGS, PINO_HTTP, PINO_LOGGER, } from "./logger.module-definition.js";
|
|
26
18
|
let Logger = class Logger {
|
|
27
19
|
parentClass;
|
|
28
|
-
|
|
20
|
+
loggerMiddleware;
|
|
29
21
|
context;
|
|
30
|
-
/** Fallback pino logger when no request context is active. @internal */
|
|
31
22
|
globalLogger;
|
|
32
|
-
/** Creates a new Logger instance.
|
|
33
|
-
* @param parentClass - The parent class that owns this logger instance
|
|
34
|
-
*/
|
|
35
23
|
constructor(parentClass) {
|
|
36
24
|
this.parentClass = parentClass;
|
|
37
25
|
this.setContext(this.parentClass?.constructor?.name);
|
|
38
26
|
}
|
|
39
|
-
/** Returns the current logger context name. */
|
|
40
27
|
getContext() {
|
|
41
28
|
return this.context;
|
|
42
29
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Sets the context name for this logger instance.
|
|
45
|
-
* @param context - The context name (typically the class name)
|
|
46
|
-
*/
|
|
47
30
|
setContext(context) {
|
|
48
31
|
this.context = context;
|
|
49
32
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Logs a message at the `trace` level.
|
|
52
|
-
* @param message - Log message
|
|
53
|
-
* @param optionalParams - Additional structured data or context override
|
|
54
|
-
*/
|
|
55
33
|
verbose(message, ...optionalParams) {
|
|
56
34
|
this.call("trace", message, ...optionalParams);
|
|
57
35
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Logs a message at the `debug` level.
|
|
60
|
-
* @param message - Log message
|
|
61
|
-
* @param optionalParams - Additional structured data or context override
|
|
62
|
-
*/
|
|
63
36
|
debug(message, ...optionalParams) {
|
|
64
37
|
this.call("debug", message, ...optionalParams);
|
|
65
38
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Logs a message at the `info` level.
|
|
68
|
-
* @param message - Log message
|
|
69
|
-
* @param optionalParams - Additional structured data or context override
|
|
70
|
-
*/
|
|
71
39
|
log(message, ...optionalParams) {
|
|
72
40
|
this.call("info", message, ...optionalParams);
|
|
73
41
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Logs a message at the `warn` level.
|
|
76
|
-
* @param message - Log message
|
|
77
|
-
* @param optionalParams - Additional structured data or context override
|
|
78
|
-
*/
|
|
79
42
|
warn(message, ...optionalParams) {
|
|
80
43
|
this.call("warn", message, ...optionalParams);
|
|
81
44
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Logs a message at the `error` level.
|
|
84
|
-
* @param message - Log message
|
|
85
|
-
* @param optionalParams - Additional structured data or context override
|
|
86
|
-
*/
|
|
87
45
|
error(message, ...optionalParams) {
|
|
88
46
|
this.call("error", message, ...optionalParams);
|
|
89
47
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Merges additional bindings into the current request's log context.
|
|
92
|
-
* @param bindings - Key-value pairs to add to log output
|
|
93
|
-
*/
|
|
94
48
|
assign(bindings) {
|
|
95
49
|
RequestContext.set(BINDINGS, {
|
|
96
50
|
...(RequestContext.get(BINDINGS) ?? {}),
|
|
97
51
|
...bindings,
|
|
98
52
|
});
|
|
99
53
|
}
|
|
100
|
-
/** Gets the current pino logger from request context or falls back to global. @internal */
|
|
101
54
|
get pinoLogger() {
|
|
102
55
|
let pinoLogger;
|
|
103
56
|
try {
|
|
104
57
|
pinoLogger = RequestContext.get(PINO_LOGGER);
|
|
105
58
|
}
|
|
106
59
|
catch {
|
|
107
|
-
//
|
|
108
60
|
}
|
|
109
61
|
if (typeof pinoLogger === "undefined") {
|
|
110
|
-
return this.
|
|
62
|
+
return (this.loggerMiddleware?.logger ??
|
|
63
|
+
this.globalLogger ??
|
|
64
|
+
(this.globalLogger = pino()));
|
|
111
65
|
}
|
|
112
66
|
return pinoLogger;
|
|
113
67
|
}
|
|
114
|
-
/** Dispatches a log message at the given level. @internal */
|
|
115
68
|
call(level, message, ...optionalParams) {
|
|
116
69
|
let bindings = {};
|
|
117
70
|
try {
|
|
118
71
|
bindings = RequestContext.get(BINDINGS) ?? {};
|
|
119
72
|
}
|
|
120
73
|
catch {
|
|
121
|
-
//
|
|
122
74
|
}
|
|
123
75
|
let context = this.context;
|
|
124
76
|
if (optionalParams.length !== 0) {
|
|
@@ -134,6 +86,11 @@ let Logger = class Logger {
|
|
|
134
86
|
this.pinoLogger[level](bindings, message);
|
|
135
87
|
}
|
|
136
88
|
};
|
|
89
|
+
__decorate([
|
|
90
|
+
Optional(),
|
|
91
|
+
Inject(PINO_HTTP),
|
|
92
|
+
__metadata("design:type", Function)
|
|
93
|
+
], Logger.prototype, "loggerMiddleware", void 0);
|
|
137
94
|
Logger = __decorate([
|
|
138
95
|
Injectable({ scope: Scope.TRANSIENT }),
|
|
139
96
|
__param(0, Inject(INQUIRER)),
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,
|
|
1
|
+
{"version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Q,EAAE,CAAC;gBAC1C,OAAO,GAAG,iBAAiB,CAAC;YAC9B,CAAC;YAED,IAAI,OAAO,cAAc,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAC1C,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;YACnD,CAAC;QACH,CAAC;QAED,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE,CAAC;QAEpC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACF,CAAA;AAxIkB;IAFhB,QAAQ,EAAE;IACV,MAAM,CAAC,SAAS,CAAC;;gDACiC;AAJxC,MAAM;IADlB,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;IAgBxB,WAAA,MAAM,CAAC,QAAQ,CAAC,CAAA;;GAflB,MAAM,CA4IlB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type LoggerModuleOptions } from "./logger-module-options.interface.js";
|
|
2
2
|
export declare const PINO_LOGGER: unique symbol;
|
|
3
|
+
export declare const PINO_HTTP: unique symbol;
|
|
3
4
|
export declare const BINDINGS: unique symbol;
|
|
4
5
|
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<{}>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ConfigurableModuleBuilder } from "@nestjs/common";
|
|
2
2
|
export const PINO_LOGGER = Symbol("PINO_LOGGER");
|
|
3
|
+
export const PINO_HTTP = Symbol("PINO_HTTP");
|
|
3
4
|
export const BINDINGS = Symbol("BINDINGS");
|
|
4
5
|
export const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE, ASYNC_OPTIONS_TYPE, } = new ConfigurableModuleBuilder().build();
|
|
5
6
|
//# sourceMappingURL=logger.module-definition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.module-definition.js","sourceRoot":"","sources":["../src/logger.module-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAI3D,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAEjD,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAE3C,MAAM,CAAC,MAAM,EACX,uBAAuB,EACvB,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,GACnB,GAAG,IAAI,yBAAyB,EAAuB,CAAC,KAAK,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"logger.module-definition.js","sourceRoot":"","sources":["../src/logger.module-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAI3D,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAEjD,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAE7C,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAE3C,MAAM,CAAC,MAAM,EACX,uBAAuB,EACvB,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,GACnB,GAAG,IAAI,yBAAyB,EAAuB,CAAC,KAAK,EAAE,CAAC"}
|
package/dist/logger.module.d.ts
CHANGED
|
@@ -1,31 +1,11 @@
|
|
|
1
1
|
import { type DynamicModule, type OnModuleInit } from "@nestjs/common";
|
|
2
2
|
import { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from "./logger.module-definition.js";
|
|
3
|
-
import {
|
|
4
|
-
/**
|
|
5
|
-
* Structured logging module powered by Pino.
|
|
6
|
-
*
|
|
7
|
-
* @remarks
|
|
8
|
-
* Provides request-scoped structured logging with automatic request correlation,
|
|
9
|
-
* HTTP logging via pino-http, and a global logging interceptor.
|
|
10
|
-
*/
|
|
3
|
+
import type { LoggerModuleOptions } from "./logger-module-options.interface.js";
|
|
11
4
|
export declare class LoggerModule extends ConfigurableModuleClass implements OnModuleInit {
|
|
12
5
|
private readonly options;
|
|
13
|
-
|
|
14
|
-
* Registers the LoggerModule with the given options.
|
|
15
|
-
* @param options - Pino logger configuration options
|
|
16
|
-
* @returns Dynamic module configuration
|
|
17
|
-
*/
|
|
6
|
+
private loggerMiddleware?;
|
|
18
7
|
static register(options: typeof OPTIONS_TYPE): DynamicModule;
|
|
19
|
-
/**
|
|
20
|
-
* Registers the LoggerModule asynchronously with factory functions.
|
|
21
|
-
* @param options - Async configuration options
|
|
22
|
-
* @returns Dynamic module configuration
|
|
23
|
-
*/
|
|
24
8
|
static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
|
|
25
|
-
/** Creates a new LoggerModule instance.
|
|
26
|
-
* @param options - Pino logger configuration options
|
|
27
|
-
*/
|
|
28
9
|
constructor(options?: LoggerModuleOptions);
|
|
29
|
-
/** Sets up the pino-http logger and registers it in the request context middleware. */
|
|
30
10
|
onModuleInit(): void;
|
|
31
11
|
}
|
package/dist/logger.module.js
CHANGED
|
@@ -10,65 +10,35 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
|
+
import { randomUUID } from "node:crypto";
|
|
13
14
|
import { REQUEST, RequestContext, RequestContextModule, RESPONSE, } from "@nest-boot/request-context";
|
|
14
15
|
import { Global, Inject, Module, Optional, } from "@nestjs/common";
|
|
15
16
|
import { APP_INTERCEPTOR } from "@nestjs/core";
|
|
16
|
-
import { randomUUID } from "crypto";
|
|
17
|
-
import pino from "pino";
|
|
18
17
|
import { LoggingInterceptor } from "./logger.interceptor.js";
|
|
19
18
|
import { Logger } from "./logger.js";
|
|
20
|
-
import { BINDINGS, ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, PINO_LOGGER, } from "./logger.module-definition.js";
|
|
19
|
+
import { BINDINGS, ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, PINO_HTTP, PINO_LOGGER, } from "./logger.module-definition.js";
|
|
21
20
|
import pinoHttp from "./pino-http.js";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* HTTP logging via pino-http, and a global logging interceptor.
|
|
28
|
-
*/
|
|
21
|
+
const pinoHttpProvider = {
|
|
22
|
+
provide: PINO_HTTP,
|
|
23
|
+
inject: [{ token: MODULE_OPTIONS_TOKEN, optional: true }],
|
|
24
|
+
useFactory: (options) => createLoggerMiddleware(options),
|
|
25
|
+
};
|
|
29
26
|
let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
30
27
|
options;
|
|
31
|
-
|
|
32
|
-
* Registers the LoggerModule with the given options.
|
|
33
|
-
* @param options - Pino logger configuration options
|
|
34
|
-
* @returns Dynamic module configuration
|
|
35
|
-
*/
|
|
28
|
+
loggerMiddleware;
|
|
36
29
|
static register(options) {
|
|
37
30
|
return super.register(options);
|
|
38
31
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Registers the LoggerModule asynchronously with factory functions.
|
|
41
|
-
* @param options - Async configuration options
|
|
42
|
-
* @returns Dynamic module configuration
|
|
43
|
-
*/
|
|
44
32
|
static registerAsync(options) {
|
|
45
33
|
return super.registerAsync(options);
|
|
46
34
|
}
|
|
47
|
-
/** Creates a new LoggerModule instance.
|
|
48
|
-
* @param options - Pino logger configuration options
|
|
49
|
-
*/
|
|
50
35
|
constructor(options = {}) {
|
|
51
36
|
super();
|
|
52
|
-
this.options = options;
|
|
53
|
-
this.options = {
|
|
54
|
-
autoLogging: {
|
|
55
|
-
ignore: (req) => process.env.NODE_ENV !== "production" &&
|
|
56
|
-
req.headers["x-logging"] === "false",
|
|
57
|
-
...(typeof this.options.autoLogging !== "boolean"
|
|
58
|
-
? this.options.autoLogging
|
|
59
|
-
: {}),
|
|
60
|
-
},
|
|
61
|
-
redact: ["req.headers.authorization", "req.headers.cookie"],
|
|
62
|
-
genReqId: this.options.genReqId ?? (() => RequestContext.id ?? randomUUID()),
|
|
63
|
-
customReceivedMessage: () => "request received",
|
|
64
|
-
customProps: () => RequestContext.isActive() ? (RequestContext.get(BINDINGS) ?? {}) : {},
|
|
65
|
-
...this.options,
|
|
66
|
-
};
|
|
37
|
+
this.options = createLoggerOptions(options);
|
|
67
38
|
}
|
|
68
|
-
/** Sets up the pino-http logger and registers it in the request context middleware. */
|
|
69
39
|
onModuleInit() {
|
|
70
|
-
const
|
|
71
|
-
const
|
|
40
|
+
const loggerMiddleware = this.loggerMiddleware ?? (this.loggerMiddleware = pinoHttp(this.options));
|
|
41
|
+
const logger = loggerMiddleware.logger;
|
|
72
42
|
RequestContext.registerMiddleware("logger", async (ctx, next) => {
|
|
73
43
|
const req = ctx.get(REQUEST);
|
|
74
44
|
const res = ctx.get(RESPONSE);
|
|
@@ -85,11 +55,17 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
85
55
|
});
|
|
86
56
|
}
|
|
87
57
|
};
|
|
58
|
+
__decorate([
|
|
59
|
+
Optional(),
|
|
60
|
+
Inject(PINO_HTTP),
|
|
61
|
+
__metadata("design:type", Function)
|
|
62
|
+
], LoggerModule.prototype, "loggerMiddleware", void 0);
|
|
88
63
|
LoggerModule = __decorate([
|
|
89
64
|
Global(),
|
|
90
65
|
Module({
|
|
91
66
|
imports: [RequestContextModule],
|
|
92
67
|
providers: [
|
|
68
|
+
pinoHttpProvider,
|
|
93
69
|
Logger,
|
|
94
70
|
{
|
|
95
71
|
provide: APP_INTERCEPTOR,
|
|
@@ -103,4 +79,25 @@ LoggerModule = __decorate([
|
|
|
103
79
|
__metadata("design:paramtypes", [Object])
|
|
104
80
|
], LoggerModule);
|
|
105
81
|
export { LoggerModule };
|
|
82
|
+
function createLoggerMiddleware(options) {
|
|
83
|
+
return pinoHttp(createLoggerOptions(options));
|
|
84
|
+
}
|
|
85
|
+
function createLoggerOptions(options = {}) {
|
|
86
|
+
const { autoLogging, enabled, formatters, genReqId, redact, serializers, stream, timestamp, } = options;
|
|
87
|
+
return {
|
|
88
|
+
autoLogging: autoLogging ?? {
|
|
89
|
+
ignore: (req) => process.env.NODE_ENV !== "production" &&
|
|
90
|
+
req.headers["x-logging"] === "false",
|
|
91
|
+
},
|
|
92
|
+
enabled,
|
|
93
|
+
formatters,
|
|
94
|
+
redact: redact ?? ["req.headers.authorization", "req.headers.cookie"],
|
|
95
|
+
serializers,
|
|
96
|
+
stream,
|
|
97
|
+
timestamp,
|
|
98
|
+
genReqId: genReqId ?? (() => RequestContext.id ?? randomUUID()),
|
|
99
|
+
customReceivedMessage: () => "request received",
|
|
100
|
+
customProps: () => RequestContext.isActive() ? (RequestContext.get(BINDINGS) ?? {}) : {},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
106
103
|
//# sourceMappingURL=logger.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.module.js","sourceRoot":"","sources":["../src/logger.module.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,OAAO,EACP,cAAc,EACd,oBAAoB,EACpB,QAAQ,GACT,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,MAAM,EACN,MAAM,EACN,MAAM,EAEN,QAAQ,
|
|
1
|
+
{"version":3,"file":"logger.module.js","sourceRoot":"","sources":["../src/logger.module.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL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ClB,CAAC;IAqCG,WAAA,QAAQ,EAAE,CAAA;IACV,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;;GArCpB,YAAY,CAyExB;;AAED,SAAS,sBAAsB,CAAC,OAA6B;IAC3D,OAAO,QAAQ,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,mBAAmB,CAAC,UAA+B,EAAE;IAC5D,MAAM,EACJ,WAAW,EACX,OAAO,EACP,UAAU,EACV,QAAQ,EACR,MAAM,EACN,WAAW,EACX,MAAM,EACN,SAAS,GACV,GAAG,OAAO,CAAC;IAEZ,OAAO;QACL,WAAW,EAAE,WAAW,IAAI;YAC1B,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CACd,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;gBACrC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,OAAO;SACvC;QACD,OAAO;QACP,UAAU;QACV,MAAM,EAAE,MAAM,IAAI,CAAC,2BAA2B,EAAE,oBAAoB,CAAC;QACrE,WAAW;QACX,MAAM;QACN,SAAS;QACT,QAAQ,EAAE,QAAQ,IAAI,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,EAAE,IAAI,UAAU,EAAE,CAAC;QAC/D,qBAAqB,EAAE,GAAG,EAAE,CAAC,kBAAkB;QAC/C,WAAW,EAAE,GAAG,EAAE,CAChB,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;KACxE,CAAC;AACJ,CAAC"}
|
package/dist/pino-http.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Request, type Response } from "express";
|
|
2
|
-
import type
|
|
2
|
+
import { type HttpLogger } from "pino-http";
|
|
3
3
|
import { type LoggerModuleOptions } from "./logger-module-options.interface.js";
|
|
4
|
-
|
|
4
|
+
export type PinoHttpLogger = HttpLogger<Request, Response>;
|
|
5
|
+
declare const pinoHttp: (options?: LoggerModuleOptions) => PinoHttpLogger;
|
|
5
6
|
export default pinoHttp;
|
package/dist/pino-http.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
const pinoHttp = require("pino-http");
|
|
1
|
+
import createPinoHttp from "pino-http";
|
|
2
|
+
const pinoHttp = createPinoHttp;
|
|
4
3
|
export default pinoHttp;
|
|
5
4
|
//# sourceMappingURL=pino-http.js.map
|
package/dist/pino-http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pino-http.js","sourceRoot":"","sources":["../src/pino-http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pino-http.js","sourceRoot":"","sources":["../src/pino-http.ts"],"names":[],"mappings":"AACA,OAAO,cAAmC,MAAM,WAAW,CAAC;AAM5D,MAAM,QAAQ,GAAG,cAEE,CAAC;AAEpB,eAAe,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-boot/logger",
|
|
3
|
-
"version": "8.0.0-beta.
|
|
3
|
+
"version": "8.0.0-beta.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/nest-boot/nest-boot.git",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
},
|
|
15
15
|
"homepage": "",
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"main": "dist/index.js",
|
|
18
|
-
"types": "dist/index.d.ts",
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
19
|
"directories": {
|
|
20
20
|
"lib": "dist"
|
|
21
21
|
},
|
|
@@ -23,38 +23,40 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"lodash": "^4.17.21",
|
|
27
|
-
"pino": "^
|
|
28
|
-
"pino-http": "^
|
|
26
|
+
"lodash-es": "^4.17.21",
|
|
27
|
+
"pino": "^9.11.0",
|
|
28
|
+
"pino-http": "^10.5.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@nestjs/common": "
|
|
32
|
-
"@nestjs/config": "
|
|
33
|
-
"@nestjs/core": "
|
|
34
|
-
"@nestjs/platform-express": "
|
|
35
|
-
"@nestjs/testing": "
|
|
31
|
+
"@nestjs/common": "^12.0.1",
|
|
32
|
+
"@nestjs/config": "^12.0.0",
|
|
33
|
+
"@nestjs/core": "^12.0.1",
|
|
34
|
+
"@nestjs/platform-express": "^12.0.1",
|
|
35
|
+
"@nestjs/testing": "^12.0.1",
|
|
36
36
|
"@types/express": "^5.0.3",
|
|
37
|
-
"@types/lodash": "^4.17.
|
|
37
|
+
"@types/lodash-es": "^4.17.12",
|
|
38
38
|
"@types/node": "^26.0.0",
|
|
39
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
39
40
|
"eslint": "^9.39.3",
|
|
40
41
|
"express": "^5.1.0",
|
|
41
42
|
"reflect-metadata": "^0.2.2",
|
|
42
43
|
"rxjs": "^7.8.2",
|
|
43
44
|
"typescript": "^6.0.3",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"@nest-boot/
|
|
47
|
-
"@nest-boot/eslint-plugin": "^8.0.0-beta.
|
|
48
|
-
"@nest-boot/
|
|
45
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
46
|
+
"vitest": "^4.1.11",
|
|
47
|
+
"@nest-boot/eslint-config": "^8.0.0-beta.1",
|
|
48
|
+
"@nest-boot/eslint-plugin": "^8.0.0-beta.1",
|
|
49
|
+
"@nest-boot/request-context": "^8.0.0-beta.1",
|
|
50
|
+
"@nest-boot/tsconfig": "^8.0.0-beta.1"
|
|
49
51
|
},
|
|
50
52
|
"peerDependencies": {
|
|
51
|
-
"@nestjs/common": "^12.0.0
|
|
52
|
-
"@nestjs/config": "^12.0.0
|
|
53
|
-
"@nestjs/core": "^12.0.0
|
|
53
|
+
"@nestjs/common": "^12.0.0",
|
|
54
|
+
"@nestjs/config": "^12.0.0",
|
|
55
|
+
"@nestjs/core": "^12.0.0",
|
|
54
56
|
"express": "^5.0.0",
|
|
55
57
|
"reflect-metadata": "^0.2.2",
|
|
56
58
|
"rxjs": "^7.0.0",
|
|
57
|
-
"@nest-boot/request-context": "^8.0.0-beta.
|
|
59
|
+
"@nest-boot/request-context": "^8.0.0-beta.1"
|
|
58
60
|
},
|
|
59
61
|
"publishConfig": {
|
|
60
62
|
"access": "public"
|
|
@@ -66,6 +68,16 @@
|
|
|
66
68
|
]
|
|
67
69
|
},
|
|
68
70
|
"type": "module",
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=26.0.0"
|
|
73
|
+
},
|
|
74
|
+
"exports": {
|
|
75
|
+
".": {
|
|
76
|
+
"types": "./dist/index.d.ts",
|
|
77
|
+
"import": "./dist/index.js"
|
|
78
|
+
},
|
|
79
|
+
"./package.json": "./package.json"
|
|
80
|
+
},
|
|
69
81
|
"scripts": {
|
|
70
82
|
"build": "tsc -p tsconfig.build.json",
|
|
71
83
|
"clean": "rm -rf .nx && rm -rf node_modules && rm -rf dist",
|
|
@@ -75,6 +87,7 @@
|
|
|
75
87
|
"test:watch": "vitest",
|
|
76
88
|
"test:debug": "vitest --inspect-brk --no-file-parallelism",
|
|
77
89
|
"test:e2e": "vitest run --config ./vitest.config.e2e.ts",
|
|
78
|
-
"test": "vitest run"
|
|
90
|
+
"test": "vitest run",
|
|
91
|
+
"test:cov": "vitest run --coverage"
|
|
79
92
|
}
|
|
80
93
|
}
|