Skip to content

Commit ccb9133

Browse files
committed
refactor: refactor logging stack handling and improve logger methods
- Adjust stack information handling to prepend it to logger arguments - Modify `logWithCallerf` and `logWithCaller` methods to improve readability and flexibility Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent 033194d commit ccb9133

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

logger.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ type defaultLogger struct {
3232
}
3333

3434
func (l defaultLogger) logWithCallerf(logger *log.Logger, format string, args ...any) {
35-
stack := stack(3)
36-
logger.Printf("%s%s", stack, fmt.Sprintf(format, args...))
35+
stackInfo := stack(3) // Assuming stack(3) returns caller info string
36+
// Prepend stack info to the arguments and adjust the format string
37+
logger.Printf("%s "+format, append([]any{stackInfo}, args...)...)
3738
}
3839

3940
func (l defaultLogger) logWithCaller(logger *log.Logger, args ...any) {
4041
stack := stack(3)
41-
logger.Println(stack, fmt.Sprint(args...))
42+
logger.Println(append([]any{stack}, args...)...)
4243
}
4344

4445
func (l defaultLogger) Infof(format string, args ...any) {

0 commit comments

Comments
 (0)