Rename log.LevelCritical to log.LevelFatal

This commit is contained in:
Deluan 2022-12-21 14:53:36 -05:00
parent 28389fb05e
commit 5943e8f953
26 changed files with 40 additions and 46 deletions

View File

@ -11,7 +11,7 @@ import (
func TestAgents(t *testing.T) { func TestAgents(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Agents Test Suite") RunSpecs(t, "Agents Test Suite")
} }

View File

@ -11,7 +11,7 @@ import (
func TestLastFM(t *testing.T) { func TestLastFM(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "LastFM Test Suite") RunSpecs(t, "LastFM Test Suite")
} }

View File

@ -11,7 +11,7 @@ import (
func TestListenBrainz(t *testing.T) { func TestListenBrainz(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "ListenBrainz Test Suite") RunSpecs(t, "ListenBrainz Test Suite")
} }

View File

@ -11,7 +11,7 @@ import (
func TestSpotify(t *testing.T) { func TestSpotify(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Spotify Test Suite") RunSpecs(t, "Spotify Test Suite")
} }

View File

@ -15,7 +15,7 @@ import (
) )
func TestAuth(t *testing.T) { func TestAuth(t *testing.T) {
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Auth Test Suite") RunSpecs(t, "Auth Test Suite")
} }

View File

@ -11,7 +11,7 @@ import (
func TestCore(t *testing.T) { func TestCore(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Core Suite") RunSpecs(t, "Core Suite")
} }

View File

@ -11,7 +11,7 @@ import (
func TestAgents(t *testing.T) { func TestAgents(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Scrobbler Test Suite") RunSpecs(t, "Scrobbler Test Suite")
} }

View File

@ -11,7 +11,7 @@ import (
func TestTranscoder(t *testing.T) { func TestTranscoder(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Transcoder Suite") RunSpecs(t, "Transcoder Suite")
} }

View File

@ -3,7 +3,6 @@ package db
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"os"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/navidrome/navidrome/conf" "github.com/navidrome/navidrome/conf"
@ -59,21 +58,18 @@ func EnsureLatestVersion() {
err = goose.SetDialect(Driver) err = goose.SetDialect(Driver)
if err != nil { if err != nil {
log.Error("Invalid DB driver", "driver", Driver, err) log.Fatal("Invalid DB driver", "driver", Driver, err)
os.Exit(1)
} }
err = goose.Run("up", db, "./") err = goose.Run("up", db, "./")
if err != nil { if err != nil {
log.Error("Failed to apply new migrations", err) log.Fatal("Failed to apply new migrations", err)
os.Exit(1)
} }
} }
func isSchemaEmpty(db *sql.DB) bool { // nolint:interfacer func isSchemaEmpty(db *sql.DB) bool { // nolint:interfacer
rows, err := db.Query("SELECT name FROM sqlite_master WHERE type='table' AND name='goose_db_version';") // nolint:rowserrcheck rows, err := db.Query("SELECT name FROM sqlite_master WHERE type='table' AND name='goose_db_version';") // nolint:rowserrcheck
if err != nil { if err != nil {
log.Error("Database could not be opened!", err) log.Fatal("Database could not be opened!", err)
os.Exit(1)
} }
defer rows.Close() defer rows.Close()
return !rows.Next() return !rows.Next()
@ -84,13 +80,11 @@ type logAdapter struct {
} }
func (l *logAdapter) Fatal(v ...interface{}) { func (l *logAdapter) Fatal(v ...interface{}) {
log.Error(fmt.Sprint(v...)) log.Fatal(fmt.Sprint(v...))
os.Exit(-1)
} }
func (l *logAdapter) Fatalf(format string, v ...interface{}) { func (l *logAdapter) Fatalf(format string, v ...interface{}) {
log.Error(fmt.Sprintf(format, v...)) log.Fatal(fmt.Sprintf(format, v...))
os.Exit(-1)
} }
func (l *logAdapter) Print(v ...interface{}) { func (l *logAdapter) Print(v ...interface{}) {

View File

@ -12,7 +12,7 @@ import (
func TestDB(t *testing.T) { func TestDB(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "DB Suite") RunSpecs(t, "DB Suite")
} }

View File

@ -41,12 +41,12 @@ var redacted = &Hook{
} }
const ( const (
LevelCritical = Level(logrus.FatalLevel) // TODO Rename to LevelFatal LevelFatal = Level(logrus.FatalLevel)
LevelError = Level(logrus.ErrorLevel) LevelError = Level(logrus.ErrorLevel)
LevelWarn = Level(logrus.WarnLevel) LevelWarn = Level(logrus.WarnLevel)
LevelInfo = Level(logrus.InfoLevel) LevelInfo = Level(logrus.InfoLevel)
LevelDebug = Level(logrus.DebugLevel) LevelDebug = Level(logrus.DebugLevel)
LevelTrace = Level(logrus.TraceLevel) LevelTrace = Level(logrus.TraceLevel)
) )
type contextKey string type contextKey string
@ -82,8 +82,8 @@ func levelFromString(l string) Level {
envLevel := strings.ToLower(l) envLevel := strings.ToLower(l)
var level Level var level Level
switch envLevel { switch envLevel {
case "critical": case "fatal":
level = LevelCritical level = LevelFatal
case "error": case "error":
level = LevelError level = LevelError
case "warn": case "warn":
@ -147,7 +147,7 @@ func CurrentLevel() Level {
} }
func Fatal(args ...interface{}) { func Fatal(args ...interface{}) {
log(LevelCritical, args...) log(LevelFatal, args...)
os.Exit(1) os.Exit(1)
} }

View File

@ -167,9 +167,9 @@ var _ = Describe("Logger", func() {
}) })
Describe("SetLevelString", func() { Describe("SetLevelString", func() {
It("converts Critical level", func() { It("converts Fatal level", func() {
SetLevelString("Critical") SetLevelString("Fatal")
Expect(CurrentLevel()).To(Equal(LevelCritical)) Expect(CurrentLevel()).To(Equal(LevelFatal))
}) })
It("converts Error level", func() { It("converts Error level", func() {
SetLevelString("ERROR") SetLevelString("ERROR")

View File

@ -10,7 +10,7 @@ import (
) )
func TestCriteria(t *testing.T) { func TestCriteria(t *testing.T) {
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
gomega.RegisterFailHandler(Fail) gomega.RegisterFailHandler(Fail)
RunSpecs(t, "Criteria Suite") RunSpecs(t, "Criteria Suite")
} }

View File

@ -12,7 +12,7 @@ import (
func TestModel(t *testing.T) { func TestModel(t *testing.T) {
tests.Init(t, true) tests.Init(t, true)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Model Suite") RunSpecs(t, "Model Suite")
} }

View File

@ -16,7 +16,7 @@ var _ = Describe("SQLStore", func() {
BeforeEach(func() { BeforeEach(func() {
ds = New(db.Db()) ds = New(db.Db())
ctx = context.Background() ctx = context.Background()
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
}) })
AfterEach(func() { AfterEach(func() {
log.SetLevel(log.LevelError) log.SetLevel(log.LevelError)

View File

@ -11,7 +11,7 @@ import (
func TestFFMpeg(t *testing.T) { func TestFFMpeg(t *testing.T) {
tests.Init(t, true) tests.Init(t, true)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "FFMpeg Suite") RunSpecs(t, "FFMpeg Suite")
} }

View File

@ -11,7 +11,7 @@ import (
func TestMetadata(t *testing.T) { func TestMetadata(t *testing.T) {
tests.Init(t, true) tests.Init(t, true)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Metadata Suite") RunSpecs(t, "Metadata Suite")
} }

View File

@ -11,7 +11,7 @@ import (
func TestTagLib(t *testing.T) { func TestTagLib(t *testing.T) {
tests.Init(t, true) tests.Init(t, true)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "TagLib Suite") RunSpecs(t, "TagLib Suite")
} }

View File

@ -17,7 +17,7 @@ func TestScanner(t *testing.T) {
conf.Server.DbPath = "file::memory:?cache=shared" conf.Server.DbPath = "file::memory:?cache=shared"
_ = orm.RegisterDataBase("default", db.Driver, conf.Server.DbPath) _ = orm.RegisterDataBase("default", db.Driver, conf.Server.DbPath)
db.EnsureLatestVersion() db.EnsureLatestVersion()
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Scanner Suite") RunSpecs(t, "Scanner Suite")
} }

View File

@ -11,7 +11,7 @@ import (
func TestEvents(t *testing.T) { func TestEvents(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Events Suite") RunSpecs(t, "Events Suite")
} }

View File

@ -11,7 +11,7 @@ import (
func TestNativeApi(t *testing.T) { func TestNativeApi(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Native RESTful API Suite") RunSpecs(t, "Native RESTful API Suite")
} }

View File

@ -11,7 +11,7 @@ import (
func TestServer(t *testing.T) { func TestServer(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Server Suite") RunSpecs(t, "Server Suite")
} }

View File

@ -9,7 +9,7 @@ import (
) )
func TestSubsonicApi(t *testing.T) { func TestSubsonicApi(t *testing.T) {
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Subsonic API Suite") RunSpecs(t, "Subsonic API Suite")
} }

View File

@ -11,7 +11,7 @@ import (
func TestCache(t *testing.T) { func TestCache(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Cache Suite") RunSpecs(t, "Cache Suite")
} }

View File

@ -12,7 +12,7 @@ import (
func TestGravatar(t *testing.T) { func TestGravatar(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Gravatar Test Suite") RunSpecs(t, "Gravatar Test Suite")
} }

View File

@ -12,7 +12,7 @@ import (
func TestPool(t *testing.T) { func TestPool(t *testing.T) {
tests.Init(t, false) tests.Init(t, false)
log.SetLevel(log.LevelCritical) log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Pool Suite") RunSpecs(t, "Pool Suite")
} }