feat(slog-integration)
- rows and err include in logs for slog logger
This commit is contained in:
parent
86755e86ea
commit
02f4f1c49c
@ -60,10 +60,16 @@ func (l *slogLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql
|
||||
sql, rows := fc()
|
||||
fields := []slog.Attr{
|
||||
slog.String("duration", fmt.Sprintf("%.3fms", float64(elapsed.Nanoseconds())/1e6)),
|
||||
slog.Int64("rows", rows),
|
||||
slog.String("sql", sql),
|
||||
}
|
||||
|
||||
if rows != -1 {
|
||||
fields = append(fields, slog.Int64("rows", rows))
|
||||
}
|
||||
if err != nil {
|
||||
fields = append(fields, slog.String("error", err.Error()))
|
||||
}
|
||||
|
||||
switch {
|
||||
case err != nil && (!l.IgnoreRecordNotFoundError || !errors.Is(err, ErrRecordNotFound)):
|
||||
l.Logger.ErrorContext(ctx, "SQL executed", slog.Attr{
|
||||
|
Loading…
x
Reference in New Issue
Block a user