@bymax-one/nest-logger 1.4.23 → 1.4.24

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.
@@ -618,7 +618,11 @@ interface BymaxLoggerModuleOptions {
618
618
  http?: HttpOptions;
619
619
  /** OpenTelemetry integration tuning. */
620
620
  otel?: OtelOptions;
621
- /** Maximum size in bytes per log entry: an integer from 1 to 2147483647. Default: 65536. */
621
+ /**
622
+ * Maximum size in UTF-8 bytes of each serialized field (`err` and any custom serializer), over
623
+ * which the value becomes a truncation envelope, and of each derived `exception.*` and
624
+ * `error.type` field, which is cut to it: an integer from 1 to 2147483647. Default: 65536.
625
+ */
622
626
  maxEntrySizeBytes?: number;
623
627
  /**
624
628
  * The most characters a string of a log record is written with. A longer string is cut to this
@@ -632,7 +636,7 @@ interface BymaxLoggerModuleOptions {
632
636
  * under a key that has a serializer (`err` and the keys of `serializers`; see
633
637
  * `maxEntrySizeBytes`), so the stack of an error logged under `err` is never cut by it. The event
634
638
  * name and the `exception.*` and `error.type` fields the library writes are added after the cut,
635
- * so the limit does not apply to them, and a key of your own with one of those names is cut like
639
+ * so the limit does not apply to them (`maxEntrySizeBytes` cuts the exception fields), and a key of your own with one of those names is cut like
636
640
  * any other. The names left whole are matched on the root key, so a key of your own named like a
637
641
  * serializer key is left whole too. An `Error` placed in the metadata under any other key is
638
642
  * data of the record when the cut runs, and its message and stack are cut like any other string.
@@ -873,6 +877,7 @@ declare const RESERVED_LOG_KEYS: Readonly<{
873
877
  readonly METHOD_SLOW_EXECUTION: "METHOD_SLOW_EXECUTION";
874
878
  readonly LOGGER_DESTINATION_INIT_FAILED: "LOGGER_DESTINATION_INIT_FAILED";
875
879
  readonly LOGGER_DESTINATION_WRITE_FAILED: "LOGGER_DESTINATION_WRITE_FAILED";
880
+ readonly LOGGER_DESTINATION_SHUTDOWN_FAILED: "LOGGER_DESTINATION_SHUTDOWN_FAILED";
876
881
  readonly LOGGER_ENTRY_TRUNCATED: "LOGGER_ENTRY_TRUNCATED";
877
882
  readonly LOGGER_REDACTION_FAILED: "LOGGER_REDACTION_FAILED";
878
883
  readonly LOGGER_OTEL_API_BROKEN: "LOGGER_OTEL_API_BROKEN";
@@ -1073,12 +1078,33 @@ declare class PinoLoggerService implements LoggerService, OnApplicationShutdown
1073
1078
  private emitStructured;
1074
1079
  /** Emit a NestJS-style variadic log, dispatching by level without computed indexing. */
1075
1080
  private nestStyleMessage;
1081
+ /**
1082
+ * Censor a text as the `message` of an entry is: under the name `message`, by the rules of
1083
+ * `redactPaths` and `redactCensor`, and neither cut nor counted. The lines the library writes to
1084
+ * `stderr` about a failure use it for the message of the error they carry.
1085
+ *
1086
+ * @internal Used by `PinoUnexpectedErrorSink`. NOT part of the supported API.
1087
+ * @param text - The text to censor.
1088
+ * @returns The text, or what hides it, and an empty text when the censor itself fails.
1089
+ */
1090
+ censorMessageText(text: string): string;
1091
+ /**
1092
+ * The entry text of an `Error`: its `message`, read without letting a hostile getter escape, then
1093
+ * censored under the name `message`, as the field `err.message` it is a copy of. It is not cut at
1094
+ * `maxStringLength`: the option does not apply to the log message, which is capped at 16384.
1095
+ *
1096
+ * @param error - The error being logged.
1097
+ * @returns The text of the entry.
1098
+ */
1099
+ private errorText;
1076
1100
  /**
1077
1101
  * The entry text of an object message, censored under the names of the field it came from and cut
1078
1102
  * like that field: the text is a copy of it, and a copy made outside the pipeline would carry a
1079
1103
  * value the pipeline censors or cuts in the field itself.
1080
1104
  *
1081
1105
  * @param text - The text and the member it came from.
1106
+ * @param cut - Present when the text is cut at `maxStringLength`; says whether the entry is
1107
+ * written, so that a cut of it is counted.
1082
1108
  * @returns The censored text, or an empty one when the redactor cannot be applied.
1083
1109
  */
1084
1110
  private censorText;
@@ -2019,6 +2045,49 @@ declare const LogContext: (name: string) => CustomDecorator<string>;
2019
2045
  */
2020
2046
  declare function LogPerformance(thresholdMs?: number): MethodDecorator;
2021
2047
 
2048
+ /**
2049
+ * What the logger counts about itself, for a host that wants to publish it as metrics or as a
2050
+ * readiness check. Provided under `LOGGER_OBSERVABILITY_TOKEN`; the `/observability` subpath builds
2051
+ * the Prometheus counters and the health indicator on it.
2052
+ */
2053
+ /** Why a field of an entry was cut or replaced: a closed set, safe to use as a metric label. */
2054
+ type TruncationReason = 'max_entry_size' | 'max_string_length';
2055
+ /** The state of the fan-out to the destinations, read without sending anything. */
2056
+ interface DeliveryState {
2057
+ /** How many destinations have finished their `onInit`, healthy or failed. */
2058
+ readonly destinations: number;
2059
+ /** How many of them failed their `onInit`. */
2060
+ readonly failedInit: number;
2061
+ /** How many have refused a write or had an entry dropped since startup. */
2062
+ readonly writeFailing: number;
2063
+ /** Whether at least one destination is healthy, so an entry can still be delivered. */
2064
+ readonly hasHealthySink: boolean;
2065
+ }
2066
+ /** The counters and the delivery state of one logger, since the module started. */
2067
+ interface ILoggerObservability {
2068
+ /**
2069
+ * How many fields were cut or replaced for a reason: with `max_entry_size` a serializer output
2070
+ * over `maxEntrySizeBytes` (or one that could not be measured) or a derived exception field cut
2071
+ * to it, with `max_string_length` a string cut at `maxStringLength`. One field is one count.
2072
+ *
2073
+ * @param reason - The reason.
2074
+ * @returns The count since startup.
2075
+ */
2076
+ truncatedTotal(reason: TruncationReason): number;
2077
+ /**
2078
+ * How many writes the destinations refused (they threw or rejected), over all destinations.
2079
+ *
2080
+ * @returns The count since startup.
2081
+ */
2082
+ destinationErrorTotal(): number;
2083
+ /**
2084
+ * The state of the fan-out.
2085
+ *
2086
+ * @returns A snapshot; nothing is sent to a destination to produce it.
2087
+ */
2088
+ deliveryState(): DeliveryState;
2089
+ }
2090
+
2022
2091
  /**
2023
2092
  * Dependency-injection tokens used by `BymaxLoggerModule`.
2024
2093
  *
@@ -2044,6 +2113,15 @@ declare const LOGGER_DESTINATIONS_TOKEN: unique symbol;
2044
2113
  * factory's hook cannot see them.
2045
2114
  */
2046
2115
  declare const LOGGER_REDACTOR_TOKEN: unique symbol;
2116
+ /**
2117
+ * Injection token for the {@link ILoggerObservability} view of the logger: the counters and the
2118
+ * delivery state that the `/observability` subpath publishes.
2119
+ *
2120
+ * Registered in the global symbol registry (`Symbol.for`) and not as a unique symbol: the package
2121
+ * ships an ES module and a CommonJS build, and a host that loads the main entry through one and the
2122
+ * subpath through the other would otherwise hold two different tokens for the same provider.
2123
+ */
2124
+ declare const LOGGER_OBSERVABILITY_TOKEN: unique symbol;
2047
2125
  /** Injection token for the per-request AsyncLocalStorage-backed log context. */
2048
2126
  declare const LOG_CONTEXT_TOKEN: unique symbol;
2049
2127
 
@@ -2197,5 +2275,5 @@ interface LogEntry {
2197
2275
  */
2198
2276
  declare const LOG_KEYS_CONVENTION_REGEX: RegExp;
2199
2277
 
2200
- export { BymaxLoggerModule, DEFAULT_REDACT_PATHS, DefaultStdoutDestination, HttpAccessLogMiddleware, HttpExceptionFilter, HttpLoggingInterceptor, InjectLogger, LOGGER_DESTINATIONS_TOKEN, LOGGER_OPTIONS_TOKEN, LOGGER_PINO_INSTANCE_TOKEN, LOGGER_REDACTOR_TOKEN, LOG_CONTEXT_METADATA_KEY, LOG_CONTEXT_TOKEN, LOG_KEYS_CONVENTION_REGEX, LogContext, LogContextService, LogPerformance, PINO_LEVEL_NAMES, PINO_LEVEL_NUMBERS, PinoLoggerService, PinoUnexpectedErrorSink, PrettyDevDestination, REDACT_COMMON_FIELDS, RESERVED_LOG_KEYS, RESERVED_LOG_KEYS_NOT_EMITTED, RequestIdMiddleware, applyAccessLog, applyRequestIdMiddleware, isValidTraceId };
2201
- export type { BymaxLoggerModuleAsyncOptions, BymaxLoggerModuleOptions, BymaxLoggerModuleOptionsFactory, EmittedDeploymentResource, EmittedServiceResource, ErrorOwnFieldsMode, HttpOptions, ILogDestination, IUnexpectedErrorSink, IncomingHeaders, LogContext$1 as LogContextBag, LogEntry, LogLevel, LoggableRequest, LoggableResponse, NextHandler, OtelOptions, PrettyViewOptions, ReservedLogKey, ResolvedBymaxLoggerModuleOptions, ResolvedServiceMetadata, ServiceMetadata, UnexpectedErrorReport };
2278
+ export { BymaxLoggerModule, DEFAULT_REDACT_PATHS, DefaultStdoutDestination, HttpAccessLogMiddleware, HttpExceptionFilter, HttpLoggingInterceptor, InjectLogger, LOGGER_DESTINATIONS_TOKEN, LOGGER_OBSERVABILITY_TOKEN, LOGGER_OPTIONS_TOKEN, LOGGER_PINO_INSTANCE_TOKEN, LOGGER_REDACTOR_TOKEN, LOG_CONTEXT_METADATA_KEY, LOG_CONTEXT_TOKEN, LOG_KEYS_CONVENTION_REGEX, LogContext, LogContextService, LogPerformance, PINO_LEVEL_NAMES, PINO_LEVEL_NUMBERS, PinoLoggerService, PinoUnexpectedErrorSink, PrettyDevDestination, REDACT_COMMON_FIELDS, RESERVED_LOG_KEYS, RESERVED_LOG_KEYS_NOT_EMITTED, RequestIdMiddleware, applyAccessLog, applyRequestIdMiddleware, isValidTraceId };
2279
+ export type { BymaxLoggerModuleAsyncOptions, BymaxLoggerModuleOptions, BymaxLoggerModuleOptionsFactory, DeliveryState, EmittedDeploymentResource, EmittedServiceResource, ErrorOwnFieldsMode, HttpOptions, ILogDestination, ILoggerObservability, IUnexpectedErrorSink, IncomingHeaders, LogContext$1 as LogContextBag, LogEntry, LogLevel, LoggableRequest, LoggableResponse, NextHandler, OtelOptions, PrettyViewOptions, ReservedLogKey, ResolvedBymaxLoggerModuleOptions, ResolvedServiceMetadata, ServiceMetadata, TruncationReason, UnexpectedErrorReport };
@@ -618,7 +618,11 @@ interface BymaxLoggerModuleOptions {
618
618
  http?: HttpOptions;
619
619
  /** OpenTelemetry integration tuning. */
620
620
  otel?: OtelOptions;
621
- /** Maximum size in bytes per log entry: an integer from 1 to 2147483647. Default: 65536. */
621
+ /**
622
+ * Maximum size in UTF-8 bytes of each serialized field (`err` and any custom serializer), over
623
+ * which the value becomes a truncation envelope, and of each derived `exception.*` and
624
+ * `error.type` field, which is cut to it: an integer from 1 to 2147483647. Default: 65536.
625
+ */
622
626
  maxEntrySizeBytes?: number;
623
627
  /**
624
628
  * The most characters a string of a log record is written with. A longer string is cut to this
@@ -632,7 +636,7 @@ interface BymaxLoggerModuleOptions {
632
636
  * under a key that has a serializer (`err` and the keys of `serializers`; see
633
637
  * `maxEntrySizeBytes`), so the stack of an error logged under `err` is never cut by it. The event
634
638
  * name and the `exception.*` and `error.type` fields the library writes are added after the cut,
635
- * so the limit does not apply to them, and a key of your own with one of those names is cut like
639
+ * so the limit does not apply to them (`maxEntrySizeBytes` cuts the exception fields), and a key of your own with one of those names is cut like
636
640
  * any other. The names left whole are matched on the root key, so a key of your own named like a
637
641
  * serializer key is left whole too. An `Error` placed in the metadata under any other key is
638
642
  * data of the record when the cut runs, and its message and stack are cut like any other string.
@@ -873,6 +877,7 @@ declare const RESERVED_LOG_KEYS: Readonly<{
873
877
  readonly METHOD_SLOW_EXECUTION: "METHOD_SLOW_EXECUTION";
874
878
  readonly LOGGER_DESTINATION_INIT_FAILED: "LOGGER_DESTINATION_INIT_FAILED";
875
879
  readonly LOGGER_DESTINATION_WRITE_FAILED: "LOGGER_DESTINATION_WRITE_FAILED";
880
+ readonly LOGGER_DESTINATION_SHUTDOWN_FAILED: "LOGGER_DESTINATION_SHUTDOWN_FAILED";
876
881
  readonly LOGGER_ENTRY_TRUNCATED: "LOGGER_ENTRY_TRUNCATED";
877
882
  readonly LOGGER_REDACTION_FAILED: "LOGGER_REDACTION_FAILED";
878
883
  readonly LOGGER_OTEL_API_BROKEN: "LOGGER_OTEL_API_BROKEN";
@@ -1073,12 +1078,33 @@ declare class PinoLoggerService implements LoggerService, OnApplicationShutdown
1073
1078
  private emitStructured;
1074
1079
  /** Emit a NestJS-style variadic log, dispatching by level without computed indexing. */
1075
1080
  private nestStyleMessage;
1081
+ /**
1082
+ * Censor a text as the `message` of an entry is: under the name `message`, by the rules of
1083
+ * `redactPaths` and `redactCensor`, and neither cut nor counted. The lines the library writes to
1084
+ * `stderr` about a failure use it for the message of the error they carry.
1085
+ *
1086
+ * @internal Used by `PinoUnexpectedErrorSink`. NOT part of the supported API.
1087
+ * @param text - The text to censor.
1088
+ * @returns The text, or what hides it, and an empty text when the censor itself fails.
1089
+ */
1090
+ censorMessageText(text: string): string;
1091
+ /**
1092
+ * The entry text of an `Error`: its `message`, read without letting a hostile getter escape, then
1093
+ * censored under the name `message`, as the field `err.message` it is a copy of. It is not cut at
1094
+ * `maxStringLength`: the option does not apply to the log message, which is capped at 16384.
1095
+ *
1096
+ * @param error - The error being logged.
1097
+ * @returns The text of the entry.
1098
+ */
1099
+ private errorText;
1076
1100
  /**
1077
1101
  * The entry text of an object message, censored under the names of the field it came from and cut
1078
1102
  * like that field: the text is a copy of it, and a copy made outside the pipeline would carry a
1079
1103
  * value the pipeline censors or cuts in the field itself.
1080
1104
  *
1081
1105
  * @param text - The text and the member it came from.
1106
+ * @param cut - Present when the text is cut at `maxStringLength`; says whether the entry is
1107
+ * written, so that a cut of it is counted.
1082
1108
  * @returns The censored text, or an empty one when the redactor cannot be applied.
1083
1109
  */
1084
1110
  private censorText;
@@ -2019,6 +2045,49 @@ declare const LogContext: (name: string) => CustomDecorator<string>;
2019
2045
  */
2020
2046
  declare function LogPerformance(thresholdMs?: number): MethodDecorator;
2021
2047
 
2048
+ /**
2049
+ * What the logger counts about itself, for a host that wants to publish it as metrics or as a
2050
+ * readiness check. Provided under `LOGGER_OBSERVABILITY_TOKEN`; the `/observability` subpath builds
2051
+ * the Prometheus counters and the health indicator on it.
2052
+ */
2053
+ /** Why a field of an entry was cut or replaced: a closed set, safe to use as a metric label. */
2054
+ type TruncationReason = 'max_entry_size' | 'max_string_length';
2055
+ /** The state of the fan-out to the destinations, read without sending anything. */
2056
+ interface DeliveryState {
2057
+ /** How many destinations have finished their `onInit`, healthy or failed. */
2058
+ readonly destinations: number;
2059
+ /** How many of them failed their `onInit`. */
2060
+ readonly failedInit: number;
2061
+ /** How many have refused a write or had an entry dropped since startup. */
2062
+ readonly writeFailing: number;
2063
+ /** Whether at least one destination is healthy, so an entry can still be delivered. */
2064
+ readonly hasHealthySink: boolean;
2065
+ }
2066
+ /** The counters and the delivery state of one logger, since the module started. */
2067
+ interface ILoggerObservability {
2068
+ /**
2069
+ * How many fields were cut or replaced for a reason: with `max_entry_size` a serializer output
2070
+ * over `maxEntrySizeBytes` (or one that could not be measured) or a derived exception field cut
2071
+ * to it, with `max_string_length` a string cut at `maxStringLength`. One field is one count.
2072
+ *
2073
+ * @param reason - The reason.
2074
+ * @returns The count since startup.
2075
+ */
2076
+ truncatedTotal(reason: TruncationReason): number;
2077
+ /**
2078
+ * How many writes the destinations refused (they threw or rejected), over all destinations.
2079
+ *
2080
+ * @returns The count since startup.
2081
+ */
2082
+ destinationErrorTotal(): number;
2083
+ /**
2084
+ * The state of the fan-out.
2085
+ *
2086
+ * @returns A snapshot; nothing is sent to a destination to produce it.
2087
+ */
2088
+ deliveryState(): DeliveryState;
2089
+ }
2090
+
2022
2091
  /**
2023
2092
  * Dependency-injection tokens used by `BymaxLoggerModule`.
2024
2093
  *
@@ -2044,6 +2113,15 @@ declare const LOGGER_DESTINATIONS_TOKEN: unique symbol;
2044
2113
  * factory's hook cannot see them.
2045
2114
  */
2046
2115
  declare const LOGGER_REDACTOR_TOKEN: unique symbol;
2116
+ /**
2117
+ * Injection token for the {@link ILoggerObservability} view of the logger: the counters and the
2118
+ * delivery state that the `/observability` subpath publishes.
2119
+ *
2120
+ * Registered in the global symbol registry (`Symbol.for`) and not as a unique symbol: the package
2121
+ * ships an ES module and a CommonJS build, and a host that loads the main entry through one and the
2122
+ * subpath through the other would otherwise hold two different tokens for the same provider.
2123
+ */
2124
+ declare const LOGGER_OBSERVABILITY_TOKEN: unique symbol;
2047
2125
  /** Injection token for the per-request AsyncLocalStorage-backed log context. */
2048
2126
  declare const LOG_CONTEXT_TOKEN: unique symbol;
2049
2127
 
@@ -2197,5 +2275,5 @@ interface LogEntry {
2197
2275
  */
2198
2276
  declare const LOG_KEYS_CONVENTION_REGEX: RegExp;
2199
2277
 
2200
- export { BymaxLoggerModule, DEFAULT_REDACT_PATHS, DefaultStdoutDestination, HttpAccessLogMiddleware, HttpExceptionFilter, HttpLoggingInterceptor, InjectLogger, LOGGER_DESTINATIONS_TOKEN, LOGGER_OPTIONS_TOKEN, LOGGER_PINO_INSTANCE_TOKEN, LOGGER_REDACTOR_TOKEN, LOG_CONTEXT_METADATA_KEY, LOG_CONTEXT_TOKEN, LOG_KEYS_CONVENTION_REGEX, LogContext, LogContextService, LogPerformance, PINO_LEVEL_NAMES, PINO_LEVEL_NUMBERS, PinoLoggerService, PinoUnexpectedErrorSink, PrettyDevDestination, REDACT_COMMON_FIELDS, RESERVED_LOG_KEYS, RESERVED_LOG_KEYS_NOT_EMITTED, RequestIdMiddleware, applyAccessLog, applyRequestIdMiddleware, isValidTraceId };
2201
- export type { BymaxLoggerModuleAsyncOptions, BymaxLoggerModuleOptions, BymaxLoggerModuleOptionsFactory, EmittedDeploymentResource, EmittedServiceResource, ErrorOwnFieldsMode, HttpOptions, ILogDestination, IUnexpectedErrorSink, IncomingHeaders, LogContext$1 as LogContextBag, LogEntry, LogLevel, LoggableRequest, LoggableResponse, NextHandler, OtelOptions, PrettyViewOptions, ReservedLogKey, ResolvedBymaxLoggerModuleOptions, ResolvedServiceMetadata, ServiceMetadata, UnexpectedErrorReport };
2278
+ export { BymaxLoggerModule, DEFAULT_REDACT_PATHS, DefaultStdoutDestination, HttpAccessLogMiddleware, HttpExceptionFilter, HttpLoggingInterceptor, InjectLogger, LOGGER_DESTINATIONS_TOKEN, LOGGER_OBSERVABILITY_TOKEN, LOGGER_OPTIONS_TOKEN, LOGGER_PINO_INSTANCE_TOKEN, LOGGER_REDACTOR_TOKEN, LOG_CONTEXT_METADATA_KEY, LOG_CONTEXT_TOKEN, LOG_KEYS_CONVENTION_REGEX, LogContext, LogContextService, LogPerformance, PINO_LEVEL_NAMES, PINO_LEVEL_NUMBERS, PinoLoggerService, PinoUnexpectedErrorSink, PrettyDevDestination, REDACT_COMMON_FIELDS, RESERVED_LOG_KEYS, RESERVED_LOG_KEYS_NOT_EMITTED, RequestIdMiddleware, applyAccessLog, applyRequestIdMiddleware, isValidTraceId };
2279
+ export type { BymaxLoggerModuleAsyncOptions, BymaxLoggerModuleOptions, BymaxLoggerModuleOptionsFactory, DeliveryState, EmittedDeploymentResource, EmittedServiceResource, ErrorOwnFieldsMode, HttpOptions, ILogDestination, ILoggerObservability, IUnexpectedErrorSink, IncomingHeaders, LogContext$1 as LogContextBag, LogEntry, LogLevel, LoggableRequest, LoggableResponse, NextHandler, OtelOptions, PrettyViewOptions, ReservedLogKey, ResolvedBymaxLoggerModuleOptions, ResolvedServiceMetadata, ServiceMetadata, TruncationReason, UnexpectedErrorReport };