@globalart/nestjs-logger 2.4.0 → 2.4.3
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 +42 -38
- 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 +42 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5,8 +5,8 @@ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).export
|
|
|
5
5
|
let _nestjs_common = require("@nestjs/common");
|
|
6
6
|
let _nestjs_core = require("@nestjs/core");
|
|
7
7
|
let os = require("os");
|
|
8
|
-
let async_hooks = require("async_hooks");
|
|
9
8
|
let nanoid = require("nanoid");
|
|
9
|
+
let async_hooks = require("async_hooks");
|
|
10
10
|
let crypto = require("crypto");
|
|
11
11
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/cjs/internal/util/isFunction.js
|
|
12
12
|
var require_isFunction = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
@@ -7073,11 +7073,6 @@ function getOpenTelemetryTraceIds() {
|
|
|
7073
7073
|
//#region src/core/trace-context.storage.ts
|
|
7074
7074
|
const traceContextStorage = new async_hooks.AsyncLocalStorage();
|
|
7075
7075
|
//#endregion
|
|
7076
|
-
//#region \0@oxc-project+runtime@0.115.0/helpers/decorateMetadata.js
|
|
7077
|
-
function __decorateMetadata(k, v) {
|
|
7078
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7079
|
-
}
|
|
7080
|
-
//#endregion
|
|
7081
7076
|
//#region \0@oxc-project+runtime@0.115.0/helpers/decorate.js
|
|
7082
7077
|
function __decorate(decorators, target, key, desc) {
|
|
7083
7078
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -7086,7 +7081,39 @@ function __decorate(decorators, target, key, desc) {
|
|
|
7086
7081
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7087
7082
|
}
|
|
7088
7083
|
//#endregion
|
|
7084
|
+
//#region src/core/trace-context.service.ts
|
|
7085
|
+
let TraceContextService = class TraceContextService {
|
|
7086
|
+
/**
|
|
7087
|
+
* Sets trace-id for the current async context.
|
|
7088
|
+
* Affects all subsequent logs within the same request/async scope.
|
|
7089
|
+
*/
|
|
7090
|
+
setTraceId(traceId) {
|
|
7091
|
+
const store = traceContextStorage.getStore();
|
|
7092
|
+
if (store) store.correlationId = traceId;
|
|
7093
|
+
}
|
|
7094
|
+
/**
|
|
7095
|
+
* Returns the current trace-id from the async context.
|
|
7096
|
+
*/
|
|
7097
|
+
getTraceId() {
|
|
7098
|
+
return traceContextStorage.getStore()?.correlationId;
|
|
7099
|
+
}
|
|
7100
|
+
/**
|
|
7101
|
+
* Runs a callback in a new isolated async context with the given trace-id.
|
|
7102
|
+
* Does not affect the parent context.
|
|
7103
|
+
*/
|
|
7104
|
+
runWithTraceId(traceId, fn) {
|
|
7105
|
+
return traceContextStorage.run({ correlationId: traceId }, fn);
|
|
7106
|
+
}
|
|
7107
|
+
};
|
|
7108
|
+
TraceContextService = __decorate([(0, _nestjs_common.Injectable)()], TraceContextService);
|
|
7109
|
+
//#endregion
|
|
7110
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/decorateMetadata.js
|
|
7111
|
+
function __decorateMetadata(k, v) {
|
|
7112
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7113
|
+
}
|
|
7114
|
+
//#endregion
|
|
7089
7115
|
//#region src/core/logger.service.ts
|
|
7116
|
+
var _ref$2;
|
|
7090
7117
|
const PINO_LEVEL_TO_LOG_LEVEL = {
|
|
7091
7118
|
60: "error",
|
|
7092
7119
|
50: "error",
|
|
@@ -7097,11 +7124,12 @@ const PINO_LEVEL_TO_LOG_LEVEL = {
|
|
|
7097
7124
|
};
|
|
7098
7125
|
let LoggerService = class LoggerService {
|
|
7099
7126
|
context;
|
|
7100
|
-
constructor(config, formatter, writer, contextResolver) {
|
|
7127
|
+
constructor(config, formatter, writer, contextResolver, traceContextService) {
|
|
7101
7128
|
this.config = config;
|
|
7102
7129
|
this.formatter = formatter;
|
|
7103
7130
|
this.writer = writer;
|
|
7104
7131
|
this.contextResolver = contextResolver;
|
|
7132
|
+
this.traceContextService = traceContextService;
|
|
7105
7133
|
}
|
|
7106
7134
|
setContext(context) {
|
|
7107
7135
|
this.context = context;
|
|
@@ -7151,8 +7179,8 @@ let LoggerService = class LoggerService {
|
|
|
7151
7179
|
traceId: source.traceId,
|
|
7152
7180
|
spanId: source.spanId
|
|
7153
7181
|
};
|
|
7182
|
+
const correlationId = this.traceContextService.getTraceId();
|
|
7154
7183
|
const otel = getOpenTelemetryTraceIds();
|
|
7155
|
-
const correlationId = traceContextStorage.getStore()?.correlationId;
|
|
7156
7184
|
return {
|
|
7157
7185
|
traceId: source.traceId ?? otel.traceId ?? correlationId,
|
|
7158
7186
|
spanId: source.spanId ?? otel.spanId ?? (0, nanoid.nanoid)(10)
|
|
@@ -7163,7 +7191,8 @@ LoggerService = __decorate([(0, _nestjs_common.Injectable)(), __decorateMetadata
|
|
|
7163
7191
|
Object,
|
|
7164
7192
|
Object,
|
|
7165
7193
|
Object,
|
|
7166
|
-
Object
|
|
7194
|
+
Object,
|
|
7195
|
+
typeof (_ref$2 = typeof TraceContextService !== "undefined" && TraceContextService) === "function" ? _ref$2 : Object
|
|
7167
7196
|
])], LoggerService);
|
|
7168
7197
|
//#endregion
|
|
7169
7198
|
//#region \0@oxc-project+runtime@0.115.0/helpers/decorateParam.js
|
|
@@ -7656,32 +7685,6 @@ let TraceContextMiddleware = class TraceContextMiddleware {
|
|
|
7656
7685
|
};
|
|
7657
7686
|
TraceContextMiddleware = __decorate([(0, _nestjs_common.Injectable)()], TraceContextMiddleware);
|
|
7658
7687
|
//#endregion
|
|
7659
|
-
//#region src/core/trace-context.service.ts
|
|
7660
|
-
let TraceContextService = class TraceContextService {
|
|
7661
|
-
/**
|
|
7662
|
-
* Sets trace-id for the current async context.
|
|
7663
|
-
* Affects all subsequent logs within the same request/async scope.
|
|
7664
|
-
*/
|
|
7665
|
-
setTraceId(traceId) {
|
|
7666
|
-
const store = traceContextStorage.getStore();
|
|
7667
|
-
if (store) store.correlationId = traceId;
|
|
7668
|
-
}
|
|
7669
|
-
/**
|
|
7670
|
-
* Returns the current trace-id from the async context.
|
|
7671
|
-
*/
|
|
7672
|
-
getTraceId() {
|
|
7673
|
-
return traceContextStorage.getStore()?.correlationId;
|
|
7674
|
-
}
|
|
7675
|
-
/**
|
|
7676
|
-
* Runs a callback in a new isolated async context with the given trace-id.
|
|
7677
|
-
* Does not affect the parent context.
|
|
7678
|
-
*/
|
|
7679
|
-
runWithTraceId(traceId, fn) {
|
|
7680
|
-
return traceContextStorage.run({ correlationId: traceId }, fn);
|
|
7681
|
-
}
|
|
7682
|
-
};
|
|
7683
|
-
TraceContextService = __decorate([(0, _nestjs_common.Injectable)()], TraceContextService);
|
|
7684
|
-
//#endregion
|
|
7685
7688
|
//#region src/core/logger.module.ts
|
|
7686
7689
|
const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE, ASYNC_OPTIONS_TYPE } = new _nestjs_common.ConfigurableModuleBuilder().setClassMethodName("forRoot").setExtras({ global: true }, (definition, extras) => ({
|
|
7687
7690
|
...definition,
|
|
@@ -7765,18 +7768,19 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
7765
7768
|
},
|
|
7766
7769
|
{
|
|
7767
7770
|
provide: LOGGER_SERVICE_TOKEN,
|
|
7768
|
-
useFactory: (config, formatterFactory, writer, contextResolver) => {
|
|
7771
|
+
useFactory: (config, formatterFactory, writer, contextResolver, traceContextService) => {
|
|
7769
7772
|
return new LoggerService(config, formatterFactory.create(config.format, {
|
|
7770
7773
|
colors: config.colors,
|
|
7771
7774
|
timestamp: config.timestamp,
|
|
7772
7775
|
context: config.context
|
|
7773
|
-
}), writer, contextResolver);
|
|
7776
|
+
}), writer, contextResolver, traceContextService);
|
|
7774
7777
|
},
|
|
7775
7778
|
inject: [
|
|
7776
7779
|
LOGGER_CONFIG_TOKEN,
|
|
7777
7780
|
FormatterFactory,
|
|
7778
7781
|
ConsoleWriter,
|
|
7779
|
-
ContextResolver
|
|
7782
|
+
ContextResolver,
|
|
7783
|
+
TraceContextService
|
|
7780
7784
|
]
|
|
7781
7785
|
},
|
|
7782
7786
|
{
|