Skip to main content
Effective debugging is crucial when working with the WhatsApp protocol. This guide covers logging configuration, common issues, and troubleshooting strategies.

Logging Configuration

Baileys uses Pino for logging. Configure the logger when creating a socket.

Log Levels

From least to most verbose:
  • fatal - Only fatal errors
  • error - Error messages
  • warn - Warnings
  • info - Informational messages (default)
  • debug - Debug information, unhandled messages
  • trace - Full protocol traces, XML representations

Basic Configuration

Pretty Printing

For human-readable console output:
Install pino-pretty:

Logging to File

From Example/example.ts:7-23:
This logs to both console (pretty) and file (raw JSON).

Custom Logger

Implement the logger interface:

Debug Output

Unhandled Messages

With debug logging enabled, Baileys logs unhandled protocol messages:
These indicate messages you might want to handle with custom callbacks.

XML Trace Output

With trace level, see binary nodes as XML:
From src/Socket/socket.ts:146-148:

Common Issues

Connection Issues

QR Code Timeout

Symptom: QR code expires before scanning

Connection Closed

Symptom: DisconnectReason.connectionClosed
Common causes:
  • Network interruption
  • Server restart
  • WebSocket timeout
Solution: Implement automatic reconnection.

Multi-Device Not Joined

Symptom: DisconnectReason.multideviceMismatch
Solution: Enable multi-device on your WhatsApp mobile app.

Authentication Issues

Logged Out

Symptom: DisconnectReason.loggedOut
Causes:
  • Logged out from phone
  • Session expired
  • Invalid credentials
Solution: Delete auth folder and re-authenticate.

Pre-Key Issues

Symptom: encrypt/get digest returned no digest node
Solution: Pre-keys are automatically re-uploaded. Ensure auth state is persistent.

Message Issues

Message Send Failures

Enable getMessage for retries:
Why it’s needed: Baileys needs to retrieve messages for retry logic and poll vote decryption.

Poll Updates Not Decrypting

Symptom: Poll votes show as encrypted
Solution: Implement getMessage to retrieve the original poll message.

Performance Issues

High Memory Usage

Cause: Storing entire chat history in memory
Solution: Implement database storage with TTL or size limits:

Slow Message Processing

Problem: Blocking event handlers

Debugging 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

Never log sensitive data in production:
  • Pre-keys, session keys
  • Message content
  • User phone numbers
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:
  1. Baileys version: npm list @whiskeysockets/baileys
  2. Node version: node --version
  3. Logs: With debug level enabled
  4. Connection state: During the issue
  5. Reproduction steps: Minimal code to reproduce

Example Debug Log

Next Steps