pollux/LOGGING_IMPLEMENTATION.md
Jeena 8fa30c2545 Initial codebase structure
- Complete Gemini server implementation with logging
- Add comprehensive documentation (README.md, AGENTS.md)
- Implement certificate management guidelines
- Add .gitignore for security and build artifacts
- All unit tests passing (14/14)
- Ready for production deployment
2026-01-15 08:21:37 +09:00

2.7 KiB

Pollux Gemini Server - Logging Implementation Complete

Summary

Successfully implemented Apache/Nginx-style logging for the Pollux Gemini server with the following features:

Implemented Features

  1. Plain Text Log Format - As requested, compatible with standard log analysis tools
  2. Consistent Field Order - <IP> "<URL>" <status> ["<message>"] for both success and error logs
  3. stdout/stderr Output - Ready for systemd integration
  4. Client IP Extraction - Extracts IP from TLS connections
  5. Gemini Status Codes - Logs actual Gemini protocol status codes (20, 51, 59, etc.)
  6. Error Messages - Detailed error descriptions for troubleshooting

📋 Log Format

Access Logs (stdout):

127.0.0.1 "gemini://jeena.net/" 20
192.168.1.100 "gemini://jeena.net/posts/vibe-coding.gmi" 20

Error Logs (stderr):

192.168.1.100 "gemini://jeena.net/posts/nonexistent.gmi" 51 "File not found"
192.168.1.100 "gemini://jeena.net/../etc/passwd" 59 "Path traversal attempt"

🖥️ systemd Integration

When run as a systemd service:

  • Access logs: journalctl -u pollux
  • Error logs: journalctl -u pollux -p err
  • Timestamps: Automatically added by systemd
  • Rotation: Handled by journald configuration
  • Filtering: Standard journalctl filtering works

📁 Files Modified

  • src/logging.rs - New logging module with RequestLogger
  • src/server.rs - Integrated logging into connection handling
  • src/main.rs - Added log level configuration
  • src/config.rs - Added log_level config option
  • Cargo.toml - Added tracing dependencies

⚙️ Configuration

log_level = "info"  # debug, info, warn, error

🧪 Gemini Protocol Considerations

  • No User-Agent: Gemini protocol doesn't have HTTP-style User-Agent headers
  • No Referer: Not part of Gemini specification (privacy-focused design)
  • Client IP: Extracted from TLS connection (best available)
  • Status Codes: Uses actual Gemini protocol codes

Testing

  • All 14 tests pass
  • Server compiles cleanly (no warnings)
  • Logging verified to produce correct format
  • Compatible with systemd journalctl

🚀 Ready for Production

The server now has production-grade logging that:

  • Works with existing log analysis tools (grep, awk, logrotate)
  • Integrates seamlessly with systemd
  • Provides essential debugging information
  • Follows Apache/Nginx conventions
  • Supports the Gemini protocol appropriately

Usage Examples

# View live logs
journalctl -u pollux -f

# Filter access logs  
journalctl -u pollux | grep -v "ERROR"

# Filter error logs
journalctl -u pollux -p err

# Time range filtering
journalctl -u pollux --since "1 hour ago"

Implementation complete and ready for deployment!