Documentation ¶
Index ¶
- Constants
- Variables
- func BindFlags(flags *pflag.FlagSet)
- func BrightF(msg string, args ...interface{}) string
- func Caller(skip ...int) string
- func CallerPC(skip ...int) uintptr
- func Debugf(format string, args ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatalf(format string, args ...interface{})
- func GetCaller(pc ...uintptr) string
- func GetNamedLoggingLevels() (levels map[string]string)
- func Infof(format string, args ...interface{})
- func IsDebugEnabled() bool
- func IsJsonLogs() bool
- func IsLevelEnabled(level int) bool
- func IsSensitiveKey(v string) bool
- func IsTraceEnabled() bool
- func NewHttpLogger(logger Logger, rt http.RoundTripper) http.RoundTripper
- func Pretty(v any) string
- func PrettyYAML(s string) string
- func Prettyf(msg string, obj interface{})
- func PrintableSecret(secret string) string
- func SanitizeHeaders(headers http.Header, redactedHeaders ...string) http.Header
- func Secretf(format string, args ...interface{})
- func SetLogger(logger Logger)
- func Stacktrace() string
- func StripSecrets(text string) string
- func StripSecretsFromMap[V comparable](m map[string]V) map[string]any
- func Tracef(format string, args ...interface{})
- func UseSlog()
- func Warnf(format string, args ...interface{})
- type LogLevel
- type Logger
- type SlogLogger
- func (s SlogLogger) DebugLevels()
- func (s SlogLogger) Debugf(format string, args ...interface{})
- func (s SlogLogger) Errorf(format string, args ...interface{})
- func (s SlogLogger) Fatalf(format string, args ...interface{})
- func (s SlogLogger) GetLevel() LogLevel
- func (s SlogLogger) GetSlogLogger() *slog.Logger
- func (s SlogLogger) Infof(format string, args ...interface{})
- func (s SlogLogger) IsDebugEnabled() bool
- func (s SlogLogger) IsLevelEnabled(level LogLevel) bool
- func (s SlogLogger) IsTraceEnabled() bool
- func (s SlogLogger) Named(name string) Logger
- func (s SlogLogger) Prettyf(msg string, obj interface{})
- func (s SlogLogger) Secretf(format string, args ...interface{})
- func (s SlogLogger) SetLogLevel(level any)
- func (s SlogLogger) SetMinLogLevel(level any)
- func (s SlogLogger) Tracef(format string, args ...interface{})
- func (s SlogLogger) V(level any) Verbose
- func (s SlogLogger) Warnf(format string, args ...interface{})
- func (s SlogLogger) WithSkipReportLevel(i int) Logger
- func (s SlogLogger) WithV(level any) Logger
- func (s SlogLogger) WithValues(keysAndValues ...interface{}) Logger
- func (s SlogLogger) WithoutName() Logger
- type Verbose
Constants ¶
const ( Cyan = cyan + Normal Magenta = magenta + Normal DarkWhite = "\x1b[38;5;244m" Normal = "m" Reset = "\x1b[0m" )
Variables ¶
var CommonRedactedHeaders = []string{
"Authorization*", "Bearer*", "Session*", "*Cookie", "*Token", "*-Secret", "*-Key",
"Password", "Passwd", "Pwd",
}
var SensitiveHeaders = []string{
"Authorization",
"Set-Cookie",
"Cookie",
"Proxy-Authorization",
"Cookie",
}
var SensitiveKeys = []string{"user", "pass", "key", "token", "username", "password"}
var SkipFrameContains = []string{
"gorm.io",
"golang.org/toolchain",
}
var SkipFrameSuffixes = []string{
"logger/slog.go",
"logger/default.go",
"logger/caller.go",
"gorm/logger.go",
"golang.org/toolchain",
}
var SlogFatal = slog.LevelError + 1
var SlogTraceLevel slog.Level = slog.LevelDebug - 1
Functions ¶
func BindFlags ¶ added in v1.4.0
BindFlags add flags to an existing flag set, note that this is not an actual binding which occurs later during initialization
func GetNamedLoggingLevels ¶ added in v1.26.2
func IsDebugEnabled ¶
func IsDebugEnabled() bool
func IsJsonLogs ¶ added in v1.20.1
func IsJsonLogs() bool
func IsLevelEnabled ¶ added in v1.20.1
func IsSensitiveKey ¶ added in v1.30.0
func IsTraceEnabled ¶
func IsTraceEnabled() bool
func NewHttpLogger ¶ added in v1.29.0
func NewHttpLogger(logger Logger, rt http.RoundTripper) http.RoundTripper
func PrettyYAML ¶ added in v1.30.5
func Prettyf ¶ added in v1.3.0
func Prettyf(msg string, obj interface{})
Prettyf is like Tracef, but pretty prints the entire struct
func PrintableSecret ¶ added in v1.26.3
PrintableSecret returns an approximation of a secret, so that it is possible to compare the secrets rudimentally e.g. for "john-doe-jane" it will return ***e Secrets smaller than 10 characters will always return *** These secrets
func SanitizeHeaders ¶ added in v1.29.0
func Secretf ¶ added in v1.3.0
func Secretf(format string, args ...interface{})
Secretf is like Tracef, but attempts to strip any secrets from the text
func Stacktrace ¶ added in v1.26.0
func Stacktrace() string
func StripSecrets ¶ added in v1.26.3
StripSecrets takes a URL, YAML or INI formatted text and removes any potentially secret data as denoted by keys containing "pass" or "secret" or exact matches for "key" the last character of the secret is kept to aid in troubleshooting
func StripSecretsFromMap ¶ added in v1.30.5
func StripSecretsFromMap[V comparable](m map[string]V) map[string]any
Types ¶
type LogLevel ¶ added in v1.26.0
type LogLevel int
func FromSlogLevel ¶ added in v1.26.0
func ParseLevel ¶ added in v1.26.0
type Logger ¶
type Logger interface { Warnf(format string, args ...interface{}) Infof(format string, args ...interface{}) Errorf(format string, args ...interface{}) Debugf(format string, args ...interface{}) Tracef(format string, args ...interface{}) Fatalf(format string, args ...interface{}) WithValues(keysAndValues ...interface{}) Logger IsTraceEnabled() bool IsDebugEnabled() bool IsLevelEnabled(level LogLevel) bool GetLevel() LogLevel SetLogLevel(level any) SetMinLogLevel(level any) V(level any) Verbose WithV(level any) Logger Named(name string) Logger WithoutName() Logger WithSkipReportLevel(i int) Logger GetSlogLogger() *slog.Logger }
func StandardLogger ¶
func StandardLogger() Logger
func WithValues ¶ added in v1.4.2
func WithValues(keysAndValues ...interface{}) Logger
type SlogLogger ¶ added in v1.26.0
type SlogLogger struct { *slog.Logger Prefix string Level *slog.LevelVar Parent *SlogLogger // contains filtered or unexported fields }
func GetLogger ¶ added in v1.26.0
func GetLogger(names ...string) *SlogLogger
func GetSlogLogger ¶ added in v1.26.0
func GetSlogLogger() SlogLogger
func New ¶ added in v1.26.0
func New(prefix string) *SlogLogger
func (SlogLogger) DebugLevels ¶ added in v1.28.0
func (s SlogLogger) DebugLevels()
func (SlogLogger) Debugf ¶ added in v1.26.0
func (s SlogLogger) Debugf(format string, args ...interface{})
func (SlogLogger) Errorf ¶ added in v1.26.0
func (s SlogLogger) Errorf(format string, args ...interface{})
func (SlogLogger) Fatalf ¶ added in v1.26.0
func (s SlogLogger) Fatalf(format string, args ...interface{})
func (SlogLogger) GetLevel ¶ added in v1.26.0
func (s SlogLogger) GetLevel() LogLevel
func (SlogLogger) GetSlogLogger ¶ added in v1.26.0
func (s SlogLogger) GetSlogLogger() *slog.Logger
func (SlogLogger) Infof ¶ added in v1.26.0
func (s SlogLogger) Infof(format string, args ...interface{})
func (SlogLogger) IsDebugEnabled ¶ added in v1.26.0
func (s SlogLogger) IsDebugEnabled() bool
func (SlogLogger) IsLevelEnabled ¶ added in v1.26.0
func (s SlogLogger) IsLevelEnabled(level LogLevel) bool
func (SlogLogger) IsTraceEnabled ¶ added in v1.26.0
func (s SlogLogger) IsTraceEnabled() bool
func (SlogLogger) Named ¶ added in v1.26.0
func (s SlogLogger) Named(name string) Logger
func (SlogLogger) Prettyf ¶ added in v1.26.0
func (s SlogLogger) Prettyf(msg string, obj interface{})
func (SlogLogger) Secretf ¶ added in v1.26.0
func (s SlogLogger) Secretf(format string, args ...interface{})
func (SlogLogger) SetLogLevel ¶ added in v1.26.0
func (s SlogLogger) SetLogLevel(level any)
func (SlogLogger) SetMinLogLevel ¶ added in v1.26.0
func (s SlogLogger) SetMinLogLevel(level any)
func (SlogLogger) Tracef ¶ added in v1.26.0
func (s SlogLogger) Tracef(format string, args ...interface{})
func (SlogLogger) V ¶ added in v1.26.0
func (s SlogLogger) V(level any) Verbose
func (SlogLogger) Warnf ¶ added in v1.26.0
func (s SlogLogger) Warnf(format string, args ...interface{})
func (SlogLogger) WithSkipReportLevel ¶ added in v1.26.0
func (s SlogLogger) WithSkipReportLevel(i int) Logger
func (SlogLogger) WithV ¶ added in v1.26.0
func (s SlogLogger) WithV(level any) Logger
func (SlogLogger) WithValues ¶ added in v1.26.0
func (s SlogLogger) WithValues(keysAndValues ...interface{}) Logger
func (SlogLogger) WithoutName ¶ added in v1.26.0
func (s SlogLogger) WithoutName() Logger