diff --git a/src/Signal/libsignal.ts b/src/Signal/libsignal.ts index b098a2a8..566f445c 100644 --- a/src/Signal/libsignal.ts +++ b/src/Signal/libsignal.ts @@ -22,42 +22,8 @@ import { SenderKeyRecord } from './Group/sender-key-record' import { GroupCipher, GroupSessionBuilder, SenderKeyDistributionMessage } from './Group' import { LIDMappingStore } from './lid-mapping' -// Suppress verbose logs from libsignal native library -// These are raw console.log calls that dump internal state and transient errors -// that are already handled by our retry logic and session recovery system -const _origConsoleLog = console.log -console.log = function(...args: unknown[]) { - if (args.length > 0 && typeof args[0] === 'string') { - const msg = args[0] - - // Check if this log comes from libsignal by examining the call stack - // This prevents suppressing unrelated logs from other modules - const stack = new Error().stack || '' - const isFromLibsignal = stack.includes('libsignal') || stack.includes('session_cipher') - - if (isFromLibsignal) { - // Suppress session lifecycle dumps (cryptographic details on every encrypt/decrypt) - if (msg.startsWith('Closing session')) { - return - } - - // Suppress transient decryption errors that are auto-recovered by retry logic - // These flood logs during normal operation when sessions are being re-established - // Final failures are still logged via our structured logger (see decode-wa-message.ts) - if ( - msg.includes('Session error') || - msg.includes('Bad MAC') || - msg.includes('MessageCounterError') || - msg.includes('Key used already or never filled') || - msg.includes('Failed to decrypt message with any known session') - ) { - return // suppress - our retry system handles these gracefully - } - } - } - - _origConsoleLog.apply(console, args) -} +// NOTE: Console.log suppression has been moved to src/index.ts +// to ensure it runs BEFORE libsignal is loaded // ============================================ // Identity Key Detection Constants diff --git a/src/index.ts b/src/index.ts index de16f702..627985c3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,38 @@ +// ============================================ +// Suppress verbose logs from libsignal BEFORE any imports +// This MUST be at the very top to intercept console.log before libsignal loads +// ============================================ +const _origConsoleLog = console.log +console.log = function(...args: unknown[]) { + if (args.length > 0 && typeof args[0] === 'string') { + const msg = args[0] + + // Check if this log comes from libsignal by examining the call stack + const stack = new Error().stack || '' + const isFromLibsignal = stack.includes('libsignal') || stack.includes('session_cipher') + + if (isFromLibsignal) { + // Suppress session lifecycle dumps + if (msg.startsWith('Closing session')) { + return + } + + // Suppress transient decryption errors auto-recovered by retry logic + if ( + msg.includes('Session error') || + msg.includes('Bad MAC') || + msg.includes('MessageCounterError') || + msg.includes('Key used already or never filled') || + msg.includes('Failed to decrypt message with any known session') + ) { + return + } + } + } + + _origConsoleLog.apply(console, args) +} + import makeWASocket, { makeWASocketAutoVersion } from './Socket/index' export * from '../WAProto/index.js'