package logger import ( "testing" "time" ) func TestLoggerExamples(t *testing.T) { // Example 1: Basic logging Info("Application starting up") Debug("Debug information", map[string]interface{}{"config_loaded": true}) // Example 2: Service-specific logging authLogger := AuthServiceLogger() authLogger.Info("User authentication successful", map[string]interface{}{ "user_id": "12345", "method": "oauth2", }) // Example 3: Error logging with context Error("Database connection failed", map[string]interface{}{ "error": "connection timeout", "retry_count": 3, "max_retries": 5, "service": "database-service", }) // Example 4: Performance timing start := time.Now() time.Sleep(10 * time.Millisecond) // Simulate work globalLogger.LogDuration(start, "Database query completed", map[string]interface{}{ "query": "SELECT * FROM users", "rows": 150, "database": "postgres", }) // Example 5: JSON format logging jsonLogger := New("test-service", DEBUG, true) jsonLogger.Info("JSON formatted log", map[string]interface{}{ "user": map[string]interface{}{ "id": "user-123", "name": "John Doe", "email": "john@example.com", }, "request": map[string]interface{}{ "method": "GET", "path": "/api/v1/users", }, }) t.Log("Logger examples executed successfully") } func TestLoggerLevels(t *testing.T) { // Test different log levels Debug("This is a debug message") Info("This is an info message") Warn("This is a warning message") Error("This is an error message") t.Log("All log levels tested") } func TestLoggerWithRequestContext(t *testing.T) { // Simulate request context with IDs logger := Default(). WithRequestID("req-123456"). WithCorrelationID("corr-789012") logger.Info("Request processing started", map[string]interface{}{ "endpoint": "/api/v1/data", "method": "POST", "client_ip": "192.168.1.100", }) t.Log("Request context logging tested") }