Logging Configuration
Baileys uses Pino for logging. Configure the logger when creating a socket.Log Levels
From least to most verbose:fatal- Only fatal errorserror- Error messageswarn- Warningsinfo- Informational messages (default)debug- Debug information, unhandled messagestrace- Full protocol traces, XML representations
Basic Configuration
Pretty Printing
For human-readable console output:Logging to File
FromExample/example.ts:7-23:
Custom Logger
Implement the logger interface:Debug Output
Unhandled Messages
With debug logging enabled, Baileys logs unhandled protocol messages:XML Trace Output
Withtrace level, see binary nodes as XML:
src/Socket/socket.ts:146-148:
Common Issues
Connection Issues
QR Code Timeout
Symptom: QR code expires before scanningConnection Closed
Symptom:DisconnectReason.connectionClosed
- Network interruption
- Server restart
- WebSocket timeout
Multi-Device Not Joined
Symptom:DisconnectReason.multideviceMismatch
Authentication Issues
Logged Out
Symptom:DisconnectReason.loggedOut
- Logged out from phone
- Session expired
- Invalid credentials
Pre-Key Issues
Symptom:encrypt/get digest returned no digest node
Message Issues
Message Send Failures
Enable getMessage for retries:Poll Updates Not Decrypting
Symptom: Poll votes show as encryptedgetMessage to retrieve the original poll message.
Performance Issues
High Memory Usage
Cause: Storing entire chat history in memorySlow Message Processing
Problem: Blocking event handlersDebugging Techniques
Inspect Binary Nodes
Trace WebSocket Events
Monitor Connection State
Debug Auth State
Error Handling
Global Error Handler
Catch Unhandled Rejections
Diagnostic Tools
Check Pre-Keys on Server
Verify Device Registration
Test Message Send
Production Recommendations
Monitor these metrics:
- Connection uptime
- Message send success rate
- Pre-key count on server
- Memory usage
- Event processing latency
Useful Commands
Clear Auth State
View Logs in Real-Time
Search Logs
Getting Help
Gather Debug Info
When reporting issues, include:- Baileys version:
npm list @whiskeysockets/baileys - Node version:
node --version - Logs: With debug level enabled
- Connection state: During the issue
- Reproduction steps: Minimal code to reproduce
Example Debug Log
Next Steps
- Custom Functionality - Building custom handlers
- WebSocket Events - Event callback patterns
- Protocol Details - Understanding the protocol