fix(logger): handle file log exception for log.Log (#5700)
Some checks are pending
Pipeline: Test, Lint, Build / Get version info (push) Waiting to run
Pipeline: Test, Lint, Build / Lint Go code (push) Waiting to run
Pipeline: Test, Lint, Build / Test Go code (push) Waiting to run
Pipeline: Test, Lint, Build / Test Go code (Windows) (push) Waiting to run
Pipeline: Test, Lint, Build / Test JS code (push) Waiting to run
Pipeline: Test, Lint, Build / Lint i18n files (push) Waiting to run
Pipeline: Test, Lint, Build / Check Docker configuration (push) Waiting to run
Pipeline: Test, Lint, Build / Build (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-1 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-2 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-3 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-4 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-5 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-6 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-7 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-8 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-9 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build-10 (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Push to GHCR (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Push to Docker Hub (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Cleanup digest artifacts (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Build Windows installers (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Package/Release (push) Blocked by required conditions
Pipeline: Test, Lint, Build / Upload Linux PKG (push) Blocked by required conditions

* fix(logger): handle file log exception for log.Log

* simplify logger, enhance test

---------

Co-authored-by: Deluan Quintão <deluan@navidrome.org>
This commit is contained in:
Kendall Garner 2026-07-02 04:27:39 +00:00 committed by GitHub
parent e80a7937e8
commit a77834ce73
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 14 deletions

View file

@ -193,34 +193,39 @@ func IsGreaterOrEqualTo(level Level) bool {
} }
func Fatal(args ...any) { func Fatal(args ...any) {
Log(LevelFatal, args...) log(LevelFatal, args...)
os.Exit(1) os.Exit(1)
} }
func Error(args ...any) { func Error(args ...any) {
Log(LevelError, args...) log(LevelError, args...)
} }
func Warn(args ...any) { func Warn(args ...any) {
Log(LevelWarn, args...) log(LevelWarn, args...)
} }
func Info(args ...any) { func Info(args ...any) {
Log(LevelInfo, args...) log(LevelInfo, args...)
} }
func Debug(args ...any) { func Debug(args ...any) {
Log(LevelDebug, args...) log(LevelDebug, args...)
} }
func Trace(args ...any) { func Trace(args ...any) {
Log(LevelTrace, args...) log(LevelTrace, args...)
} }
func Log(level Level, args ...any) { func Log(level Level, args ...any) {
log(level, args...)
}
func log(level Level, args ...any) {
if !shouldLog(level, 3) { if !shouldLog(level, 3) {
return return
} }
logger, msg := parseArgs(args) logger, msg := parseArgs(args)
logger.Log(logrus.Level(level), msg) logger.Log(logrus.Level(level), msg)
} }

View file

@ -135,18 +135,32 @@ var _ = Describe("Logger", func() {
}) })
Describe("LogLevels", func() { Describe("LogLevels", func() {
It("logs at specific levels", func() { BeforeEach(func() {
SetLevel(LevelError) SetLevel(LevelFatal)
Debug("message 1") SetLogLevels(nil)
})
DescribeTable("logs at specific levels", func(logger func(...any), level Level) {
logger("message 1")
Expect(hook.LastEntry()).To(BeNil()) Expect(hook.LastEntry()).To(BeNil())
SetLogLevels(map[string]string{ Log(level, "message 1.5")
"log/log_test": "debug", Expect(hook.LastEntry()).To(BeNil())
})
Debug("message 2") SetLogLevels(map[string]string{"log/log_test": "trace"})
logger("message 2")
Expect(hook.LastEntry().Message).To(Equal("message 2")) Expect(hook.LastEntry().Message).To(Equal("message 2"))
})
Log(level, "message 2.5")
Expect(hook.LastEntry().Message).To(Equal("message 2.5"))
},
Entry("Error", Error, LevelError),
Entry("Warn", Warn, LevelWarn),
Entry("Info", Info, LevelInfo),
Entry("Debug", Debug, LevelDebug),
Entry("Trace", Trace, LevelTrace),
)
}) })
Describe("IsGreaterOrEqualTo", func() { Describe("IsGreaterOrEqualTo", func() {