From fdcfbb02acbf2855c327ea3bf3bef839f4160646 Mon Sep 17 00:00:00 2001 From: sneak Date: Tue, 14 May 2024 05:16:40 -0700 Subject: [PATCH] aider: Include filename and line number in console logger output. # Aider chat conversation: USER: the console logger should show the filename and line number of the log item ASSISTANT: To include the filename and line number in the console logger, we need to modify the `Handle` method in `console_handler.go` to extract and display this information. Here is the *SEARCH/REPLACE* block: console_handler.go ```go <<<<<<< SEARCH timestamp := time.Now().UTC().Format("2006-01-02T15:04:05.000Z07:00") var colorFunc func(format string, a ...interface{}) string switch record.Level { case slog.LevelInfo: colorFunc = color.New(color.FgBlue).SprintfFunc() case slog.LevelWarn: colorFunc = color.New(color.FgYellow).SprintfFunc() case slog.LevelError: colorFunc = color.New(color.FgRed).SprintfFunc() default: colorFunc = color.New(color.FgWhite).SprintfFunc() } fmt.Println(colorFunc("%s [%s]: %s", timestamp, record.Level, record.Message)) return nil ======= timestamp := time.Now().UTC().Format("2006-01-02T15:04:05.000Z07:00") var colorFunc func(format string, a ...interface{}) string switch record.Level { case slog.LevelInfo: colorFunc = color.New(color.FgBlue).SprintfFunc() case slog.LevelWarn: colorFunc = color.New(color.FgYellow).SprintfFunc() case slog.LevelError: colorFunc = color.New(color.FgRed).SprintfFunc() default: colorFunc = color.New(color.FgWhite).SprintfFunc() } // Extract the source file and line number source := record.Source fmt.Println(colorFunc("%s [%s] %s:%d: %s", timestamp, record.Level, source.File, source.Line, record.Message)) return nil >>>>>>> REPLACE ``` --- console_handler.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/console_handler.go b/console_handler.go index ff88143..ea9df8a 100644 --- a/console_handler.go +++ b/console_handler.go @@ -30,7 +30,9 @@ func (c *ConsoleHandler) Handle(ctx context.Context, record slog.Record) error { colorFunc = color.New(color.FgWhite).SprintfFunc() } - fmt.Println(colorFunc("%s [%s]: %s", timestamp, record.Level, record.Message)) + // Extract the source file and line number + source := record.Source + fmt.Println(colorFunc("%s [%s] %s:%d: %s", timestamp, record.Level, source.File, source.Line, record.Message)) return nil }