APISIX Logging Guide

APISIX Logging Configuration Overview
Introduction to Logging
APISIX provides comprehensive logging capabilities to help monitor and troubleshoot your API gateway. This guide covers various logging plugins and configurations available in APISIX.
HTTP Logger Configuration
HTTP Logging Setup
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/api/*",
"plugins": {
"http-logger": {
"uri": "http://logging-server:8080/logs",
"batch_max_size": 1000,
"max_retry_count": 3,
"retry_delay": 2,
"buffer_duration": 60,
"inactive_timeout": 5
}
}
}'
File Logger
Local File Logging
curl http://127.0.0.1:9080/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/api/*",
"plugins": {
"file-logger": {
"path": "/tmp/logs/access.log"
}
}
}'
Syslog Integration
Syslog Configuration
curl http://127.0.0.1:9080/apisix/admin/routes/3 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/api/*",
"plugins": {
"syslog": {
"host": "localhost",
"port": 5140,
"timeout": 3000
}
}
}'
Pro Tip: Use batch processing for better performance when dealing with high-volume logs.
Kafka Logger
Kafka Integration
curl http://127.0.0.1:9080/apisix/admin/routes/4 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/api/*",
"plugins": {
"kafka-logger": {
"broker_list": {
"127.0.0.1:9092"
},
"kafka_topic": "apisix-logger",
"batch_max_size": 1000
}
}
}'
Best Practices
Logging Recommendations
- Implement log rotation
- Use appropriate log levels
- Configure batch processing for performance
- Monitor log storage usage
- Implement log retention policies