import { Timespan } from '@rsdk/common'; import { DEFAULT_LEVEL, LogLevel, LogTimestampFormat } from '@rsdk/logging'; import { ArrayParser, BoolParser, Config, ConfigSection, EnumParser, IntParser, Property, StringParser, StringRecordParser, TimespanParser, UrlParser, } from '../config'; import { ConfigTag } from '../config/config.const'; export enum LogOtelProtocol { httpProtobuf = 'http/protobuf', http = 'http', httpJson = 'http/json', grpc = 'grpc', console = 'console', } @ConfigSection({ tags: [ConfigTag.infrastructure, ConfigTag.logging], }) export class LoggingConfig extends Config { @Property('LOG_LEVEL', new EnumParser(LogLevel), { // TODO: Can pass anything instead of enum value. Need to handle this! defaultValue: DEFAULT_LEVEL, description: 'Log level', }) readonly level!: LogLevel; @Property('LOG_REDACT', new ArrayParser(new StringParser()), { defaultValue: [], description: 'Redaction sensitive data details: https://github.com/pinojs/pino/blob/master/docs/redaction.md', }) readonly redact!: string[]; @Property('LOG_SYNC', new BoolParser(), { defaultValue: false, description: 'Synchronous stdout writes. Applies only to in-process stream mode; worker transports (OTEL/HTTP/forced) are always async. https://github.com/pinojs/pino/blob/master/docs/asynchronous.md', }) readonly sync!: boolean; @Property('LOG_SHUTDOWN_TIMEOUT', new TimespanParser(), { defaultValue: new Timespan(1, 's'), description: 'Max time to flush buffered worker-transport logs on application shutdown. Raise it when using OTEL: its worker may take longer to flush the last batch', }) readonly shutdownTimeout!: Timespan; @Property('LOG_FORCE_TRANSPORT', new BoolParser(), { defaultValue: false, description: 'Use worker-based transport even when only stdout is configured (no OTEL/HTTP). Otherwise stdout-only logging stays in-process', }) readonly forceTransport!: boolean; @Property('LOG_HTTP_ENDPOINT', new UrlParser('http:', 'https:'), { defaultValue: undefined, description: 'URL endpoint for the HTTP logs transport. Transport is enabled when set', }) readonly httpEndpoint?: URL; @Property('LOG_HTTP_HEADERS', new StringRecordParser(), { defaultValue: {}, description: 'JSON object of HTTP headers sent by the HTTP logs transport', }) readonly httpHeaders!: Record; @Property('LOG_HTTP_TIMEOUT', new TimespanParser(), { defaultValue: new Timespan(2500, 'ms'), description: 'Request timeout for the HTTP logs transport', }) readonly httpTimeout!: Timespan; @Property('LOG_HTTP_BATCH_SIZE', new IntParser(), { defaultValue: 100, description: 'Number of logs flushed per batch by the HTTP logs transport', }) readonly httpBatchSize!: number; @Property('LOG_HTTP_BATCH_INTERVAL', new TimespanParser(), { defaultValue: new Timespan(5, 's'), description: 'Max interval between batch flushes of the HTTP logs transport', }) readonly httpBatchInterval!: Timespan; @Property('LOG_HTTP_MAX_RETRIES', new IntParser(), { defaultValue: 2, description: 'Max retry attempts for a failed HTTP logs batch', }) readonly httpMaxRetries!: number; @Property('LOG_HTTP_RETRY_DELAY', new TimespanParser(), { defaultValue: new Timespan(1, 's'), description: 'Base delay between HTTP logs retry attempts', }) readonly httpRetryDelay!: Timespan; @Property('LOG_HTTP_MAX_BUFFER_SIZE', new IntParser(), { defaultValue: 100000, description: 'Max number of buffered logs before dropping (HTTP logs transport)', }) readonly httpMaxBufferSize!: number; @Property('LOG_HTTP_SILENT', new BoolParser(), { defaultValue: false, description: 'Suppress internal warnings/errors of the HTTP logs transport', }) readonly httpSilent!: boolean; @Property('LOG_OTEL_ENABLED', new BoolParser(), { defaultValue: false, description: 'Enable OpenTelemetry logs exporter', }) readonly otelEnabled!: boolean; @Property('LOG_OTEL_ENDPOINT', new UrlParser('http:', 'https:'), { defaultValue: undefined, description: 'OTLP endpoint URL for the OpenTelemetry logs exporter', }) readonly otelEndpoint?: URL; @Property('LOG_OTEL_PROTOCOL', new EnumParser(LogOtelProtocol), { defaultValue: undefined, description: 'OTLP exporter protocol for the OpenTelemetry logs. When unset, resolved from standard OTEL_EXPORTER_OTLP_PROTOCOL env (defaults to http/protobuf)', }) readonly otelProtocol?: LogOtelProtocol; @Property('LOG_OTEL_SERVICE_NAME', new StringParser(), { defaultValue: undefined, description: 'service.name resource attribute for the OpenTelemetry logs. When unset, resolved from standard OTEL env', }) readonly otelServiceName?: string; @Property('LOG_TIMESTAMP_FORMAT', new EnumParser(LogTimestampFormat), { defaultValue: LogTimestampFormat.isoTime, description: 'Log timestamp format', }) readonly logTimestampFormat!: LogTimestampFormat; }