The mcpproxy-go project includes a comprehensive logging system that follows OS-specific standards for log file storage and provides flexible configuration options.
The logging system provides:
- OS-specific standard directory compliance for log storage
- Automatic log rotation with configurable size, age, and backup limits
- Multiple output formats (console, structured, JSON)
- Configurable log levels (debug, info, warn, error)
- Thread-safe concurrent logging
- CLI and configuration file control
# Enable file logging with default settings
mcpproxy serve --log-to-file
# Set log level and enable file logging
mcpproxy serve --log-level debug --log-to-file
# Use custom log file location
mcpproxy serve --log-file /path/to/custom/mcpproxy.log
# Disable file logging (console only)
mcpproxy serve --log-to-file=false{
"logging": {
"level": "info",
"enable_file": true,
"enable_console": true,
"filename": "mcpproxy.log",
"max_size": 10,
"max_backups": 5,
"max_age": 30,
"compress": true,
"json_format": false
}
}The logging system automatically selects the appropriate directory based on your operating system:
- Location:
~/Library/Logs/mcpproxy/ - Standard: macOS File System Programming Guide
- Example:
/Users/username/Library/Logs/mcpproxy/mcpproxy.log
- Location:
%LOCALAPPDATA%\mcpproxy\logs\ - Fallback:
%USERPROFILE%\AppData\Local\mcpproxy\logs\ - Standard: Windows Application Data Guidelines
- Example:
C:\Users\username\AppData\Local\mcpproxy\logs\mcpproxy.log
- Regular User:
~/.local/state/mcpproxy/logs/(XDG Base Directory Specification) - Root User:
/var/log/mcpproxy/ - XDG Override: Uses
$XDG_STATE_HOME/mcpproxy/logs/if set - Example:
/home/username/.local/state/mcpproxy/logs/mcpproxy.log
- Location:
~/.mcpproxy/logs/ - Used when: OS detection fails or standard directories are inaccessible
| Level | Description | Use Case |
|---|---|---|
debug |
Detailed diagnostic information | Development, troubleshooting |
info |
General operational messages | Default production logging |
warn |
Warning conditions that should be noted | Potential issues |
error |
Error conditions that need attention | Problems requiring action |
| Setting | Type | Default | Description |
|---|---|---|---|
max_size |
int | 10 | Maximum log file size in MB before rotation |
max_backups |
int | 5 | Maximum number of backup files to keep |
max_age |
int | 30 | Maximum age of backup files in days |
compress |
bool | true | Whether to compress rotated log files |
2025-06-24 09:31:16 | INFO | server/server.go:176 | Starting mcpproxy | {"version": "v0.1.0"}
{"level":"info","ts":"2025-06-24T09:31:16.519+03:00","caller":"server/server.go:176","msg":"Starting mcpproxy","version":"v0.1.0"}| Flag | Type | Default | Description |
|---|---|---|---|
--log-level |
string | "info" | Set the log level (debug, info, warn, error) |
--log-to-file |
bool | true | Enable logging to file in standard OS location |
--log-file |
string | "" | Custom log file path (overrides standard location) |
{
"logging": {
"level": "info", // Log level: debug, info, warn, error
"enable_file": true, // Enable file logging
"enable_console": true, // Enable console logging
"filename": "mcpproxy.log", // Log filename (in standard directory)
"max_size": 10, // Max file size in MB
"max_backups": 5, // Number of backup files to keep
"max_age": 30, // Max age of backups in days
"compress": true, // Compress rotated files
"json_format": false // Use JSON format instead of console format
}
}# Use a custom log file path
mcpproxy serve --log-file /var/log/myapp/mcpproxy.log
# Use custom path with configuration
{
"logging": {
"filename": "/var/log/myapp/mcpproxy.log"
}
}{
"logging": {
"level": "info",
"enable_file": true,
"enable_console": false,
"json_format": true,
"max_size": 100,
"max_backups": 10,
"max_age": 90
}
}{
"logging": {
"level": "debug",
"enable_file": true,
"enable_console": true,
"json_format": false,
"max_size": 1,
"max_backups": 2,
"max_age": 1
}
}The logging system uses lumberjack for automatic log rotation:
- Size-based rotation: When a log file exceeds
max_sizeMB - Age-based cleanup: Removes files older than
max_agedays - Count-based cleanup: Keeps only
max_backupsbackup files - Compression: Optionally compresses rotated files with gzip
mcpproxy.log # Current log file
mcpproxy.log.2025-06-24 # Rotated by date
mcpproxy.log.2025-06-23.gz # Compressed backup
Use the built-in command to find log directory:
# The log directory path is shown in startup logs
mcpproxy serve --log-level debug | grep "Log directory configured"Startup Information:
Log directory configured | {"path": "/Users/user/Library/Logs/mcpproxy", "os": "darwin", "standard": "macOS File System Programming Guide"}
Starting mcpproxy | {"version": "v0.1.0", "log_level": "info"}
Server Operations:
Server is ready | {"phase": "Ready", "message": "Server is ready"}
Tool called | {"tool": "example:search", "server": "example", "duration": "150ms"}
Error Handling:
Failed to connect to upstream server | {"server": "example", "error": "connection refused"}
| Level | Performance | Use Case |
|---|---|---|
error |
Minimal overhead | Production (errors only) |
warn |
Low overhead | Production (recommended) |
info |
Moderate overhead | Production (verbose) |
debug |
High overhead | Development only |
- File logging: Better for production, log rotation, persistence
- Console logging: Better for development, real-time monitoring
- Both enabled: Flexible but higher overhead
- Check permissions: Ensure write access to the standard directory
- Check disk space: Ensure sufficient space for log files
- Use custom path: Override with
--log-fileif needed
# Test with custom path
mcpproxy serve --log-file ./mcpproxy.log --log-level debug- Check file size: Ensure logs exceed
max_sizethreshold - Check permissions: Ensure write access for rotation
- Check configuration: Verify rotation settings
- Reduce log level: Use
warnorerrorin production - Disable console logging: Use file-only logging
- Increase rotation size: Reduce rotation frequency
{
"logging": {
"level": "warn",
"enable_console": false,
"max_size": 100
}
}The logging system includes comprehensive tests:
# Run all logging tests
go test ./internal/logs
# Run E2E logging tests
go test ./internal/logs -run TestE2E
# Test specific functionality
go test ./internal/logs -run TestE2E_LogRotation
go test ./internal/logs -run TestE2E_ConcurrentLogging- Log file permissions: Files created with 0644 permissions
- Directory permissions: Directories created with 0755 permissions
- Sensitive data: Avoid logging sensitive information
- Log rotation: Old logs are automatically cleaned up
# Mount log directory as volume
VOLUME ["/var/log/mcpproxy"]
# Configure for container logging
ENV LOG_LEVEL=info
ENV LOG_TO_FILE=true[Unit]
Description=MCP Proxy Service
[Service]
ExecStart=/usr/local/bin/mcpproxy serve --log-to-file --log-level info
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.targetFor centralized logging with tools like ELK stack or Fluentd:
{
"logging": {
"json_format": true,
"enable_console": false,
"max_size": 50,
"compress": false
}
}// Get OS-specific log directory
logDir, err := logs.GetLogDir()
// Get log directory information
info, err := logs.GetLogDirInfo()
// Ensure log directory exists
err := logs.EnsureLogDir(logDir)
// Get full path for log file
logPath, err := logs.GetLogFilePath("mcpproxy.log")// Setup logger with configuration
config := &config.LogConfig{
Level: "info",
EnableFile: true,
EnableConsole: true,
// ... other options
}
logger, err := logs.SetupLogger(config)The logging system follows established standards for each operating system:
- macOS: File System Programming Guide
- Windows: Application Data Guidelines
- Linux: XDG Base Directory Specification
This ensures that logs are stored in the expected locations for each platform, making them easy to find and manage.