logger

package
v1.27.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2024 License: Apache-2.0 Imports: 20 Imported by: 130

Documentation

Index

Constants

View Source
const (
	Cyan = cyan + Normal

	Magenta   = magenta + Normal
	DarkWhite = "\x1b[38;5;244m"
	Normal    = "m"
	Reset     = "\x1b[0m"
)

Variables

View Source
var SkipFrameContains = []string{
	"gorm.io",
	"golang.org/toolchain",
}
View Source
var SkipFrameSuffixes = []string{
	"logger/slog.go",
	"logger/default.go",
	"logger/caller.go",
	"gorm/logger.go",
	"golang.org/toolchain",
}
View Source
var SlogFatal = slog.LevelError + 1
View Source
var SlogTraceLevel slog.Level = slog.LevelDebug - 1
View Source
var SlogTraceLevel1 slog.Level = SlogTraceLevel - 1
View Source
var SlogTraceLevel2 slog.Level = SlogTraceLevel - 2
View Source
var SlogTraceLevel3 slog.Level = SlogTraceLevel - 3
View Source
var SlogTraceLevel4 slog.Level = SlogTraceLevel - 4

Functions

func BindFlags added in v1.4.0

func BindFlags(flags *pflag.FlagSet)

func BindGoFlags added in v1.21.2

func BindGoFlags()

func BrightF added in v1.26.0

func BrightF(msg string, args ...interface{}) string

func Caller added in v1.26.0

func Caller(skip ...int) string

Caller return the file name and line number of the current file

func CallerPC added in v1.26.0

func CallerPC(skip ...int) uintptr

func Debugf

func Debugf(format string, args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func GetCaller added in v1.27.0

func GetCaller(pc ...uintptr) string

func GetNamedLoggingLevels added in v1.26.2

func GetNamedLoggingLevels() (levels map[string]string)

func Infof

func Infof(format string, args ...interface{})

func IsDebugEnabled

func IsDebugEnabled() bool

func IsJsonLogs added in v1.20.1

func IsJsonLogs() bool

func IsLevelEnabled added in v1.20.1

func IsLevelEnabled(level int) bool

func IsTraceEnabled

func IsTraceEnabled() bool

func Pretty added in v1.26.0

func Pretty(v any) string

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

func PrintableSecret(secret string) string

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 SetLogger added in v1.20.0

func SetLogger(logger Logger)

func Stacktrace added in v1.26.0

func Stacktrace() string

func StripSecrets added in v1.26.3

func StripSecrets(text string) string

StripSecrets takes a 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 Tracef

func Tracef(format string, args ...interface{})

func UseSlog added in v1.26.0

func UseSlog()

func Warnf

func Warnf(format string, args ...interface{})

Types

type LogLevel added in v1.26.0

type LogLevel int
const (
	Debug  LogLevel = 1
	Trace  LogLevel = 2
	Trace1 LogLevel = 3
	Trace2 LogLevel = 4
	Trace3 LogLevel = 5
	Trace4 LogLevel = 6
	Info   LogLevel = 0
	Warn   LogLevel = -1
	Error  LogLevel = -2
	Fatal  LogLevel = -3
	Silent LogLevel = 10
)

func FromSlogLevel added in v1.26.0

func FromSlogLevel(level slog.Level) LogLevel

func ParseLevel added in v1.26.0

func ParseLevel(logger Logger, level any) LogLevel

func (LogLevel) Slog added in v1.26.0

func (level LogLevel) Slog() slog.Level

func (LogLevel) String added in v1.27.0

func (l LogLevel) String() string

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) 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

type Verbose added in v1.5.1

type Verbose interface {
	Infof(format string, args ...interface{})
	Enabled() bool
}

func V added in v1.5.1

func V(level any) Verbose

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL