@globalart/nestjs-logger 1.4.0 → 1.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.d.cts CHANGED
@@ -352,12 +352,12 @@ declare class Observable<T> implements Subscribable<T> {
352
352
  }
353
353
  //#endregion
354
354
  //#region src/types/index.d.ts
355
- type LogLevel = "error" | "warn" | "info" | "debug" | "verbose";
355
+ type LogLevel$1 = "error" | "warn" | "info" | "debug" | "verbose";
356
356
  type LogFormat = "json" | "text" | "pino";
357
- declare const LOG_LEVELS: Record<LogLevel, number>;
357
+ declare const LOG_LEVELS: Record<LogLevel$1, number>;
358
358
  declare const PINO_LEVELS: Record<number, string>;
359
359
  interface LogEntry {
360
- readonly level: LogLevel;
360
+ readonly level: LogLevel$1;
361
361
  readonly message: string;
362
362
  readonly timestamp: Date;
363
363
  readonly context?: string;
@@ -406,7 +406,7 @@ interface ExcludeOption {
406
406
  path: string;
407
407
  }
408
408
  interface LoggerConfiguration {
409
- readonly level: LogLevel;
409
+ readonly level: LogLevel$1;
410
410
  readonly timestamp: boolean;
411
411
  readonly colors: boolean;
412
412
  readonly context?: string;
@@ -421,7 +421,7 @@ interface FormatterOptions {
421
421
  readonly context?: string;
422
422
  }
423
423
  interface LoggerOptions {
424
- level?: LogLevel;
424
+ level?: LogLevel$1;
425
425
  timestamp?: boolean;
426
426
  colors?: boolean;
427
427
  context?: string;
@@ -462,8 +462,9 @@ interface ILogFormatter {
462
462
  format(entry: LogEntry): string;
463
463
  formatHttpRequest(entry: HttpRequestLogEntry): string;
464
464
  }
465
+ type LogLevel = "error" | "warn" | "info" | "debug" | "verbose";
465
466
  interface ILogWriter {
466
- write(formattedLog: string): void;
467
+ write(formattedLog: string, level?: LogLevel): void;
467
468
  }
468
469
  interface IContextResolver {
469
470
  resolve(): string;
@@ -556,7 +557,7 @@ declare class ContextResolver implements IContextResolver {
556
557
  //#endregion
557
558
  //#region src/writers/console-writer.d.ts
558
559
  declare class ConsoleWriter implements ILogWriter {
559
- write(formattedLog: string): void;
560
+ write(formattedLog: string, level?: LogLevel): void;
560
561
  }
561
562
  //#endregion
562
563
  //#region src/factories/formatter.factory.d.ts
@@ -594,5 +595,5 @@ declare const LogMetadata: (metadata: Record<string, unknown>) => _nestjs_common
594
595
  */
595
596
  declare const ExcludeLogging: () => _nestjs_common0.CustomDecorator<typeof LOGGER_EXCLUDE_METADATA>;
596
597
  //#endregion
597
- export { DynamicContextLoggerFactory, ExcludeLogging, ExcludeOption, FormatterOptions, HttpLoggerInterceptor, HttpRequest, HttpRequestLogEntry, HttpResponse, IContextResolver, IDataSanitizer, ILogFormatter, ILogWriter, ILogger, IRequestIdGenerator, InjectLogger, LOG_LEVELS, LogContext, LogEntry, LogFormat, LogLevel, LogMetadata, LogOptions, LoggerConfiguration, LoggerMetadata, LoggerModule, type LoggerModuleAsyncOptions, type LoggerModuleOptions, LoggerOptions, LoggerService, LoggerTransport, PINO_LEVELS, PinoOptions };
598
+ export { DynamicContextLoggerFactory, ExcludeLogging, ExcludeOption, FormatterOptions, HttpLoggerInterceptor, HttpRequest, HttpRequestLogEntry, HttpResponse, IContextResolver, IDataSanitizer, ILogFormatter, ILogWriter, ILogger, IRequestIdGenerator, InjectLogger, LOG_LEVELS, LogContext, LogEntry, LogFormat, LogMetadata, LogOptions, LoggerConfiguration, LoggerMetadata, LoggerModule, type LoggerModuleAsyncOptions, type LoggerModuleOptions, LoggerOptions, LoggerService, LoggerTransport, PINO_LEVELS, PinoOptions };
598
599
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -352,12 +352,12 @@ declare class Observable<T> implements Subscribable<T> {
352
352
  }
353
353
  //#endregion
354
354
  //#region src/types/index.d.ts
355
- type LogLevel = "error" | "warn" | "info" | "debug" | "verbose";
355
+ type LogLevel$1 = "error" | "warn" | "info" | "debug" | "verbose";
356
356
  type LogFormat = "json" | "text" | "pino";
357
- declare const LOG_LEVELS: Record<LogLevel, number>;
357
+ declare const LOG_LEVELS: Record<LogLevel$1, number>;
358
358
  declare const PINO_LEVELS: Record<number, string>;
359
359
  interface LogEntry {
360
- readonly level: LogLevel;
360
+ readonly level: LogLevel$1;
361
361
  readonly message: string;
362
362
  readonly timestamp: Date;
363
363
  readonly context?: string;
@@ -406,7 +406,7 @@ interface ExcludeOption {
406
406
  path: string;
407
407
  }
408
408
  interface LoggerConfiguration {
409
- readonly level: LogLevel;
409
+ readonly level: LogLevel$1;
410
410
  readonly timestamp: boolean;
411
411
  readonly colors: boolean;
412
412
  readonly context?: string;
@@ -421,7 +421,7 @@ interface FormatterOptions {
421
421
  readonly context?: string;
422
422
  }
423
423
  interface LoggerOptions {
424
- level?: LogLevel;
424
+ level?: LogLevel$1;
425
425
  timestamp?: boolean;
426
426
  colors?: boolean;
427
427
  context?: string;
@@ -462,8 +462,9 @@ interface ILogFormatter {
462
462
  format(entry: LogEntry): string;
463
463
  formatHttpRequest(entry: HttpRequestLogEntry): string;
464
464
  }
465
+ type LogLevel = "error" | "warn" | "info" | "debug" | "verbose";
465
466
  interface ILogWriter {
466
- write(formattedLog: string): void;
467
+ write(formattedLog: string, level?: LogLevel): void;
467
468
  }
468
469
  interface IContextResolver {
469
470
  resolve(): string;
@@ -556,7 +557,7 @@ declare class ContextResolver implements IContextResolver {
556
557
  //#endregion
557
558
  //#region src/writers/console-writer.d.ts
558
559
  declare class ConsoleWriter implements ILogWriter {
559
- write(formattedLog: string): void;
560
+ write(formattedLog: string, level?: LogLevel): void;
560
561
  }
561
562
  //#endregion
562
563
  //#region src/factories/formatter.factory.d.ts
@@ -594,5 +595,5 @@ declare const LogMetadata: (metadata: Record<string, unknown>) => _nestjs_common
594
595
  */
595
596
  declare const ExcludeLogging: () => _nestjs_common0.CustomDecorator<typeof LOGGER_EXCLUDE_METADATA>;
596
597
  //#endregion
597
- export { DynamicContextLoggerFactory, ExcludeLogging, ExcludeOption, FormatterOptions, HttpLoggerInterceptor, HttpRequest, HttpRequestLogEntry, HttpResponse, IContextResolver, IDataSanitizer, ILogFormatter, ILogWriter, ILogger, IRequestIdGenerator, InjectLogger, LOG_LEVELS, LogContext, LogEntry, LogFormat, LogLevel, LogMetadata, LogOptions, LoggerConfiguration, LoggerMetadata, LoggerModule, type LoggerModuleAsyncOptions, type LoggerModuleOptions, LoggerOptions, LoggerService, LoggerTransport, PINO_LEVELS, PinoOptions };
598
+ export { DynamicContextLoggerFactory, ExcludeLogging, ExcludeOption, FormatterOptions, HttpLoggerInterceptor, HttpRequest, HttpRequestLogEntry, HttpResponse, IContextResolver, IDataSanitizer, ILogFormatter, ILogWriter, ILogger, IRequestIdGenerator, InjectLogger, LOG_LEVELS, LogContext, LogEntry, LogFormat, LogMetadata, LogOptions, LoggerConfiguration, LoggerMetadata, LoggerModule, type LoggerModuleAsyncOptions, type LoggerModuleOptions, LoggerOptions, LoggerService, LoggerTransport, PINO_LEVELS, PinoOptions };
598
599
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -7303,6 +7303,14 @@ function __decorate(decorators, target, key, desc) {
7303
7303
 
7304
7304
  //#endregion
7305
7305
  //#region src/core/logger.service.ts
7306
+ const PINO_LEVEL_TO_LOG_LEVEL = {
7307
+ 60: "error",
7308
+ 50: "error",
7309
+ 40: "warn",
7310
+ 30: "info",
7311
+ 20: "debug",
7312
+ 10: "verbose"
7313
+ };
7306
7314
  let LoggerService = class LoggerService {
7307
7315
  context;
7308
7316
  constructor(config, formatter, writer, contextResolver) {
@@ -7332,7 +7340,8 @@ let LoggerService = class LoggerService {
7332
7340
  logHttpRequest(entry) {
7333
7341
  const enriched = this.enrichWithTraceIds(entry);
7334
7342
  const formatted = this.formatter.formatHttpRequest(enriched);
7335
- this.writer.write(formatted);
7343
+ const level = PINO_LEVEL_TO_LOG_LEVEL[entry.level] ?? "info";
7344
+ this.writer.write(formatted, level);
7336
7345
  }
7337
7346
  writeLog(level, options) {
7338
7347
  const { traceId, spanId } = this.resolveTraceIds(options);
@@ -7347,7 +7356,7 @@ let LoggerService = class LoggerService {
7347
7356
  spanId
7348
7357
  };
7349
7358
  const formatted = this.formatter.format(entry);
7350
- this.writer.write(formatted);
7359
+ this.writer.write(formatted, level);
7351
7360
  }
7352
7361
  resolveTraceIds(options) {
7353
7362
  if (options.traceId && options.spanId) return {
@@ -7426,12 +7435,6 @@ let HttpLoggerInterceptor = class HttpLoggerInterceptor {
7426
7435
  if (this.config.format === "pino") {
7427
7436
  const entry = this.createHttpLogEntry(request, response, requestId, startTime, 50, errorMessage || "request failed");
7428
7437
  this.logger.logHttpRequest(entry);
7429
- const baseEntry = this.createLogEntry(request, response, requestId, startTime);
7430
- this.logger.error({
7431
- ...baseEntry,
7432
- message: errorMessage || baseEntry.message,
7433
- trace: errorTrace
7434
- });
7435
7438
  } else {
7436
7439
  const baseEntry = this.createLogEntry(request, response, requestId, startTime);
7437
7440
  this.logger.error({
@@ -7860,9 +7863,16 @@ ContextResolver = __decorate([Injectable()], ContextResolver);
7860
7863
 
7861
7864
  //#endregion
7862
7865
  //#region src/writers/console-writer.ts
7866
+ const CONSOLE_BY_LEVEL = {
7867
+ error: (msg) => console.error(msg),
7868
+ warn: (msg) => console.warn(msg),
7869
+ info: (msg) => console.log(msg),
7870
+ debug: (msg) => console.debug(msg),
7871
+ verbose: (msg) => console.log(msg)
7872
+ };
7863
7873
  let ConsoleWriter = class ConsoleWriter {
7864
- write(formattedLog) {
7865
- console.log(formattedLog);
7874
+ write(formattedLog, level) {
7875
+ (level ? CONSOLE_BY_LEVEL[level] : console.log)(formattedLog);
7866
7876
  }
7867
7877
  };
7868
7878
  ConsoleWriter = __decorate([Injectable()], ConsoleWriter);