Enhance logging configuration by introducing file output options and rotation settings in config.dev.toml. Update logger implementation to support multiple output streams, including file logging with rotation using lumberjack. Improve error handling and logging across various components, ensuring consistent logging practices. Update .gitignore to include log files and compressed logs. Add new Go module dependency for lumberjack.

This commit is contained in:
windyboy
2025-11-17 12:58:40 +08:00
parent 204217015d
commit 67abd66fa3
12 changed files with 326 additions and 31 deletions
+11 -5
View File
@@ -150,6 +150,12 @@ func (p *MessageProcessor) Handle(ctx context.Context, raw []byte, msgID string)
latency := parsed.ParsedAt.Sub(receivedAt)
p.telemetry.RecordFailure("repository")
p.telemetry.RecordProcessingResult(ctx, string(parsed.Status), parsed.Category, latency)
// Log business layer failure with message context (Repository layer already logged technical error)
msgLogger.Error("Failed to persist parsed message",
zap.String("status", string(parsed.Status)),
zap.Duration("latency", latency),
zap.Error(err),
)
return fmt.Errorf("failed to insert message: %w", err)
}
@@ -202,11 +208,11 @@ func (p *MessageProcessor) persistRaw(ctx context.Context, msg *dto.ParsedTelegr
msg.ReceivedAt = time.Now()
}
if err := p.repository.InsertRaw(ctx, msg); err != nil {
p.logger.Error("Failed to persist raw telegram",
zap.String("message_id", msg.MessageID),
zap.String("status", string(msg.Status)),
zap.Error(err),
)
// Error already logged in Repository.InsertRaw, no need to log again
// Just add event to span if recording
if span := trace.SpanFromContext(ctx); span.IsRecording() {
span.RecordError(err)
}
} else {
if span := trace.SpanFromContext(ctx); span.IsRecording() {
span.AddEvent("raw telegram persisted",