Compare commits
1 Commits
log/v0.12.
...
log/v0.13.
| Author | SHA1 | Date | |
|---|---|---|---|
| 7bb09785f2 |
@@ -104,8 +104,8 @@ func Fatal(ctx context.Context, args ...any) {
|
|||||||
globalLogger.AddCallerSkip(1).Fatal(ctx, args...)
|
globalLogger.AddCallerSkip(1).Fatal(ctx, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Panic 输出 LevelPanic 等级的日志,
|
// Panic 输出 LevelPanic 等级的日志后执行 panic,
|
||||||
// Panic 不会调用 panic 函数.
|
// 即使 Logger 日志等级高于 LevelPanic 也会 panic.
|
||||||
func Panic(ctx context.Context, args ...any) {
|
func Panic(ctx context.Context, args ...any) {
|
||||||
globalLogger.AddCallerSkip(1).Panic(ctx, args...)
|
globalLogger.AddCallerSkip(1).Panic(ctx, args...)
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,7 @@ func Fatalf(ctx context.Context, format string, args ...any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Panicf 格式化输出 LevelPanic 等级的日志,
|
// Panicf 格式化输出 LevelPanic 等级的日志,
|
||||||
// Panicf 不会调用 panic 函数.
|
// 即使 Logger 日志等级高于 LevelPanic 也会 panic.
|
||||||
func Panicf(ctx context.Context, format string, args ...any) {
|
func Panicf(ctx context.Context, format string, args ...any) {
|
||||||
globalLogger.AddCallerSkip(1).Panicf(ctx, format, args...)
|
globalLogger.AddCallerSkip(1).Panicf(ctx, format, args...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,8 +127,8 @@ func (entry Entry) Fatal(ctx context.Context, args ...any) {
|
|||||||
entry.logger.Exit(1)
|
entry.logger.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Panic 输出 LevelPanic 等级的日志,
|
// Panic 输出 LevelPanic 等级的日志后执行 panic,
|
||||||
// Panic 不会调用 panic 函数.
|
// 即使 Logger 日志等级高于 LevelPanic 也会 panic.
|
||||||
func (entry Entry) Panic(ctx context.Context, args ...any) {
|
func (entry Entry) Panic(ctx context.Context, args ...any) {
|
||||||
entry.log(ctx, LevelPanic, fmt.Sprint(args...))
|
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 格式化输出 LevelPanic 等级的日志,
|
||||||
// Panicf 不会调用 panic 函数.
|
// 即使 Logger 日志等级高于 LevelPanic 也会 panic.
|
||||||
func (entry Entry) Panicf(ctx context.Context, format string, args ...any) {
|
func (entry Entry) Panicf(ctx context.Context, format string, args ...any) {
|
||||||
entry.log(ctx, LevelPanic, fmt.Sprintf(format, args...))
|
entry.log(ctx, LevelPanic, fmt.Sprintf(format, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (entry Entry) log(ctx context.Context, level Level, message string) {
|
func (entry Entry) log(ctx context.Context, level Level, message string) {
|
||||||
|
defer func() {
|
||||||
|
if level == LevelPanic {
|
||||||
|
panic(message)
|
||||||
|
}
|
||||||
|
}()
|
||||||
newEntry := entry.copy()
|
newEntry := entry.copy()
|
||||||
if newEntry.logger.GetLevel() < level {
|
if newEntry.logger.GetLevel() < level {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user