Skip to main content

Logging Configuration

Gate uses structured logging with Uber’s Zap logger, providing high-performance, leveled logging with structured fields. Logs can be configured via command-line flags and environment variables.

Log Levels

Gate supports multiple log verbosity levels, controlled by the --verbosity flag or GATE_VERBOSITY environment variable:

Setting Log Level

Configuration

Command-Line Flags

Environment Variables

Configuration File

Log Format

Gate uses different log formats depending on the mode:

Production Format (Default)

JSON-structured logs optimized for machine parsing:

Development Format (Debug Mode)

Human-readable console logs with colors:

Logger Implementation

Gate’s logger is configured in cmd/gate/root.go:191:

Structured Fields

Gate logs include structured fields for easy filtering:
Output:

OpenTelemetry Integration

When OpenTelemetry tracing is enabled, logs automatically include trace context:
Logs will include trace and span IDs:
This enables correlation between logs and traces in observability platforms.

Log Aggregation

Grafana Loki

Loki is designed for aggregating logs from multiple sources.

Docker Compose with Loki

Loki Configuration

Querying Logs in Grafana

Promtail for Log Shipping

Use Promtail to ship logs from files to Loki:

Elasticsearch and Kibana

For Elasticsearch-based log aggregation:

Best Practices

1. Production Logging

Log only essential information:
  • Service startup/shutdown
  • Player connections/disconnections
  • Configuration changes
  • Errors and warnings

2. Development Logging

Includes:
  • Detailed packet information
  • Authentication flows
  • Internal state changes
  • Performance metrics

3. Structured Fields

Always use structured fields instead of string formatting:

4. Log Sampling

For high-frequency events, use sampling to reduce log volume:

5. Sensitive Data

Never log sensitive information:

6. Error Context

Include context when logging errors:

Log Rotation

Using logrotate (Linux)

Using Docker logging driver

Custom Plugin Logging

Use the context logger in your plugins:

Troubleshooting

No Logs Appearing

  1. Check verbosity level:
  2. Ensure debug mode is not disabled in config:
  3. Verify logger initialization in Gate startup logs

Too Many Logs

  1. Reduce verbosity:
  2. Disable debug mode:
  3. Implement log sampling for high-frequency events

Logs Not in JSON Format

Gate uses console encoding by default. For JSON logs, you need to modify the logger configuration or use a log shipper to parse console logs.

Next Steps

OpenTelemetry

Set up comprehensive observability

Metrics

Monitor proxy performance metrics