Compare commits

..

1 Commits

Author SHA1 Message Date
7bb09785f2 log/Panic改回调用panic; 2023-05-06 14:54:36 +08:00
2 changed files with 11 additions and 6 deletions

View File

@@ -104,8 +104,8 @@ func Fatal(ctx context.Context, args ...any) {
globalLogger.AddCallerSkip(1).Fatal(ctx, args...)
}
// Panic 输出 LevelPanic 等级的日志,
// Panic 不会调用 panic 函数.
// Panic 输出 LevelPanic 等级的日志后执行 panic,
// 即使 Logger 日志等级高于 LevelPanic 也会 panic.
func Panic(ctx context.Context, args ...any) {
globalLogger.AddCallerSkip(1).Panic(ctx, args...)
}
@@ -146,7 +146,7 @@ func Fatalf(ctx context.Context, format string, args ...any) {
}
// Panicf 格式化输出 LevelPanic 等级的日志,
// Panicf 不会调用 panic 函数.
// 即使 Logger 日志等级高于 LevelPanic 也会 panic.
func Panicf(ctx context.Context, format string, args ...any) {
globalLogger.AddCallerSkip(1).Panicf(ctx, format, args...)
}

View File

@@ -127,8 +127,8 @@ func (entry Entry) Fatal(ctx context.Context, args ...any) {
entry.logger.Exit(1)
}
// Panic 输出 LevelPanic 等级的日志,
// Panic 不会调用 panic 函数.
// Panic 输出 LevelPanic 等级的日志后执行 panic,
// 即使 Logger 日志等级高于 LevelPanic 也会 panic.
func (entry Entry) Panic(ctx context.Context, args ...any) {
entry.log(ctx, LevelPanic, fmt.Sprint(args...))
}
@@ -170,12 +170,17 @@ func (entry Entry) Fatalf(ctx context.Context, format string, args ...any) {
}
// Panicf 格式化输出 LevelPanic 等级的日志,
// Panicf 不会调用 panic 函数.
// 即使 Logger 日志等级高于 LevelPanic 也会 panic.
func (entry Entry) Panicf(ctx context.Context, format string, args ...any) {
entry.log(ctx, LevelPanic, fmt.Sprintf(format, args...))
}
func (entry Entry) log(ctx context.Context, level Level, message string) {
defer func() {
if level == LevelPanic {
panic(message)
}
}()
newEntry := entry.copy()
if newEntry.logger.GetLevel() < level {
return