@globalart/nestjs-logger 2.4.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 +38 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -19
- package/dist/index.d.mts +20 -19
- package/dist/index.mjs +38 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -440,14 +440,33 @@ interface IRequestIdGenerator {
|
|
|
440
440
|
generate(): string;
|
|
441
441
|
}
|
|
442
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
|
|
443
461
|
//#region src/core/logger.service.d.ts
|
|
444
462
|
declare class LoggerService implements LoggerService$1, ILogger {
|
|
445
463
|
private readonly config;
|
|
446
464
|
private readonly formatter;
|
|
447
465
|
private readonly writer;
|
|
448
466
|
private readonly contextResolver;
|
|
467
|
+
private readonly traceContextService;
|
|
449
468
|
private context?;
|
|
450
|
-
constructor(config: LoggerConfiguration, formatter: ILogFormatter, writer: ILogWriter, contextResolver: IContextResolver);
|
|
469
|
+
constructor(config: LoggerConfiguration, formatter: ILogFormatter, writer: ILogWriter, contextResolver: IContextResolver, traceContextService: TraceContextService);
|
|
451
470
|
setContext(context: string): void;
|
|
452
471
|
log(options: LogOptions): void;
|
|
453
472
|
error(options: LogOptions): void;
|
|
@@ -511,24 +530,6 @@ declare class LoggerModule extends ConfigurableModuleClass implements NestModule
|
|
|
511
530
|
private static createDynamicContextProviders;
|
|
512
531
|
}
|
|
513
532
|
//#endregion
|
|
514
|
-
//#region src/core/trace-context.service.d.ts
|
|
515
|
-
declare class TraceContextService {
|
|
516
|
-
/**
|
|
517
|
-
* Sets trace-id for the current async context.
|
|
518
|
-
* Affects all subsequent logs within the same request/async scope.
|
|
519
|
-
*/
|
|
520
|
-
setTraceId(traceId: string): void;
|
|
521
|
-
/**
|
|
522
|
-
* Returns the current trace-id from the async context.
|
|
523
|
-
*/
|
|
524
|
-
getTraceId(): string | undefined;
|
|
525
|
-
/**
|
|
526
|
-
* Runs a callback in a new isolated async context with the given trace-id.
|
|
527
|
-
* Does not affect the parent context.
|
|
528
|
-
*/
|
|
529
|
-
runWithTraceId<T>(traceId: string, fn: () => T): T;
|
|
530
|
-
}
|
|
531
|
-
//#endregion
|
|
532
533
|
//#region src/constants/index.d.ts
|
|
533
534
|
declare const LOGGER_CONTEXT_METADATA: unique symbol;
|
|
534
535
|
declare const LOGGER_METADATA_METADATA: unique symbol;
|
package/dist/index.d.mts
CHANGED
|
@@ -440,14 +440,33 @@ interface IRequestIdGenerator {
|
|
|
440
440
|
generate(): string;
|
|
441
441
|
}
|
|
442
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
|
|
443
461
|
//#region src/core/logger.service.d.ts
|
|
444
462
|
declare class LoggerService implements LoggerService$1, ILogger {
|
|
445
463
|
private readonly config;
|
|
446
464
|
private readonly formatter;
|
|
447
465
|
private readonly writer;
|
|
448
466
|
private readonly contextResolver;
|
|
467
|
+
private readonly traceContextService;
|
|
449
468
|
private context?;
|
|
450
|
-
constructor(config: LoggerConfiguration, formatter: ILogFormatter, writer: ILogWriter, contextResolver: IContextResolver);
|
|
469
|
+
constructor(config: LoggerConfiguration, formatter: ILogFormatter, writer: ILogWriter, contextResolver: IContextResolver, traceContextService: TraceContextService);
|
|
451
470
|
setContext(context: string): void;
|
|
452
471
|
log(options: LogOptions): void;
|
|
453
472
|
error(options: LogOptions): void;
|
|
@@ -511,24 +530,6 @@ declare class LoggerModule extends ConfigurableModuleClass implements NestModule
|
|
|
511
530
|
private static createDynamicContextProviders;
|
|
512
531
|
}
|
|
513
532
|
//#endregion
|
|
514
|
-
//#region src/core/trace-context.service.d.ts
|
|
515
|
-
declare class TraceContextService {
|
|
516
|
-
/**
|
|
517
|
-
* Sets trace-id for the current async context.
|
|
518
|
-
* Affects all subsequent logs within the same request/async scope.
|
|
519
|
-
*/
|
|
520
|
-
setTraceId(traceId: string): void;
|
|
521
|
-
/**
|
|
522
|
-
* Returns the current trace-id from the async context.
|
|
523
|
-
*/
|
|
524
|
-
getTraceId(): string | undefined;
|
|
525
|
-
/**
|
|
526
|
-
* Runs a callback in a new isolated async context with the given trace-id.
|
|
527
|
-
* Does not affect the parent context.
|
|
528
|
-
*/
|
|
529
|
-
runWithTraceId<T>(traceId: string, fn: () => T): T;
|
|
530
|
-
}
|
|
531
|
-
//#endregion
|
|
532
533
|
//#region src/constants/index.d.ts
|
|
533
534
|
declare const LOGGER_CONTEXT_METADATA: unique symbol;
|
|
534
535
|
declare const LOGGER_METADATA_METADATA: unique symbol;
|
package/dist/index.mjs
CHANGED
|
@@ -2,8 +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 { AsyncLocalStorage } from "async_hooks";
|
|
6
5
|
import { nanoid } from "nanoid";
|
|
6
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
7
7
|
import { randomBytes, randomUUID } from "crypto";
|
|
8
8
|
//#region \0rolldown/runtime.js
|
|
9
9
|
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
@@ -7074,11 +7074,6 @@ function getOpenTelemetryTraceIds() {
|
|
|
7074
7074
|
//#region src/core/trace-context.storage.ts
|
|
7075
7075
|
const traceContextStorage = new AsyncLocalStorage();
|
|
7076
7076
|
//#endregion
|
|
7077
|
-
//#region \0@oxc-project+runtime@0.115.0/helpers/decorateMetadata.js
|
|
7078
|
-
function __decorateMetadata(k, v) {
|
|
7079
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7080
|
-
}
|
|
7081
|
-
//#endregion
|
|
7082
7077
|
//#region \0@oxc-project+runtime@0.115.0/helpers/decorate.js
|
|
7083
7078
|
function __decorate(decorators, target, key, desc) {
|
|
7084
7079
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -7087,7 +7082,39 @@ function __decorate(decorators, target, key, desc) {
|
|
|
7087
7082
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7088
7083
|
}
|
|
7089
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
|
|
7090
7116
|
//#region src/core/logger.service.ts
|
|
7117
|
+
var _ref$2;
|
|
7091
7118
|
const PINO_LEVEL_TO_LOG_LEVEL = {
|
|
7092
7119
|
60: "error",
|
|
7093
7120
|
50: "error",
|
|
@@ -7098,11 +7125,12 @@ const PINO_LEVEL_TO_LOG_LEVEL = {
|
|
|
7098
7125
|
};
|
|
7099
7126
|
let LoggerService = class LoggerService {
|
|
7100
7127
|
context;
|
|
7101
|
-
constructor(config, formatter, writer, contextResolver) {
|
|
7128
|
+
constructor(config, formatter, writer, contextResolver, traceContextService) {
|
|
7102
7129
|
this.config = config;
|
|
7103
7130
|
this.formatter = formatter;
|
|
7104
7131
|
this.writer = writer;
|
|
7105
7132
|
this.contextResolver = contextResolver;
|
|
7133
|
+
this.traceContextService = traceContextService;
|
|
7106
7134
|
}
|
|
7107
7135
|
setContext(context) {
|
|
7108
7136
|
this.context = context;
|
|
@@ -7152,8 +7180,8 @@ let LoggerService = class LoggerService {
|
|
|
7152
7180
|
traceId: source.traceId,
|
|
7153
7181
|
spanId: source.spanId
|
|
7154
7182
|
};
|
|
7183
|
+
const correlationId = this.traceContextService.getTraceId();
|
|
7155
7184
|
const otel = getOpenTelemetryTraceIds();
|
|
7156
|
-
const correlationId = traceContextStorage.getStore()?.correlationId;
|
|
7157
7185
|
return {
|
|
7158
7186
|
traceId: source.traceId ?? otel.traceId ?? correlationId,
|
|
7159
7187
|
spanId: source.spanId ?? otel.spanId ?? nanoid(10)
|
|
@@ -7164,7 +7192,8 @@ LoggerService = __decorate([Injectable(), __decorateMetadata("design:paramtypes"
|
|
|
7164
7192
|
Object,
|
|
7165
7193
|
Object,
|
|
7166
7194
|
Object,
|
|
7167
|
-
Object
|
|
7195
|
+
Object,
|
|
7196
|
+
typeof (_ref$2 = typeof TraceContextService !== "undefined" && TraceContextService) === "function" ? _ref$2 : Object
|
|
7168
7197
|
])], LoggerService);
|
|
7169
7198
|
//#endregion
|
|
7170
7199
|
//#region \0@oxc-project+runtime@0.115.0/helpers/decorateParam.js
|
|
@@ -7657,32 +7686,6 @@ let TraceContextMiddleware = class TraceContextMiddleware {
|
|
|
7657
7686
|
};
|
|
7658
7687
|
TraceContextMiddleware = __decorate([Injectable()], TraceContextMiddleware);
|
|
7659
7688
|
//#endregion
|
|
7660
|
-
//#region src/core/trace-context.service.ts
|
|
7661
|
-
let TraceContextService = class TraceContextService {
|
|
7662
|
-
/**
|
|
7663
|
-
* Sets trace-id for the current async context.
|
|
7664
|
-
* Affects all subsequent logs within the same request/async scope.
|
|
7665
|
-
*/
|
|
7666
|
-
setTraceId(traceId) {
|
|
7667
|
-
const store = traceContextStorage.getStore();
|
|
7668
|
-
if (store) store.correlationId = traceId;
|
|
7669
|
-
}
|
|
7670
|
-
/**
|
|
7671
|
-
* Returns the current trace-id from the async context.
|
|
7672
|
-
*/
|
|
7673
|
-
getTraceId() {
|
|
7674
|
-
return traceContextStorage.getStore()?.correlationId;
|
|
7675
|
-
}
|
|
7676
|
-
/**
|
|
7677
|
-
* Runs a callback in a new isolated async context with the given trace-id.
|
|
7678
|
-
* Does not affect the parent context.
|
|
7679
|
-
*/
|
|
7680
|
-
runWithTraceId(traceId, fn) {
|
|
7681
|
-
return traceContextStorage.run({ correlationId: traceId }, fn);
|
|
7682
|
-
}
|
|
7683
|
-
};
|
|
7684
|
-
TraceContextService = __decorate([Injectable()], TraceContextService);
|
|
7685
|
-
//#endregion
|
|
7686
7689
|
//#region src/core/logger.module.ts
|
|
7687
7690
|
const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE, ASYNC_OPTIONS_TYPE } = new ConfigurableModuleBuilder().setClassMethodName("forRoot").setExtras({ global: true }, (definition, extras) => ({
|
|
7688
7691
|
...definition,
|