@globalart/nestjs-logger 2.3.0 → 2.4.2
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/index.cjs +76 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -19
- package/dist/index.d.mts +26 -19
- package/dist/index.mjs +71 -83
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import * as _nestjs_common0 from "@nestjs/common";
|
|
4
4
|
import { CallHandler, DynamicModule, ExecutionContext, LoggerService as LoggerService$1, MiddlewareConsumer, NestInterceptor, NestModule, RequestMethod } from "@nestjs/common";
|
|
5
5
|
import { Reflector } from "@nestjs/core";
|
|
6
|
-
import { ClsService } from "nestjs-cls";
|
|
7
6
|
|
|
8
7
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/types/internal/Subscription.d.ts
|
|
9
8
|
/**
|
|
@@ -353,10 +352,10 @@ declare class Observable<T> implements Subscribable<T> {
|
|
|
353
352
|
}
|
|
354
353
|
//#endregion
|
|
355
354
|
//#region src/types/index.d.ts
|
|
356
|
-
type LogLevel
|
|
355
|
+
type LogLevel = "error" | "warn" | "info" | "debug" | "verbose";
|
|
357
356
|
type LogFormat = "json" | "text" | "pino";
|
|
358
357
|
interface LogEntry {
|
|
359
|
-
readonly level: LogLevel
|
|
358
|
+
readonly level: LogLevel;
|
|
360
359
|
readonly message: string;
|
|
361
360
|
readonly timestamp: Date;
|
|
362
361
|
readonly context?: string;
|
|
@@ -405,7 +404,7 @@ interface ExcludeOption {
|
|
|
405
404
|
path: string;
|
|
406
405
|
}
|
|
407
406
|
interface LoggerConfiguration {
|
|
408
|
-
readonly level: LogLevel
|
|
407
|
+
readonly level: LogLevel;
|
|
409
408
|
readonly timestamp: boolean;
|
|
410
409
|
readonly colors: boolean;
|
|
411
410
|
readonly context?: string;
|
|
@@ -428,7 +427,6 @@ interface ILogFormatter {
|
|
|
428
427
|
format(entry: LogEntry): string;
|
|
429
428
|
formatHttpRequest(entry: HttpRequestLogEntry): string;
|
|
430
429
|
}
|
|
431
|
-
type LogLevel = "error" | "warn" | "info" | "debug" | "verbose";
|
|
432
430
|
interface ILogWriter {
|
|
433
431
|
write(formattedLog: string, level?: LogLevel): void;
|
|
434
432
|
}
|
|
@@ -442,15 +440,33 @@ interface IRequestIdGenerator {
|
|
|
442
440
|
generate(): string;
|
|
443
441
|
}
|
|
444
442
|
//#endregion
|
|
443
|
+
//#region src/core/trace-context.service.d.ts
|
|
444
|
+
declare class TraceContextService {
|
|
445
|
+
/**
|
|
446
|
+
* Sets trace-id for the current async context.
|
|
447
|
+
* Affects all subsequent logs within the same request/async scope.
|
|
448
|
+
*/
|
|
449
|
+
setTraceId(traceId: string): void;
|
|
450
|
+
/**
|
|
451
|
+
* Returns the current trace-id from the async context.
|
|
452
|
+
*/
|
|
453
|
+
getTraceId(): string | undefined;
|
|
454
|
+
/**
|
|
455
|
+
* Runs a callback in a new isolated async context with the given trace-id.
|
|
456
|
+
* Does not affect the parent context.
|
|
457
|
+
*/
|
|
458
|
+
runWithTraceId<T>(traceId: string, fn: () => T): T;
|
|
459
|
+
}
|
|
460
|
+
//#endregion
|
|
445
461
|
//#region src/core/logger.service.d.ts
|
|
446
462
|
declare class LoggerService implements LoggerService$1, ILogger {
|
|
447
463
|
private readonly config;
|
|
448
464
|
private readonly formatter;
|
|
449
465
|
private readonly writer;
|
|
450
466
|
private readonly contextResolver;
|
|
451
|
-
private readonly
|
|
467
|
+
private readonly traceContextService;
|
|
452
468
|
private context?;
|
|
453
|
-
constructor(config: LoggerConfiguration, formatter: ILogFormatter, writer: ILogWriter, contextResolver: IContextResolver,
|
|
469
|
+
constructor(config: LoggerConfiguration, formatter: ILogFormatter, writer: ILogWriter, contextResolver: IContextResolver, traceContextService: TraceContextService);
|
|
454
470
|
setContext(context: string): void;
|
|
455
471
|
log(options: LogOptions): void;
|
|
456
472
|
error(options: LogOptions): void;
|
|
@@ -479,8 +495,6 @@ declare class HttpLoggerInterceptor implements NestInterceptor {
|
|
|
479
495
|
private sanitizeHeaders;
|
|
480
496
|
private getRequestMethod;
|
|
481
497
|
private shouldExcludeRequest;
|
|
482
|
-
private sanitizeGraphQLArgs;
|
|
483
|
-
private getGraphQLResultSize;
|
|
484
498
|
private extractErrorMessage;
|
|
485
499
|
private extractErrorTrace;
|
|
486
500
|
}
|
|
@@ -510,6 +524,8 @@ declare class LoggerModule extends ConfigurableModuleClass implements NestModule
|
|
|
510
524
|
configure(consumer: MiddlewareConsumer): void;
|
|
511
525
|
static forRoot(options?: typeof OPTIONS_TYPE): DynamicModule;
|
|
512
526
|
static forRootAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
|
|
527
|
+
private static readonly BASE_EXPORTS;
|
|
528
|
+
private static createConfigProvider;
|
|
513
529
|
private static createCoreProviders;
|
|
514
530
|
private static createDynamicContextProviders;
|
|
515
531
|
}
|
|
@@ -520,18 +536,9 @@ declare const LOGGER_METADATA_METADATA: unique symbol;
|
|
|
520
536
|
declare const LOGGER_EXCLUDE_METADATA: unique symbol;
|
|
521
537
|
//#endregion
|
|
522
538
|
//#region src/decorators/index.d.ts
|
|
523
|
-
/**
|
|
524
|
-
* Decorator to set logging context for a class or method
|
|
525
|
-
*/
|
|
526
539
|
declare const LogContext: (context: string) => _nestjs_common0.CustomDecorator<typeof LOGGER_CONTEXT_METADATA>;
|
|
527
|
-
/**
|
|
528
|
-
* Decorator to add metadata to logs
|
|
529
|
-
*/
|
|
530
540
|
declare const LogMetadata: (metadata: Record<string, unknown>) => _nestjs_common0.CustomDecorator<typeof LOGGER_METADATA_METADATA>;
|
|
531
|
-
/**
|
|
532
|
-
* Decorator to exclude logging for a controller or method
|
|
533
|
-
*/
|
|
534
541
|
declare const ExcludeLogging: () => _nestjs_common0.CustomDecorator<typeof LOGGER_EXCLUDE_METADATA>;
|
|
535
542
|
//#endregion
|
|
536
|
-
export { ExcludeLogging, HttpLoggerInterceptor, InjectLogger, LogContext, LogMetadata, LoggerModule, LoggerService };
|
|
543
|
+
export { ExcludeLogging, HttpLoggerInterceptor, InjectLogger, LogContext, LogMetadata, LoggerModule, LoggerService, TraceContextService };
|
|
537
544
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import * as _nestjs_common0 from "@nestjs/common";
|
|
4
4
|
import { CallHandler, DynamicModule, ExecutionContext, LoggerService as LoggerService$1, MiddlewareConsumer, NestInterceptor, NestModule, RequestMethod } from "@nestjs/common";
|
|
5
5
|
import { Reflector } from "@nestjs/core";
|
|
6
|
-
import { ClsService } from "nestjs-cls";
|
|
7
6
|
|
|
8
7
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/types/internal/Subscription.d.ts
|
|
9
8
|
/**
|
|
@@ -353,10 +352,10 @@ declare class Observable<T> implements Subscribable<T> {
|
|
|
353
352
|
}
|
|
354
353
|
//#endregion
|
|
355
354
|
//#region src/types/index.d.ts
|
|
356
|
-
type LogLevel
|
|
355
|
+
type LogLevel = "error" | "warn" | "info" | "debug" | "verbose";
|
|
357
356
|
type LogFormat = "json" | "text" | "pino";
|
|
358
357
|
interface LogEntry {
|
|
359
|
-
readonly level: LogLevel
|
|
358
|
+
readonly level: LogLevel;
|
|
360
359
|
readonly message: string;
|
|
361
360
|
readonly timestamp: Date;
|
|
362
361
|
readonly context?: string;
|
|
@@ -405,7 +404,7 @@ interface ExcludeOption {
|
|
|
405
404
|
path: string;
|
|
406
405
|
}
|
|
407
406
|
interface LoggerConfiguration {
|
|
408
|
-
readonly level: LogLevel
|
|
407
|
+
readonly level: LogLevel;
|
|
409
408
|
readonly timestamp: boolean;
|
|
410
409
|
readonly colors: boolean;
|
|
411
410
|
readonly context?: string;
|
|
@@ -428,7 +427,6 @@ interface ILogFormatter {
|
|
|
428
427
|
format(entry: LogEntry): string;
|
|
429
428
|
formatHttpRequest(entry: HttpRequestLogEntry): string;
|
|
430
429
|
}
|
|
431
|
-
type LogLevel = "error" | "warn" | "info" | "debug" | "verbose";
|
|
432
430
|
interface ILogWriter {
|
|
433
431
|
write(formattedLog: string, level?: LogLevel): void;
|
|
434
432
|
}
|
|
@@ -442,15 +440,33 @@ interface IRequestIdGenerator {
|
|
|
442
440
|
generate(): string;
|
|
443
441
|
}
|
|
444
442
|
//#endregion
|
|
443
|
+
//#region src/core/trace-context.service.d.ts
|
|
444
|
+
declare class TraceContextService {
|
|
445
|
+
/**
|
|
446
|
+
* Sets trace-id for the current async context.
|
|
447
|
+
* Affects all subsequent logs within the same request/async scope.
|
|
448
|
+
*/
|
|
449
|
+
setTraceId(traceId: string): void;
|
|
450
|
+
/**
|
|
451
|
+
* Returns the current trace-id from the async context.
|
|
452
|
+
*/
|
|
453
|
+
getTraceId(): string | undefined;
|
|
454
|
+
/**
|
|
455
|
+
* Runs a callback in a new isolated async context with the given trace-id.
|
|
456
|
+
* Does not affect the parent context.
|
|
457
|
+
*/
|
|
458
|
+
runWithTraceId<T>(traceId: string, fn: () => T): T;
|
|
459
|
+
}
|
|
460
|
+
//#endregion
|
|
445
461
|
//#region src/core/logger.service.d.ts
|
|
446
462
|
declare class LoggerService implements LoggerService$1, ILogger {
|
|
447
463
|
private readonly config;
|
|
448
464
|
private readonly formatter;
|
|
449
465
|
private readonly writer;
|
|
450
466
|
private readonly contextResolver;
|
|
451
|
-
private readonly
|
|
467
|
+
private readonly traceContextService;
|
|
452
468
|
private context?;
|
|
453
|
-
constructor(config: LoggerConfiguration, formatter: ILogFormatter, writer: ILogWriter, contextResolver: IContextResolver,
|
|
469
|
+
constructor(config: LoggerConfiguration, formatter: ILogFormatter, writer: ILogWriter, contextResolver: IContextResolver, traceContextService: TraceContextService);
|
|
454
470
|
setContext(context: string): void;
|
|
455
471
|
log(options: LogOptions): void;
|
|
456
472
|
error(options: LogOptions): void;
|
|
@@ -479,8 +495,6 @@ declare class HttpLoggerInterceptor implements NestInterceptor {
|
|
|
479
495
|
private sanitizeHeaders;
|
|
480
496
|
private getRequestMethod;
|
|
481
497
|
private shouldExcludeRequest;
|
|
482
|
-
private sanitizeGraphQLArgs;
|
|
483
|
-
private getGraphQLResultSize;
|
|
484
498
|
private extractErrorMessage;
|
|
485
499
|
private extractErrorTrace;
|
|
486
500
|
}
|
|
@@ -510,6 +524,8 @@ declare class LoggerModule extends ConfigurableModuleClass implements NestModule
|
|
|
510
524
|
configure(consumer: MiddlewareConsumer): void;
|
|
511
525
|
static forRoot(options?: typeof OPTIONS_TYPE): DynamicModule;
|
|
512
526
|
static forRootAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
|
|
527
|
+
private static readonly BASE_EXPORTS;
|
|
528
|
+
private static createConfigProvider;
|
|
513
529
|
private static createCoreProviders;
|
|
514
530
|
private static createDynamicContextProviders;
|
|
515
531
|
}
|
|
@@ -520,18 +536,9 @@ declare const LOGGER_METADATA_METADATA: unique symbol;
|
|
|
520
536
|
declare const LOGGER_EXCLUDE_METADATA: unique symbol;
|
|
521
537
|
//#endregion
|
|
522
538
|
//#region src/decorators/index.d.ts
|
|
523
|
-
/**
|
|
524
|
-
* Decorator to set logging context for a class or method
|
|
525
|
-
*/
|
|
526
539
|
declare const LogContext: (context: string) => _nestjs_common0.CustomDecorator<typeof LOGGER_CONTEXT_METADATA>;
|
|
527
|
-
/**
|
|
528
|
-
* Decorator to add metadata to logs
|
|
529
|
-
*/
|
|
530
540
|
declare const LogMetadata: (metadata: Record<string, unknown>) => _nestjs_common0.CustomDecorator<typeof LOGGER_METADATA_METADATA>;
|
|
531
|
-
/**
|
|
532
|
-
* Decorator to exclude logging for a controller or method
|
|
533
|
-
*/
|
|
534
541
|
declare const ExcludeLogging: () => _nestjs_common0.CustomDecorator<typeof LOGGER_EXCLUDE_METADATA>;
|
|
535
542
|
//#endregion
|
|
536
|
-
export { ExcludeLogging, HttpLoggerInterceptor, InjectLogger, LogContext, LogMetadata, LoggerModule, LoggerService };
|
|
543
|
+
export { ExcludeLogging, HttpLoggerInterceptor, InjectLogger, LogContext, LogMetadata, LoggerModule, LoggerService, TraceContextService };
|
|
537
544
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -2,9 +2,8 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { ConfigurableModuleBuilder, Inject, Injectable, Module, RequestMethod, SetMetadata } from "@nestjs/common";
|
|
3
3
|
import { APP_INTERCEPTOR, Reflector } from "@nestjs/core";
|
|
4
4
|
import { hostname } from "os";
|
|
5
|
-
import { ClsService } from "nestjs-cls";
|
|
6
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
7
5
|
import { nanoid } from "nanoid";
|
|
6
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
8
7
|
import { randomBytes, randomUUID } from "crypto";
|
|
9
8
|
//#region \0rolldown/runtime.js
|
|
10
9
|
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
@@ -7075,11 +7074,6 @@ function getOpenTelemetryTraceIds() {
|
|
|
7075
7074
|
//#region src/core/trace-context.storage.ts
|
|
7076
7075
|
const traceContextStorage = new AsyncLocalStorage();
|
|
7077
7076
|
//#endregion
|
|
7078
|
-
//#region \0@oxc-project+runtime@0.115.0/helpers/decorateMetadata.js
|
|
7079
|
-
function __decorateMetadata(k, v) {
|
|
7080
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7081
|
-
}
|
|
7082
|
-
//#endregion
|
|
7083
7077
|
//#region \0@oxc-project+runtime@0.115.0/helpers/decorate.js
|
|
7084
7078
|
function __decorate(decorators, target, key, desc) {
|
|
7085
7079
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -7088,6 +7082,37 @@ function __decorate(decorators, target, key, desc) {
|
|
|
7088
7082
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7089
7083
|
}
|
|
7090
7084
|
//#endregion
|
|
7085
|
+
//#region src/core/trace-context.service.ts
|
|
7086
|
+
let TraceContextService = class TraceContextService {
|
|
7087
|
+
/**
|
|
7088
|
+
* Sets trace-id for the current async context.
|
|
7089
|
+
* Affects all subsequent logs within the same request/async scope.
|
|
7090
|
+
*/
|
|
7091
|
+
setTraceId(traceId) {
|
|
7092
|
+
const store = traceContextStorage.getStore();
|
|
7093
|
+
if (store) store.correlationId = traceId;
|
|
7094
|
+
}
|
|
7095
|
+
/**
|
|
7096
|
+
* Returns the current trace-id from the async context.
|
|
7097
|
+
*/
|
|
7098
|
+
getTraceId() {
|
|
7099
|
+
return traceContextStorage.getStore()?.correlationId;
|
|
7100
|
+
}
|
|
7101
|
+
/**
|
|
7102
|
+
* Runs a callback in a new isolated async context with the given trace-id.
|
|
7103
|
+
* Does not affect the parent context.
|
|
7104
|
+
*/
|
|
7105
|
+
runWithTraceId(traceId, fn) {
|
|
7106
|
+
return traceContextStorage.run({ correlationId: traceId }, fn);
|
|
7107
|
+
}
|
|
7108
|
+
};
|
|
7109
|
+
TraceContextService = __decorate([Injectable()], TraceContextService);
|
|
7110
|
+
//#endregion
|
|
7111
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/decorateMetadata.js
|
|
7112
|
+
function __decorateMetadata(k, v) {
|
|
7113
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7114
|
+
}
|
|
7115
|
+
//#endregion
|
|
7091
7116
|
//#region src/core/logger.service.ts
|
|
7092
7117
|
var _ref$2;
|
|
7093
7118
|
const PINO_LEVEL_TO_LOG_LEVEL = {
|
|
@@ -7100,12 +7125,12 @@ const PINO_LEVEL_TO_LOG_LEVEL = {
|
|
|
7100
7125
|
};
|
|
7101
7126
|
let LoggerService = class LoggerService {
|
|
7102
7127
|
context;
|
|
7103
|
-
constructor(config, formatter, writer, contextResolver,
|
|
7128
|
+
constructor(config, formatter, writer, contextResolver, traceContextService) {
|
|
7104
7129
|
this.config = config;
|
|
7105
7130
|
this.formatter = formatter;
|
|
7106
7131
|
this.writer = writer;
|
|
7107
7132
|
this.contextResolver = contextResolver;
|
|
7108
|
-
this.
|
|
7133
|
+
this.traceContextService = traceContextService;
|
|
7109
7134
|
}
|
|
7110
7135
|
setContext(context) {
|
|
7111
7136
|
this.context = context;
|
|
@@ -7155,8 +7180,8 @@ let LoggerService = class LoggerService {
|
|
|
7155
7180
|
traceId: source.traceId,
|
|
7156
7181
|
spanId: source.spanId
|
|
7157
7182
|
};
|
|
7183
|
+
const correlationId = this.traceContextService.getTraceId();
|
|
7158
7184
|
const otel = getOpenTelemetryTraceIds();
|
|
7159
|
-
const correlationId = traceContextStorage.getStore()?.correlationId;
|
|
7160
7185
|
return {
|
|
7161
7186
|
traceId: source.traceId ?? otel.traceId ?? correlationId,
|
|
7162
7187
|
spanId: source.spanId ?? otel.spanId ?? nanoid(10)
|
|
@@ -7168,7 +7193,7 @@ LoggerService = __decorate([Injectable(), __decorateMetadata("design:paramtypes"
|
|
|
7168
7193
|
Object,
|
|
7169
7194
|
Object,
|
|
7170
7195
|
Object,
|
|
7171
|
-
typeof (_ref$2 = typeof
|
|
7196
|
+
typeof (_ref$2 = typeof TraceContextService !== "undefined" && TraceContextService) === "function" ? _ref$2 : Object
|
|
7172
7197
|
])], LoggerService);
|
|
7173
7198
|
//#endregion
|
|
7174
7199
|
//#region \0@oxc-project+runtime@0.115.0/helpers/decorateParam.js
|
|
@@ -7180,9 +7205,6 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
7180
7205
|
//#endregion
|
|
7181
7206
|
//#region src/core/http-logger.interceptor.ts
|
|
7182
7207
|
var _ref$1, _ref2$1;
|
|
7183
|
-
try {
|
|
7184
|
-
__require("@nestjs/graphql").GqlExecutionContext;
|
|
7185
|
-
} catch {}
|
|
7186
7208
|
let HttpLoggerInterceptor = class HttpLoggerInterceptor {
|
|
7187
7209
|
hostname = hostname();
|
|
7188
7210
|
pid = process.pid;
|
|
@@ -7194,6 +7216,7 @@ let HttpLoggerInterceptor = class HttpLoggerInterceptor {
|
|
|
7194
7216
|
this.reflector = reflector;
|
|
7195
7217
|
}
|
|
7196
7218
|
intercept(context, next) {
|
|
7219
|
+
if (!this.config.logRequests) return next.handle();
|
|
7197
7220
|
const request = context.switchToHttp().getRequest();
|
|
7198
7221
|
const response = context.switchToHttp().getResponse();
|
|
7199
7222
|
if (!request || !request.method) return next.handle();
|
|
@@ -7305,20 +7328,6 @@ let HttpLoggerInterceptor = class HttpLoggerInterceptor {
|
|
|
7305
7328
|
return path === excludeOption.path;
|
|
7306
7329
|
});
|
|
7307
7330
|
}
|
|
7308
|
-
sanitizeGraphQLArgs(args) {
|
|
7309
|
-
if (!args || typeof args !== "object") return args;
|
|
7310
|
-
const sanitized = { ...args };
|
|
7311
|
-
if (sanitized.input && sanitized.input.password) sanitized.input = {
|
|
7312
|
-
...sanitized.input,
|
|
7313
|
-
password: "[HIDDEN]"
|
|
7314
|
-
};
|
|
7315
|
-
return this.dataSanitizer.sanitize(sanitized);
|
|
7316
|
-
}
|
|
7317
|
-
getGraphQLResultSize(result) {
|
|
7318
|
-
if (Array.isArray(result)) return `${result.length} items`;
|
|
7319
|
-
if (result && typeof result === "object") return "1 object";
|
|
7320
|
-
return "primitive";
|
|
7321
|
-
}
|
|
7322
7331
|
extractErrorMessage(error) {
|
|
7323
7332
|
if (!error) return void 0;
|
|
7324
7333
|
if (typeof error.getResponse === "function") {
|
|
@@ -7500,20 +7509,17 @@ let PinoFormatter = class PinoFormatter extends BaseFormatter {
|
|
|
7500
7509
|
const obj = {
|
|
7501
7510
|
level: entry.level,
|
|
7502
7511
|
message: entry.message,
|
|
7503
|
-
timestamp: entry.timestamp
|
|
7504
|
-
context: entry.context,
|
|
7505
|
-
metadata: entry.metadata,
|
|
7506
|
-
trace: entry.trace
|
|
7512
|
+
timestamp: entry.timestamp
|
|
7507
7513
|
};
|
|
7514
|
+
if (entry.context) obj.context = entry.context;
|
|
7515
|
+
if (entry.metadata) obj.metadata = entry.metadata;
|
|
7516
|
+
if (entry.trace) obj.trace = entry.trace;
|
|
7508
7517
|
if (entry.traceId) obj.traceId = entry.traceId;
|
|
7509
7518
|
if (entry.spanId) obj.spanId = entry.spanId;
|
|
7510
7519
|
return JSON.stringify(obj);
|
|
7511
7520
|
}
|
|
7512
7521
|
formatHttpRequest(entry) {
|
|
7513
|
-
const
|
|
7514
|
-
if (entry.traceId) obj.traceId = entry.traceId;
|
|
7515
|
-
if (entry.spanId) obj.spanId = entry.spanId;
|
|
7516
|
-
const jsonString = JSON.stringify(obj);
|
|
7522
|
+
const jsonString = JSON.stringify(entry);
|
|
7517
7523
|
return this.options.colors ? this.colorize(jsonString, this.getColorForLevel(entry.level)) : jsonString;
|
|
7518
7524
|
}
|
|
7519
7525
|
};
|
|
@@ -7698,27 +7704,11 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
7698
7704
|
...parent.providers ?? [],
|
|
7699
7705
|
...this.createCoreProviders(),
|
|
7700
7706
|
...contextProviders,
|
|
7701
|
-
|
|
7702
|
-
provide: LOGGER_CONFIG_TOKEN,
|
|
7703
|
-
useFactory: (opts) => ({
|
|
7704
|
-
...DEFAULT_LOGGER_CONFIG,
|
|
7705
|
-
...opts,
|
|
7706
|
-
sensitiveFields: opts.sensitiveFields ?? DEFAULT_LOGGER_CONFIG.sensitiveFields,
|
|
7707
|
-
exclude: opts.exclude ?? DEFAULT_LOGGER_CONFIG.exclude
|
|
7708
|
-
}),
|
|
7709
|
-
inject: [MODULE_OPTIONS_TOKEN]
|
|
7710
|
-
},
|
|
7711
|
-
...options.logRequests ? [{
|
|
7712
|
-
provide: APP_INTERCEPTOR,
|
|
7713
|
-
useExisting: HttpLoggerInterceptor
|
|
7714
|
-
}] : []
|
|
7707
|
+
this.createConfigProvider()
|
|
7715
7708
|
],
|
|
7716
7709
|
exports: [
|
|
7717
7710
|
...parent.exports ?? [],
|
|
7718
|
-
|
|
7719
|
-
HttpLoggerInterceptor,
|
|
7720
|
-
DYNAMIC_CONTEXT_LOGGER_FACTORY_TOKEN,
|
|
7721
|
-
TraceContextMiddleware,
|
|
7711
|
+
...this.BASE_EXPORTS,
|
|
7722
7712
|
...contextProviders.map((p) => p.provide)
|
|
7723
7713
|
]
|
|
7724
7714
|
};
|
|
@@ -7732,35 +7722,38 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
7732
7722
|
...parent.providers ?? [],
|
|
7733
7723
|
...this.createCoreProviders(),
|
|
7734
7724
|
...contextProviders,
|
|
7735
|
-
|
|
7736
|
-
provide: LOGGER_CONFIG_TOKEN,
|
|
7737
|
-
useFactory: (opts) => ({
|
|
7738
|
-
...DEFAULT_LOGGER_CONFIG,
|
|
7739
|
-
...opts,
|
|
7740
|
-
sensitiveFields: opts.sensitiveFields ?? DEFAULT_LOGGER_CONFIG.sensitiveFields,
|
|
7741
|
-
exclude: opts.exclude ?? DEFAULT_LOGGER_CONFIG.exclude
|
|
7742
|
-
}),
|
|
7743
|
-
inject: [MODULE_OPTIONS_TOKEN]
|
|
7744
|
-
},
|
|
7745
|
-
{
|
|
7746
|
-
provide: APP_INTERCEPTOR,
|
|
7747
|
-
useFactory: (config, interceptor) => config.logRequests ? interceptor : null,
|
|
7748
|
-
inject: [LOGGER_CONFIG_TOKEN, HttpLoggerInterceptor]
|
|
7749
|
-
}
|
|
7725
|
+
this.createConfigProvider()
|
|
7750
7726
|
],
|
|
7751
7727
|
exports: [
|
|
7752
7728
|
...parent.exports ?? [],
|
|
7753
|
-
|
|
7754
|
-
HttpLoggerInterceptor,
|
|
7755
|
-
DYNAMIC_CONTEXT_LOGGER_FACTORY_TOKEN,
|
|
7756
|
-
TraceContextMiddleware,
|
|
7729
|
+
...this.BASE_EXPORTS,
|
|
7757
7730
|
...contextProviders.map((p) => p.provide)
|
|
7758
7731
|
]
|
|
7759
7732
|
};
|
|
7760
7733
|
}
|
|
7734
|
+
static BASE_EXPORTS = [
|
|
7735
|
+
LOGGER_SERVICE_TOKEN,
|
|
7736
|
+
HttpLoggerInterceptor,
|
|
7737
|
+
DYNAMIC_CONTEXT_LOGGER_FACTORY_TOKEN,
|
|
7738
|
+
TraceContextMiddleware,
|
|
7739
|
+
TraceContextService
|
|
7740
|
+
];
|
|
7741
|
+
static createConfigProvider() {
|
|
7742
|
+
return {
|
|
7743
|
+
provide: LOGGER_CONFIG_TOKEN,
|
|
7744
|
+
useFactory: (opts) => ({
|
|
7745
|
+
...DEFAULT_LOGGER_CONFIG,
|
|
7746
|
+
...opts,
|
|
7747
|
+
sensitiveFields: opts.sensitiveFields ?? DEFAULT_LOGGER_CONFIG.sensitiveFields,
|
|
7748
|
+
exclude: opts.exclude ?? DEFAULT_LOGGER_CONFIG.exclude
|
|
7749
|
+
}),
|
|
7750
|
+
inject: [MODULE_OPTIONS_TOKEN]
|
|
7751
|
+
};
|
|
7752
|
+
}
|
|
7761
7753
|
static createCoreProviders() {
|
|
7762
7754
|
return [
|
|
7763
7755
|
TraceContextMiddleware,
|
|
7756
|
+
TraceContextService,
|
|
7764
7757
|
FormatterFactory,
|
|
7765
7758
|
ConsoleWriter,
|
|
7766
7759
|
ContextResolver,
|
|
@@ -7799,6 +7792,10 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
7799
7792
|
RequestIdGenerator,
|
|
7800
7793
|
LOGGER_CONFIG_TOKEN
|
|
7801
7794
|
]
|
|
7795
|
+
},
|
|
7796
|
+
{
|
|
7797
|
+
provide: APP_INTERCEPTOR,
|
|
7798
|
+
useExisting: HttpLoggerInterceptor
|
|
7802
7799
|
}
|
|
7803
7800
|
];
|
|
7804
7801
|
}
|
|
@@ -7813,19 +7810,10 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
7813
7810
|
LoggerModule = __decorate([Module({})], LoggerModule);
|
|
7814
7811
|
//#endregion
|
|
7815
7812
|
//#region src/decorators/index.ts
|
|
7816
|
-
/**
|
|
7817
|
-
* Decorator to set logging context for a class or method
|
|
7818
|
-
*/
|
|
7819
7813
|
const LogContext = (context) => SetMetadata(LOGGER_CONTEXT_METADATA, context);
|
|
7820
|
-
/**
|
|
7821
|
-
* Decorator to add metadata to logs
|
|
7822
|
-
*/
|
|
7823
7814
|
const LogMetadata = (metadata) => SetMetadata(LOGGER_METADATA_METADATA, metadata);
|
|
7824
|
-
/**
|
|
7825
|
-
* Decorator to exclude logging for a controller or method
|
|
7826
|
-
*/
|
|
7827
7815
|
const ExcludeLogging = () => SetMetadata(LOGGER_EXCLUDE_METADATA, true);
|
|
7828
7816
|
//#endregion
|
|
7829
|
-
export { ExcludeLogging, HttpLoggerInterceptor, InjectLogger, LogContext, LogMetadata, LoggerModule, LoggerService };
|
|
7817
|
+
export { ExcludeLogging, HttpLoggerInterceptor, InjectLogger, LogContext, LogMetadata, LoggerModule, LoggerService, TraceContextService };
|
|
7830
7818
|
|
|
7831
7819
|
//# sourceMappingURL=index.mjs.map
|