@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.cjs
CHANGED
|
@@ -5,9 +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 nestjs_cls = require("nestjs-cls");
|
|
9
|
-
let async_hooks = require("async_hooks");
|
|
10
8
|
let nanoid = require("nanoid");
|
|
9
|
+
let async_hooks = require("async_hooks");
|
|
11
10
|
let crypto = require("crypto");
|
|
12
11
|
//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/cjs/internal/util/isFunction.js
|
|
13
12
|
var require_isFunction = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
@@ -7074,11 +7073,6 @@ function getOpenTelemetryTraceIds() {
|
|
|
7074
7073
|
//#region src/core/trace-context.storage.ts
|
|
7075
7074
|
const traceContextStorage = new async_hooks.AsyncLocalStorage();
|
|
7076
7075
|
//#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
7076
|
//#region \0@oxc-project+runtime@0.115.0/helpers/decorate.js
|
|
7083
7077
|
function __decorate(decorators, target, key, desc) {
|
|
7084
7078
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -7087,6 +7081,37 @@ function __decorate(decorators, target, key, desc) {
|
|
|
7087
7081
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7088
7082
|
}
|
|
7089
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
|
|
7090
7115
|
//#region src/core/logger.service.ts
|
|
7091
7116
|
var _ref$2;
|
|
7092
7117
|
const PINO_LEVEL_TO_LOG_LEVEL = {
|
|
@@ -7099,12 +7124,12 @@ const PINO_LEVEL_TO_LOG_LEVEL = {
|
|
|
7099
7124
|
};
|
|
7100
7125
|
let LoggerService = class LoggerService {
|
|
7101
7126
|
context;
|
|
7102
|
-
constructor(config, formatter, writer, contextResolver,
|
|
7127
|
+
constructor(config, formatter, writer, contextResolver, traceContextService) {
|
|
7103
7128
|
this.config = config;
|
|
7104
7129
|
this.formatter = formatter;
|
|
7105
7130
|
this.writer = writer;
|
|
7106
7131
|
this.contextResolver = contextResolver;
|
|
7107
|
-
this.
|
|
7132
|
+
this.traceContextService = traceContextService;
|
|
7108
7133
|
}
|
|
7109
7134
|
setContext(context) {
|
|
7110
7135
|
this.context = context;
|
|
@@ -7154,8 +7179,8 @@ let LoggerService = class LoggerService {
|
|
|
7154
7179
|
traceId: source.traceId,
|
|
7155
7180
|
spanId: source.spanId
|
|
7156
7181
|
};
|
|
7182
|
+
const correlationId = this.traceContextService.getTraceId();
|
|
7157
7183
|
const otel = getOpenTelemetryTraceIds();
|
|
7158
|
-
const correlationId = traceContextStorage.getStore()?.correlationId;
|
|
7159
7184
|
return {
|
|
7160
7185
|
traceId: source.traceId ?? otel.traceId ?? correlationId,
|
|
7161
7186
|
spanId: source.spanId ?? otel.spanId ?? (0, nanoid.nanoid)(10)
|
|
@@ -7167,7 +7192,7 @@ LoggerService = __decorate([(0, _nestjs_common.Injectable)(), __decorateMetadata
|
|
|
7167
7192
|
Object,
|
|
7168
7193
|
Object,
|
|
7169
7194
|
Object,
|
|
7170
|
-
typeof (_ref$2 = typeof
|
|
7195
|
+
typeof (_ref$2 = typeof TraceContextService !== "undefined" && TraceContextService) === "function" ? _ref$2 : Object
|
|
7171
7196
|
])], LoggerService);
|
|
7172
7197
|
//#endregion
|
|
7173
7198
|
//#region \0@oxc-project+runtime@0.115.0/helpers/decorateParam.js
|
|
@@ -7179,9 +7204,6 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
7179
7204
|
//#endregion
|
|
7180
7205
|
//#region src/core/http-logger.interceptor.ts
|
|
7181
7206
|
var _ref$1, _ref2$1;
|
|
7182
|
-
try {
|
|
7183
|
-
require("@nestjs/graphql").GqlExecutionContext;
|
|
7184
|
-
} catch {}
|
|
7185
7207
|
let HttpLoggerInterceptor = class HttpLoggerInterceptor {
|
|
7186
7208
|
hostname = (0, os.hostname)();
|
|
7187
7209
|
pid = process.pid;
|
|
@@ -7193,6 +7215,7 @@ let HttpLoggerInterceptor = class HttpLoggerInterceptor {
|
|
|
7193
7215
|
this.reflector = reflector;
|
|
7194
7216
|
}
|
|
7195
7217
|
intercept(context, next) {
|
|
7218
|
+
if (!this.config.logRequests) return next.handle();
|
|
7196
7219
|
const request = context.switchToHttp().getRequest();
|
|
7197
7220
|
const response = context.switchToHttp().getResponse();
|
|
7198
7221
|
if (!request || !request.method) return next.handle();
|
|
@@ -7304,20 +7327,6 @@ let HttpLoggerInterceptor = class HttpLoggerInterceptor {
|
|
|
7304
7327
|
return path === excludeOption.path;
|
|
7305
7328
|
});
|
|
7306
7329
|
}
|
|
7307
|
-
sanitizeGraphQLArgs(args) {
|
|
7308
|
-
if (!args || typeof args !== "object") return args;
|
|
7309
|
-
const sanitized = { ...args };
|
|
7310
|
-
if (sanitized.input && sanitized.input.password) sanitized.input = {
|
|
7311
|
-
...sanitized.input,
|
|
7312
|
-
password: "[HIDDEN]"
|
|
7313
|
-
};
|
|
7314
|
-
return this.dataSanitizer.sanitize(sanitized);
|
|
7315
|
-
}
|
|
7316
|
-
getGraphQLResultSize(result) {
|
|
7317
|
-
if (Array.isArray(result)) return `${result.length} items`;
|
|
7318
|
-
if (result && typeof result === "object") return "1 object";
|
|
7319
|
-
return "primitive";
|
|
7320
|
-
}
|
|
7321
7330
|
extractErrorMessage(error) {
|
|
7322
7331
|
if (!error) return void 0;
|
|
7323
7332
|
if (typeof error.getResponse === "function") {
|
|
@@ -7499,20 +7508,17 @@ let PinoFormatter = class PinoFormatter extends BaseFormatter {
|
|
|
7499
7508
|
const obj = {
|
|
7500
7509
|
level: entry.level,
|
|
7501
7510
|
message: entry.message,
|
|
7502
|
-
timestamp: entry.timestamp
|
|
7503
|
-
context: entry.context,
|
|
7504
|
-
metadata: entry.metadata,
|
|
7505
|
-
trace: entry.trace
|
|
7511
|
+
timestamp: entry.timestamp
|
|
7506
7512
|
};
|
|
7513
|
+
if (entry.context) obj.context = entry.context;
|
|
7514
|
+
if (entry.metadata) obj.metadata = entry.metadata;
|
|
7515
|
+
if (entry.trace) obj.trace = entry.trace;
|
|
7507
7516
|
if (entry.traceId) obj.traceId = entry.traceId;
|
|
7508
7517
|
if (entry.spanId) obj.spanId = entry.spanId;
|
|
7509
7518
|
return JSON.stringify(obj);
|
|
7510
7519
|
}
|
|
7511
7520
|
formatHttpRequest(entry) {
|
|
7512
|
-
const
|
|
7513
|
-
if (entry.traceId) obj.traceId = entry.traceId;
|
|
7514
|
-
if (entry.spanId) obj.spanId = entry.spanId;
|
|
7515
|
-
const jsonString = JSON.stringify(obj);
|
|
7521
|
+
const jsonString = JSON.stringify(entry);
|
|
7516
7522
|
return this.options.colors ? this.colorize(jsonString, this.getColorForLevel(entry.level)) : jsonString;
|
|
7517
7523
|
}
|
|
7518
7524
|
};
|
|
@@ -7697,27 +7703,11 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
7697
7703
|
...parent.providers ?? [],
|
|
7698
7704
|
...this.createCoreProviders(),
|
|
7699
7705
|
...contextProviders,
|
|
7700
|
-
|
|
7701
|
-
provide: LOGGER_CONFIG_TOKEN,
|
|
7702
|
-
useFactory: (opts) => ({
|
|
7703
|
-
...DEFAULT_LOGGER_CONFIG,
|
|
7704
|
-
...opts,
|
|
7705
|
-
sensitiveFields: opts.sensitiveFields ?? DEFAULT_LOGGER_CONFIG.sensitiveFields,
|
|
7706
|
-
exclude: opts.exclude ?? DEFAULT_LOGGER_CONFIG.exclude
|
|
7707
|
-
}),
|
|
7708
|
-
inject: [MODULE_OPTIONS_TOKEN]
|
|
7709
|
-
},
|
|
7710
|
-
...options.logRequests ? [{
|
|
7711
|
-
provide: _nestjs_core.APP_INTERCEPTOR,
|
|
7712
|
-
useExisting: HttpLoggerInterceptor
|
|
7713
|
-
}] : []
|
|
7706
|
+
this.createConfigProvider()
|
|
7714
7707
|
],
|
|
7715
7708
|
exports: [
|
|
7716
7709
|
...parent.exports ?? [],
|
|
7717
|
-
|
|
7718
|
-
HttpLoggerInterceptor,
|
|
7719
|
-
DYNAMIC_CONTEXT_LOGGER_FACTORY_TOKEN,
|
|
7720
|
-
TraceContextMiddleware,
|
|
7710
|
+
...this.BASE_EXPORTS,
|
|
7721
7711
|
...contextProviders.map((p) => p.provide)
|
|
7722
7712
|
]
|
|
7723
7713
|
};
|
|
@@ -7731,35 +7721,38 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
7731
7721
|
...parent.providers ?? [],
|
|
7732
7722
|
...this.createCoreProviders(),
|
|
7733
7723
|
...contextProviders,
|
|
7734
|
-
|
|
7735
|
-
provide: LOGGER_CONFIG_TOKEN,
|
|
7736
|
-
useFactory: (opts) => ({
|
|
7737
|
-
...DEFAULT_LOGGER_CONFIG,
|
|
7738
|
-
...opts,
|
|
7739
|
-
sensitiveFields: opts.sensitiveFields ?? DEFAULT_LOGGER_CONFIG.sensitiveFields,
|
|
7740
|
-
exclude: opts.exclude ?? DEFAULT_LOGGER_CONFIG.exclude
|
|
7741
|
-
}),
|
|
7742
|
-
inject: [MODULE_OPTIONS_TOKEN]
|
|
7743
|
-
},
|
|
7744
|
-
{
|
|
7745
|
-
provide: _nestjs_core.APP_INTERCEPTOR,
|
|
7746
|
-
useFactory: (config, interceptor) => config.logRequests ? interceptor : null,
|
|
7747
|
-
inject: [LOGGER_CONFIG_TOKEN, HttpLoggerInterceptor]
|
|
7748
|
-
}
|
|
7724
|
+
this.createConfigProvider()
|
|
7749
7725
|
],
|
|
7750
7726
|
exports: [
|
|
7751
7727
|
...parent.exports ?? [],
|
|
7752
|
-
|
|
7753
|
-
HttpLoggerInterceptor,
|
|
7754
|
-
DYNAMIC_CONTEXT_LOGGER_FACTORY_TOKEN,
|
|
7755
|
-
TraceContextMiddleware,
|
|
7728
|
+
...this.BASE_EXPORTS,
|
|
7756
7729
|
...contextProviders.map((p) => p.provide)
|
|
7757
7730
|
]
|
|
7758
7731
|
};
|
|
7759
7732
|
}
|
|
7733
|
+
static BASE_EXPORTS = [
|
|
7734
|
+
LOGGER_SERVICE_TOKEN,
|
|
7735
|
+
HttpLoggerInterceptor,
|
|
7736
|
+
DYNAMIC_CONTEXT_LOGGER_FACTORY_TOKEN,
|
|
7737
|
+
TraceContextMiddleware,
|
|
7738
|
+
TraceContextService
|
|
7739
|
+
];
|
|
7740
|
+
static createConfigProvider() {
|
|
7741
|
+
return {
|
|
7742
|
+
provide: LOGGER_CONFIG_TOKEN,
|
|
7743
|
+
useFactory: (opts) => ({
|
|
7744
|
+
...DEFAULT_LOGGER_CONFIG,
|
|
7745
|
+
...opts,
|
|
7746
|
+
sensitiveFields: opts.sensitiveFields ?? DEFAULT_LOGGER_CONFIG.sensitiveFields,
|
|
7747
|
+
exclude: opts.exclude ?? DEFAULT_LOGGER_CONFIG.exclude
|
|
7748
|
+
}),
|
|
7749
|
+
inject: [MODULE_OPTIONS_TOKEN]
|
|
7750
|
+
};
|
|
7751
|
+
}
|
|
7760
7752
|
static createCoreProviders() {
|
|
7761
7753
|
return [
|
|
7762
7754
|
TraceContextMiddleware,
|
|
7755
|
+
TraceContextService,
|
|
7763
7756
|
FormatterFactory,
|
|
7764
7757
|
ConsoleWriter,
|
|
7765
7758
|
ContextResolver,
|
|
@@ -7798,6 +7791,10 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
7798
7791
|
RequestIdGenerator,
|
|
7799
7792
|
LOGGER_CONFIG_TOKEN
|
|
7800
7793
|
]
|
|
7794
|
+
},
|
|
7795
|
+
{
|
|
7796
|
+
provide: _nestjs_core.APP_INTERCEPTOR,
|
|
7797
|
+
useExisting: HttpLoggerInterceptor
|
|
7801
7798
|
}
|
|
7802
7799
|
];
|
|
7803
7800
|
}
|
|
@@ -7812,17 +7809,8 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
7812
7809
|
LoggerModule = __decorate([(0, _nestjs_common.Module)({})], LoggerModule);
|
|
7813
7810
|
//#endregion
|
|
7814
7811
|
//#region src/decorators/index.ts
|
|
7815
|
-
/**
|
|
7816
|
-
* Decorator to set logging context for a class or method
|
|
7817
|
-
*/
|
|
7818
7812
|
const LogContext = (context) => (0, _nestjs_common.SetMetadata)(LOGGER_CONTEXT_METADATA, context);
|
|
7819
|
-
/**
|
|
7820
|
-
* Decorator to add metadata to logs
|
|
7821
|
-
*/
|
|
7822
7813
|
const LogMetadata = (metadata) => (0, _nestjs_common.SetMetadata)(LOGGER_METADATA_METADATA, metadata);
|
|
7823
|
-
/**
|
|
7824
|
-
* Decorator to exclude logging for a controller or method
|
|
7825
|
-
*/
|
|
7826
7814
|
const ExcludeLogging = () => (0, _nestjs_common.SetMetadata)(LOGGER_EXCLUDE_METADATA, true);
|
|
7827
7815
|
//#endregion
|
|
7828
7816
|
exports.ExcludeLogging = ExcludeLogging;
|
|
@@ -7847,5 +7835,11 @@ Object.defineProperty(exports, "LoggerService", {
|
|
|
7847
7835
|
return LoggerService;
|
|
7848
7836
|
}
|
|
7849
7837
|
});
|
|
7838
|
+
Object.defineProperty(exports, "TraceContextService", {
|
|
7839
|
+
enumerable: true,
|
|
7840
|
+
get: function() {
|
|
7841
|
+
return TraceContextService;
|
|
7842
|
+
}
|
|
7843
|
+
});
|
|
7850
7844
|
|
|
7851
7845
|
//# sourceMappingURL=index.cjs.map
|