@globalart/nestjs-logger 2.3.0 → 2.4.0
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 +68 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -19
- package/dist/index.d.mts +25 -19
- package/dist/index.mjs +63 -78
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,6 @@ 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
8
|
let async_hooks = require("async_hooks");
|
|
10
9
|
let nanoid = require("nanoid");
|
|
11
10
|
let crypto = require("crypto");
|
|
@@ -7088,7 +7087,6 @@ function __decorate(decorators, target, key, desc) {
|
|
|
7088
7087
|
}
|
|
7089
7088
|
//#endregion
|
|
7090
7089
|
//#region src/core/logger.service.ts
|
|
7091
|
-
var _ref$2;
|
|
7092
7090
|
const PINO_LEVEL_TO_LOG_LEVEL = {
|
|
7093
7091
|
60: "error",
|
|
7094
7092
|
50: "error",
|
|
@@ -7099,12 +7097,11 @@ const PINO_LEVEL_TO_LOG_LEVEL = {
|
|
|
7099
7097
|
};
|
|
7100
7098
|
let LoggerService = class LoggerService {
|
|
7101
7099
|
context;
|
|
7102
|
-
constructor(config, formatter, writer, contextResolver
|
|
7100
|
+
constructor(config, formatter, writer, contextResolver) {
|
|
7103
7101
|
this.config = config;
|
|
7104
7102
|
this.formatter = formatter;
|
|
7105
7103
|
this.writer = writer;
|
|
7106
7104
|
this.contextResolver = contextResolver;
|
|
7107
|
-
this.clsService = clsService;
|
|
7108
7105
|
}
|
|
7109
7106
|
setContext(context) {
|
|
7110
7107
|
this.context = context;
|
|
@@ -7166,8 +7163,7 @@ LoggerService = __decorate([(0, _nestjs_common.Injectable)(), __decorateMetadata
|
|
|
7166
7163
|
Object,
|
|
7167
7164
|
Object,
|
|
7168
7165
|
Object,
|
|
7169
|
-
Object
|
|
7170
|
-
typeof (_ref$2 = typeof nestjs_cls.ClsService !== "undefined" && nestjs_cls.ClsService) === "function" ? _ref$2 : Object
|
|
7166
|
+
Object
|
|
7171
7167
|
])], LoggerService);
|
|
7172
7168
|
//#endregion
|
|
7173
7169
|
//#region \0@oxc-project+runtime@0.115.0/helpers/decorateParam.js
|
|
@@ -7179,9 +7175,6 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
7179
7175
|
//#endregion
|
|
7180
7176
|
//#region src/core/http-logger.interceptor.ts
|
|
7181
7177
|
var _ref$1, _ref2$1;
|
|
7182
|
-
try {
|
|
7183
|
-
require("@nestjs/graphql").GqlExecutionContext;
|
|
7184
|
-
} catch {}
|
|
7185
7178
|
let HttpLoggerInterceptor = class HttpLoggerInterceptor {
|
|
7186
7179
|
hostname = (0, os.hostname)();
|
|
7187
7180
|
pid = process.pid;
|
|
@@ -7193,6 +7186,7 @@ let HttpLoggerInterceptor = class HttpLoggerInterceptor {
|
|
|
7193
7186
|
this.reflector = reflector;
|
|
7194
7187
|
}
|
|
7195
7188
|
intercept(context, next) {
|
|
7189
|
+
if (!this.config.logRequests) return next.handle();
|
|
7196
7190
|
const request = context.switchToHttp().getRequest();
|
|
7197
7191
|
const response = context.switchToHttp().getResponse();
|
|
7198
7192
|
if (!request || !request.method) return next.handle();
|
|
@@ -7304,20 +7298,6 @@ let HttpLoggerInterceptor = class HttpLoggerInterceptor {
|
|
|
7304
7298
|
return path === excludeOption.path;
|
|
7305
7299
|
});
|
|
7306
7300
|
}
|
|
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
7301
|
extractErrorMessage(error) {
|
|
7322
7302
|
if (!error) return void 0;
|
|
7323
7303
|
if (typeof error.getResponse === "function") {
|
|
@@ -7499,20 +7479,17 @@ let PinoFormatter = class PinoFormatter extends BaseFormatter {
|
|
|
7499
7479
|
const obj = {
|
|
7500
7480
|
level: entry.level,
|
|
7501
7481
|
message: entry.message,
|
|
7502
|
-
timestamp: entry.timestamp
|
|
7503
|
-
context: entry.context,
|
|
7504
|
-
metadata: entry.metadata,
|
|
7505
|
-
trace: entry.trace
|
|
7482
|
+
timestamp: entry.timestamp
|
|
7506
7483
|
};
|
|
7484
|
+
if (entry.context) obj.context = entry.context;
|
|
7485
|
+
if (entry.metadata) obj.metadata = entry.metadata;
|
|
7486
|
+
if (entry.trace) obj.trace = entry.trace;
|
|
7507
7487
|
if (entry.traceId) obj.traceId = entry.traceId;
|
|
7508
7488
|
if (entry.spanId) obj.spanId = entry.spanId;
|
|
7509
7489
|
return JSON.stringify(obj);
|
|
7510
7490
|
}
|
|
7511
7491
|
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);
|
|
7492
|
+
const jsonString = JSON.stringify(entry);
|
|
7516
7493
|
return this.options.colors ? this.colorize(jsonString, this.getColorForLevel(entry.level)) : jsonString;
|
|
7517
7494
|
}
|
|
7518
7495
|
};
|
|
@@ -7679,6 +7656,32 @@ let TraceContextMiddleware = class TraceContextMiddleware {
|
|
|
7679
7656
|
};
|
|
7680
7657
|
TraceContextMiddleware = __decorate([(0, _nestjs_common.Injectable)()], TraceContextMiddleware);
|
|
7681
7658
|
//#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
|
|
7682
7685
|
//#region src/core/logger.module.ts
|
|
7683
7686
|
const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE, ASYNC_OPTIONS_TYPE } = new _nestjs_common.ConfigurableModuleBuilder().setClassMethodName("forRoot").setExtras({ global: true }, (definition, extras) => ({
|
|
7684
7687
|
...definition,
|
|
@@ -7697,27 +7700,11 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
7697
7700
|
...parent.providers ?? [],
|
|
7698
7701
|
...this.createCoreProviders(),
|
|
7699
7702
|
...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
|
-
}] : []
|
|
7703
|
+
this.createConfigProvider()
|
|
7714
7704
|
],
|
|
7715
7705
|
exports: [
|
|
7716
7706
|
...parent.exports ?? [],
|
|
7717
|
-
|
|
7718
|
-
HttpLoggerInterceptor,
|
|
7719
|
-
DYNAMIC_CONTEXT_LOGGER_FACTORY_TOKEN,
|
|
7720
|
-
TraceContextMiddleware,
|
|
7707
|
+
...this.BASE_EXPORTS,
|
|
7721
7708
|
...contextProviders.map((p) => p.provide)
|
|
7722
7709
|
]
|
|
7723
7710
|
};
|
|
@@ -7731,35 +7718,38 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
7731
7718
|
...parent.providers ?? [],
|
|
7732
7719
|
...this.createCoreProviders(),
|
|
7733
7720
|
...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
|
-
}
|
|
7721
|
+
this.createConfigProvider()
|
|
7749
7722
|
],
|
|
7750
7723
|
exports: [
|
|
7751
7724
|
...parent.exports ?? [],
|
|
7752
|
-
|
|
7753
|
-
HttpLoggerInterceptor,
|
|
7754
|
-
DYNAMIC_CONTEXT_LOGGER_FACTORY_TOKEN,
|
|
7755
|
-
TraceContextMiddleware,
|
|
7725
|
+
...this.BASE_EXPORTS,
|
|
7756
7726
|
...contextProviders.map((p) => p.provide)
|
|
7757
7727
|
]
|
|
7758
7728
|
};
|
|
7759
7729
|
}
|
|
7730
|
+
static BASE_EXPORTS = [
|
|
7731
|
+
LOGGER_SERVICE_TOKEN,
|
|
7732
|
+
HttpLoggerInterceptor,
|
|
7733
|
+
DYNAMIC_CONTEXT_LOGGER_FACTORY_TOKEN,
|
|
7734
|
+
TraceContextMiddleware,
|
|
7735
|
+
TraceContextService
|
|
7736
|
+
];
|
|
7737
|
+
static createConfigProvider() {
|
|
7738
|
+
return {
|
|
7739
|
+
provide: LOGGER_CONFIG_TOKEN,
|
|
7740
|
+
useFactory: (opts) => ({
|
|
7741
|
+
...DEFAULT_LOGGER_CONFIG,
|
|
7742
|
+
...opts,
|
|
7743
|
+
sensitiveFields: opts.sensitiveFields ?? DEFAULT_LOGGER_CONFIG.sensitiveFields,
|
|
7744
|
+
exclude: opts.exclude ?? DEFAULT_LOGGER_CONFIG.exclude
|
|
7745
|
+
}),
|
|
7746
|
+
inject: [MODULE_OPTIONS_TOKEN]
|
|
7747
|
+
};
|
|
7748
|
+
}
|
|
7760
7749
|
static createCoreProviders() {
|
|
7761
7750
|
return [
|
|
7762
7751
|
TraceContextMiddleware,
|
|
7752
|
+
TraceContextService,
|
|
7763
7753
|
FormatterFactory,
|
|
7764
7754
|
ConsoleWriter,
|
|
7765
7755
|
ContextResolver,
|
|
@@ -7798,6 +7788,10 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
7798
7788
|
RequestIdGenerator,
|
|
7799
7789
|
LOGGER_CONFIG_TOKEN
|
|
7800
7790
|
]
|
|
7791
|
+
},
|
|
7792
|
+
{
|
|
7793
|
+
provide: _nestjs_core.APP_INTERCEPTOR,
|
|
7794
|
+
useExisting: HttpLoggerInterceptor
|
|
7801
7795
|
}
|
|
7802
7796
|
];
|
|
7803
7797
|
}
|
|
@@ -7812,17 +7806,8 @@ let LoggerModule = class LoggerModule extends ConfigurableModuleClass {
|
|
|
7812
7806
|
LoggerModule = __decorate([(0, _nestjs_common.Module)({})], LoggerModule);
|
|
7813
7807
|
//#endregion
|
|
7814
7808
|
//#region src/decorators/index.ts
|
|
7815
|
-
/**
|
|
7816
|
-
* Decorator to set logging context for a class or method
|
|
7817
|
-
*/
|
|
7818
7809
|
const LogContext = (context) => (0, _nestjs_common.SetMetadata)(LOGGER_CONTEXT_METADATA, context);
|
|
7819
|
-
/**
|
|
7820
|
-
* Decorator to add metadata to logs
|
|
7821
|
-
*/
|
|
7822
7810
|
const LogMetadata = (metadata) => (0, _nestjs_common.SetMetadata)(LOGGER_METADATA_METADATA, metadata);
|
|
7823
|
-
/**
|
|
7824
|
-
* Decorator to exclude logging for a controller or method
|
|
7825
|
-
*/
|
|
7826
7811
|
const ExcludeLogging = () => (0, _nestjs_common.SetMetadata)(LOGGER_EXCLUDE_METADATA, true);
|
|
7827
7812
|
//#endregion
|
|
7828
7813
|
exports.ExcludeLogging = ExcludeLogging;
|
|
@@ -7847,5 +7832,11 @@ Object.defineProperty(exports, "LoggerService", {
|
|
|
7847
7832
|
return LoggerService;
|
|
7848
7833
|
}
|
|
7849
7834
|
});
|
|
7835
|
+
Object.defineProperty(exports, "TraceContextService", {
|
|
7836
|
+
enumerable: true,
|
|
7837
|
+
get: function() {
|
|
7838
|
+
return TraceContextService;
|
|
7839
|
+
}
|
|
7840
|
+
});
|
|
7850
7841
|
|
|
7851
7842
|
//# sourceMappingURL=index.cjs.map
|