mirror of
https://github.com/stashapp/stash.git
synced 2025-12-13 11:52:46 +01:00
* Upgrade gqlgen to v0.17.2 This enables builds on Go 1.18. github.com/vektah/gqlparser is upgraded to the newest version too. Getting this to work is a bit of a hazzle. I had to first remove vendoring from the repository, perform the upgrade and then re-introduce the vendor directory. I think gqlgens analysis went wrong for some reason on the upgrade. It would seem a clean-room installation fixed it. * Bump project to 1.18 * Update all packages, address gqlgenc breaking changes * Let `go mod tidy` handle the go.mod file * Upgrade linter to 1.45.2 * Introduce v1.45.2 of the linter The linter now correctly warns on `strings.Title` because it isn't unicode-aware. Fix this by using the suggested fix from x/text/cases to produce unicode-aware strings. The mapping isn't entirely 1-1 as this new approach has a larger iface: it spans all of unicode rather than just ASCII. It coincides for ASCII however, so things should be largely the same. * Ready ourselves for errchkjson and contextcheck. * Revert dockerfile golang version changes for now Co-authored-by: Kermie <kermie@isinthe.house> Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
131 lines
3.5 KiB
Go
131 lines
3.5 KiB
Go
// Package log provides a global logger for zerolog.
|
|
package log
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/rs/zerolog"
|
|
)
|
|
|
|
// Logger is the global logger.
|
|
var Logger = zerolog.New(os.Stderr).With().Timestamp().Logger()
|
|
|
|
// Output duplicates the global logger and sets w as its output.
|
|
func Output(w io.Writer) zerolog.Logger {
|
|
return Logger.Output(w)
|
|
}
|
|
|
|
// With creates a child logger with the field added to its context.
|
|
func With() zerolog.Context {
|
|
return Logger.With()
|
|
}
|
|
|
|
// Level creates a child logger with the minimum accepted level set to level.
|
|
func Level(level zerolog.Level) zerolog.Logger {
|
|
return Logger.Level(level)
|
|
}
|
|
|
|
// Sample returns a logger with the s sampler.
|
|
func Sample(s zerolog.Sampler) zerolog.Logger {
|
|
return Logger.Sample(s)
|
|
}
|
|
|
|
// Hook returns a logger with the h Hook.
|
|
func Hook(h zerolog.Hook) zerolog.Logger {
|
|
return Logger.Hook(h)
|
|
}
|
|
|
|
// Err starts a new message with error level with err as a field if not nil or
|
|
// with info level if err is nil.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Err(err error) *zerolog.Event {
|
|
return Logger.Err(err)
|
|
}
|
|
|
|
// Trace starts a new message with trace level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Trace() *zerolog.Event {
|
|
return Logger.Trace()
|
|
}
|
|
|
|
// Debug starts a new message with debug level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Debug() *zerolog.Event {
|
|
return Logger.Debug()
|
|
}
|
|
|
|
// Info starts a new message with info level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Info() *zerolog.Event {
|
|
return Logger.Info()
|
|
}
|
|
|
|
// Warn starts a new message with warn level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Warn() *zerolog.Event {
|
|
return Logger.Warn()
|
|
}
|
|
|
|
// Error starts a new message with error level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Error() *zerolog.Event {
|
|
return Logger.Error()
|
|
}
|
|
|
|
// Fatal starts a new message with fatal level. The os.Exit(1) function
|
|
// is called by the Msg method.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Fatal() *zerolog.Event {
|
|
return Logger.Fatal()
|
|
}
|
|
|
|
// Panic starts a new message with panic level. The message is also sent
|
|
// to the panic function.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Panic() *zerolog.Event {
|
|
return Logger.Panic()
|
|
}
|
|
|
|
// WithLevel starts a new message with level.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func WithLevel(level zerolog.Level) *zerolog.Event {
|
|
return Logger.WithLevel(level)
|
|
}
|
|
|
|
// Log starts a new message with no level. Setting zerolog.GlobalLevel to
|
|
// zerolog.Disabled will still disable events produced by this method.
|
|
//
|
|
// You must call Msg on the returned event in order to send the event.
|
|
func Log() *zerolog.Event {
|
|
return Logger.Log()
|
|
}
|
|
|
|
// Print sends a log event using debug level and no extra field.
|
|
// Arguments are handled in the manner of fmt.Print.
|
|
func Print(v ...interface{}) {
|
|
Logger.Debug().CallerSkipFrame(1).Msg(fmt.Sprint(v...))
|
|
}
|
|
|
|
// Printf sends a log event using debug level and no extra field.
|
|
// Arguments are handled in the manner of fmt.Printf.
|
|
func Printf(format string, v ...interface{}) {
|
|
Logger.Debug().CallerSkipFrame(1).Msgf(format, v...)
|
|
}
|
|
|
|
// Ctx returns the Logger associated with the ctx. If no logger
|
|
// is associated, a disabled logger is returned.
|
|
func Ctx(ctx context.Context) *zerolog.Logger {
|
|
return zerolog.Ctx(ctx)
|
|
}
|