diff --git a/src/Utils/baileys-logger.ts b/src/Utils/baileys-logger.ts index ccb49b38..b713296c 100644 --- a/src/Utils/baileys-logger.ts +++ b/src/Utils/baileys-logger.ts @@ -331,28 +331,12 @@ export class BaileysLogger implements ILogger { ...(typeof sanitizedObj === 'object' && sanitizedObj !== null ? sanitizedObj : { value: sanitizedObj }), } - // Structured log (using type-safe method call) - switch (level) { - case 'trace': - this.structuredLogger.trace(enrichedObj, msg) - break - case 'debug': - this.structuredLogger.debug(enrichedObj, msg) - break - case 'info': - this.structuredLogger.info(enrichedObj, msg) - break - case 'warn': - this.structuredLogger.warn(enrichedObj, msg) - break - case 'error': - this.structuredLogger.error(enrichedObj, msg) - break - case 'fatal': - this.structuredLogger.fatal(enrichedObj, msg) - break - default: - this.structuredLogger.info(enrichedObj, msg) + // Structured log (skip if level is 'silent') + if (level !== 'silent') { + const logMethod = (this.structuredLogger as unknown as Record void) | undefined>)[level] + if (logMethod) { + logMethod.call(this.structuredLogger, enrichedObj, msg) + } } // Event handler diff --git a/src/Utils/cache-utils.ts b/src/Utils/cache-utils.ts index 5746ddc7..205cd28f 100644 --- a/src/Utils/cache-utils.ts +++ b/src/Utils/cache-utils.ts @@ -505,7 +505,7 @@ const globalCaches: Map> = new Map() export function getGlobalCache(namespace: string, options?: CacheOptions): Cache { if (!globalCaches.has(namespace)) { - globalCaches.set(namespace, new Cache({ ...options, namespace })) + globalCaches.set(namespace, new Cache({ ...options, namespace }) as Cache) } return globalCaches.get(namespace) as Cache } diff --git a/src/Utils/logger-adapter.ts b/src/Utils/logger-adapter.ts index 48ce0227..8d7d3b4b 100644 --- a/src/Utils/logger-adapter.ts +++ b/src/Utils/logger-adapter.ts @@ -120,7 +120,7 @@ export class LoggerAdapter implements ILogger { } if (this.config.levelMapping && level in this.config.levelMapping) { - return this.config.levelMapping[level] || 'info' + return this.config.levelMapping[level] ?? 'info' } return (level as LogLevel) || 'info' @@ -328,8 +328,8 @@ function createLogMethod( if (typeof logger[level] === 'function') { ;(logger[level] as (obj: unknown, msg?: string) => void)(obj, msg) } else { - // Fallback to console - const consoleMethod = (console as unknown as Record void>)[level] + // Fallback to console methods + const consoleMethod = (console as unknown as Record void) | undefined>)[level] if (typeof consoleMethod === 'function') { consoleMethod(obj, msg) } diff --git a/src/Utils/prometheus-metrics.ts b/src/Utils/prometheus-metrics.ts index 7e64e5f4..a7a06730 100644 --- a/src/Utils/prometheus-metrics.ts +++ b/src/Utils/prometheus-metrics.ts @@ -566,7 +566,7 @@ export class Summary implements BaseMetric { * Metrics registry */ export class MetricsRegistry { - private metrics: Map = new Map() + private metricsMap: Map = new Map() private prefix: string private defaultLabels: Labels @@ -580,7 +580,7 @@ export class MetricsRegistry { */ register(metric: T): T { const fullName = this.prefix ? `${this.prefix}_${metric.name}` : metric.name - this.metrics.set(fullName, metric) + this.metricsMap.set(fullName, metric) return metric } @@ -589,7 +589,7 @@ export class MetricsRegistry { */ get(name: string): Counter | Gauge | Histogram | Summary | undefined { const fullName = this.prefix ? `${this.prefix}_${name}` : name - return this.metrics.get(fullName) + return this.metricsMap.get(fullName) } /** @@ -597,14 +597,14 @@ export class MetricsRegistry { */ remove(name: string): boolean { const fullName = this.prefix ? `${this.prefix}_${name}` : name - return this.metrics.delete(fullName) + return this.metricsMap.delete(fullName) } /** * Reset all metrics */ resetAll(): void { - for (const metric of this.metrics.values()) { + for (const metric of this.metricsMap.values()) { metric.reset() } } @@ -615,7 +615,7 @@ export class MetricsRegistry { async getMetricsOutput(): Promise { const lines: string[] = [] - for (const [name, metric] of this.metrics.entries()) { + for (const [name, metric] of this.metricsMap) { lines.push(`# HELP ${name} ${metric.help}`) lines.push(`# TYPE ${name} ${metric.type}`) diff --git a/src/Utils/trace-context.ts b/src/Utils/trace-context.ts index 2f0e0dbe..9d87d501 100644 --- a/src/Utils/trace-context.ts +++ b/src/Utils/trace-context.ts @@ -559,7 +559,9 @@ export function extractTraceHeaders(headers: Record) options.baggage = {} const pairs = baggageHeader.split(',') for (const pair of pairs) { - const [key, value] = pair.split('=') + const parts = pair.split('=') + const key = parts[0] + const value = parts[1] if (key && value) { options.baggage[key.trim()] = decodeURIComponent(value.trim()) }