writeLogEntry writes a log entry to the file
(entry LogEntry)
| 98 | |
| 99 | // writeLogEntry writes a log entry to the file |
| 100 | func (rl *RequestLogger) writeLogEntry(entry LogEntry) error { |
| 101 | jsonData, err := json.Marshal(entry) |
| 102 | if err != nil { |
| 103 | return fmt.Errorf("failed to marshal log entry: %w", err) |
| 104 | } |
| 105 | |
| 106 | // Write JSON entry followed by newline |
| 107 | if _, err := rl.logFile.Write(jsonData); err != nil { |
| 108 | return fmt.Errorf("failed to write log entry: %w", err) |
| 109 | } |
| 110 | |
| 111 | if _, err := rl.logFile.WriteString("\n"); err != nil { |
| 112 | return fmt.Errorf("failed to write newline: %w", err) |
| 113 | } |
| 114 | |
| 115 | // Flush to ensure data is written immediately |
| 116 | return rl.logFile.Sync() |
| 117 | } |
| 118 | |
| 119 | // Close closes the log file |
| 120 | func (rl *RequestLogger) Close() error { |
no outgoing calls
no test coverage detected