Use internal log package to avoid breaking programs that have their own global loggers
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Elara 2023-09-20 15:33:26 -07:00
parent cf8d08574f
commit 6388180768
22 changed files with 105 additions and 21 deletions

View File

@ -23,7 +23,7 @@ import (
"path/filepath"
"github.com/urfave/cli/v2"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/build"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/osutils"

View File

@ -26,7 +26,7 @@ import (
"strings"
"github.com/twitchtv/twirp"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/api"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"

View File

@ -28,7 +28,7 @@ import (
"github.com/go-chi/chi/v5"
"github.com/twitchtv/twirp"
"go.elara.ws/logger"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/api"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/repos"

View File

@ -29,7 +29,7 @@ import (
"os"
"strings"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/repos"
)

2
fix.go
View File

@ -22,7 +22,7 @@ import (
"os"
"github.com/urfave/cli/v2"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/repos"

View File

@ -22,7 +22,7 @@ import (
"fmt"
"os"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"github.com/urfave/cli/v2"
"go.elara.ws/lure/distro"

View File

@ -22,7 +22,7 @@ import (
"fmt"
"github.com/urfave/cli/v2"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/build"
"go.elara.ws/lure/internal/cliutils"
"go.elara.ws/lure/internal/config"

View File

@ -20,7 +20,7 @@ import (
"github.com/goreleaser/nfpm/v2"
"github.com/goreleaser/nfpm/v2/files"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/distro"
"go.elara.ws/lure/internal/cliutils"
"go.elara.ws/lure/internal/config"

View File

@ -4,7 +4,7 @@ import (
"context"
"path/filepath"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/types"

View File

@ -22,7 +22,7 @@ import (
"os"
"github.com/AlecAivazis/survey/v2"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/pager"

View File

@ -22,7 +22,7 @@ import (
"os"
"github.com/pelletier/go-toml/v2"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/types"
)

View File

@ -23,7 +23,7 @@ import (
"path/filepath"
"github.com/pelletier/go-toml/v2"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
)
type Paths struct {

View File

@ -22,7 +22,7 @@ import (
"os"
"strings"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"golang.org/x/text/language"
)

View File

@ -27,7 +27,7 @@ import (
"os"
"github.com/jmoiron/sqlx"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/config"
"golang.org/x/exp/slices"
"modernc.org/sqlite"

View File

@ -36,7 +36,7 @@ import (
"github.com/PuerkitoBio/purell"
"github.com/vmihailenco/msgpack/v5"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/dlcache"
"golang.org/x/exp/slices"
)

84
internal/log/log.go Normal file
View File

@ -0,0 +1,84 @@
package log
import (
"os"
"go.elara.ws/logger"
)
var Logger logger.Logger = logger.NewCLI(os.Stderr)
// NoPanic prevents the logger from panicking on panic events
func NoPanic() {
Logger.NoPanic()
}
// NoExit prevents the logger from exiting on fatal events
func NoExit() {
Logger.NoExit()
}
// SetLevel sets the log level of the logger
func SetLevel(l logger.LogLevel) {
Logger.SetLevel(l)
}
// Debug creates a new debug event with the given message
func Debug(msg string) logger.LogBuilder {
return Logger.Debug(msg)
}
// Debugf creates a new debug event with the formatted message
func Debugf(format string, v ...any) logger.LogBuilder {
return Logger.Debugf(format, v...)
}
// Info creates a new info event with the given message
func Info(msg string) logger.LogBuilder {
return Logger.Info(msg)
}
// Infof creates a new info event with the formatted message
func Infof(format string, v ...any) logger.LogBuilder {
return Logger.Infof(format, v...)
}
// Warn creates a new warn event with the given message
func Warn(msg string) logger.LogBuilder {
return Logger.Warn(msg)
}
// Warnf creates a new warn event with the formatted message
func Warnf(format string, v ...any) logger.LogBuilder {
return Logger.Warnf(format, v...)
}
// Error creates a new error event with the given message
func Error(msg string) logger.LogBuilder {
return Logger.Error(msg)
}
// Errorf creates a new error event with the formatted message
func Errorf(format string, v ...any) logger.LogBuilder {
return Logger.Errorf(format, v...)
}
// Fatal creates a new fatal event with the given message
func Fatal(msg string) logger.LogBuilder {
return Logger.Fatal(msg)
}
// Fatalf creates a new fatal event with the formatted message
func Fatalf(format string, v ...any) logger.LogBuilder {
return Logger.Fatalf(format, v...)
}
// Fatal creates a new fatal event with the given message
func Panic(msg string) logger.LogBuilder {
return Logger.Panic(msg)
}
// Fatalf creates a new fatal event with the formatted message
func Panicf(format string, v ...any) logger.LogBuilder {
return Logger.Panicf(format, v...)
}

View File

@ -34,7 +34,7 @@ import (
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/format/diff"
"github.com/pelletier/go-toml/v2"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/distro"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"

View File

@ -4,7 +4,7 @@ import (
"embed"
"go.elara.ws/logger"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/translate"
"golang.org/x/text/language"
)

View File

@ -22,7 +22,7 @@ import (
"fmt"
"github.com/urfave/cli/v2"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/repos"

View File

@ -28,9 +28,9 @@ import (
"github.com/mattn/go-isatty"
"github.com/urfave/cli/v2"
"go.elara.ws/logger"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/translations"
"go.elara.ws/lure/manager"
)

View File

@ -24,7 +24,7 @@ import (
"github.com/pelletier/go-toml/v2"
"github.com/urfave/cli/v2"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/internal/config"
"go.elara.ws/lure/internal/db"
"go.elara.ws/lure/internal/repos"

View File

@ -23,7 +23,7 @@ import (
"fmt"
"github.com/urfave/cli/v2"
"go.elara.ws/logger/log"
"go.elara.ws/lure/internal/log"
"go.elara.ws/lure/distro"
"go.elara.ws/lure/internal/build"
"go.elara.ws/lure/internal/config"