Skip to main content

Overview

Pion WebRTC provides a customizable logging interface that allows you to integrate with your existing logging infrastructure. You can control log levels, format output, and direct logs to different destinations for each WebRTC subsystem (ICE, DTLS, SCTP, etc.).
Custom logging is particularly useful for debugging connection issues, monitoring production systems, or integrating with centralized logging platforms.

Logging Interface

Pion uses the logging.LeveledLogger interface from github.com/pion/logging:
logger-interface.go

LoggerFactory Interface

The LoggerFactory creates loggers for different subsystems:
factory-interface.go
Subsystems include: ice, dtls, sctp, srtp, rtcp, and more.

Basic Custom Logger

Here’s a complete example of implementing a custom logger:
custom-logger.go
From examples/custom-logger/main.go:20-64.

Per-Subsystem Logging

You can create different loggers for each subsystem:
per-subsystem.go

Logging to File

Direct logs to a file:
file-logger.go

Structured Logging (JSON)

Integrate with structured logging libraries:
json-logger.go

Using Pion’s Default Logger

Pion provides a default logger implementation:
default-logger.go

Log Levels

Pion supports these log levels:
1

Trace

Most verbose - detailed packet-level information
2

Debug

Debugging information - state changes, decisions
3

Info

General information - connection established, etc.
4

Warn

Warnings - recoverable issues
5

Error

Errors - failures and exceptions
Trace logs can be extremely verbose and impact performance. Only enable in development.

Common Subsystems

These are the subsystems you’ll see in logs:
string
ICE agent - candidate gathering, connectivity checks
string
DTLS handshake and encryption
string
SCTP for data channels
string
SRTP encryption/decryption
string
RTCP packet processing
string
PeerConnection lifecycle

Filtering by Subsystem

Only log specific subsystems:
filter-subsystem.go

Logrus Integration

logrus-integration.go

Zap Integration

zap-integration.go

Complete Example

See the complete working example at examples/custom-logger/main.go.This example demonstrates:
  • Implementing LeveledLogger interface
  • Creating a LoggerFactory
  • Per-subsystem logger creation
  • Integration with SettingEngine
  • Full PeerConnection setup with custom logging

Debugging Tips

1

Enable Debug Logs for ICE

Most connection issues are ICE-related. Enable debug logging for the ice subsystem.
2

Log DTLS Handshake

Certificate and DTLS issues appear in dtls subsystem logs.
3

Monitor SCTP for Data Channels

Data channel issues show up in sctp logs.
4

Avoid Trace in Production

Trace logs can significantly impact performance. Use Debug or Info in production.

SettingEngine

Configure advanced WebRTC behavior

ICE Configuration

Debug ICE connectivity