A thread-safe, asynchronous logging system that writes messages to timestamped files.
import "path/to/logging"
// Initialize with default settings (buffer size: 1000) InitLogServer() // Enable logging - creates ./logs directory and log file if err := EnableLogging(); err != nil { log.Fatal(err) } // Write logs asynchronously WriteLogs("Starting application...") // Check logging status if IsLoggingEnabled() { WriteLogs("System is running") } // Disable logging - ensures all messages are written before closing DisableLogging()
// Initialize with custom buffer size InitLogServer(WithBufferSize(2000))
- Thread-safe operations
- Non-blocking writes with configurable buffer
- Automatic log file creation with timestamps
- Clean session markers
- Log files format:
./logs/anthropic-debug-YYYYMMDD-HHMMSS.log
- Initialize early in your application
- Always handle
EnableLogging()errors - Call
DisableLogging()before application shutdown - Monitor stderr for dropped message warnings
=== Session Started: 2024年12月09日 15:04:05 ===
[2024年12月09日 15:04:05.123] Log message 1
[2024年12月09日 15:04:06.234] Log message 2
=== Session Ended: 2024年12月09日 15:04:07 ===