fix: move console.log suppression to index.ts entrypoint

fix: move console.log suppression to index.ts entrypoint
This commit is contained in:
Renato Alcara
2026-02-11 02:17:54 -03:00
committed by GitHub
2 changed files with 37 additions and 36 deletions
+2 -36
View File
@@ -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
+35
View File
@@ -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'