Documentation ¶
Index ¶
- Variables
- func Debug(text string) *golog.Message
- func DebugCtx(ctx context.Context, text string) *golog.Message
- func DebugWriter() *golog.LevelWriter
- func Debugf(format string, args ...any) *golog.Message
- func DebugfCtx(ctx context.Context, format string, args ...any) *golog.Message
- func Error(text string) *golog.Message
- func ErrorCtx(ctx context.Context, text string) *golog.Message
- func ErrorWriter() *golog.LevelWriter
- func Errorf(format string, args ...any) *golog.Message
- func ErrorfCtx(ctx context.Context, format string, args ...any) *golog.Message
- func Fatal(text string) *golog.Message
- func FatalAndPanic(p any)
- func FatalCtx(ctx context.Context, text string) *golog.Message
- func FatalWriter() *golog.LevelWriter
- func Fatalf(format string, args ...any) *golog.Message
- func FatalfCtx(ctx context.Context, format string, args ...any) *golog.Message
- func Flush()
- func HTTPMiddlewareFunc(level golog.Level, message string, onlyHeaders ...string) func(next http.Handler) http.Handler
- func HTTPMiddlewareHandler(next http.Handler, level golog.Level, message string, onlyHeaders ...string) http.Handler
- func Info(text string) *golog.Message
- func InfoCtx(ctx context.Context, text string) *golog.Message
- func InfoWriter() *golog.LevelWriter
- func Infof(format string, args ...any) *golog.Message
- func InfofCtx(ctx context.Context, format string, args ...any) *golog.Message
- func NewLevelWriter(level golog.Level) *golog.LevelWriter
- func NewMessage(ctx context.Context, level golog.Level, text string) *golog.Message
- func NewMessageAt(ctx context.Context, t time.Time, level golog.Level, text string) *golog.Message
- func NewMessagef(ctx context.Context, level golog.Level, format string, args ...any) *golog.Message
- func NewPackageLogger(pkgName string, filters ...golog.LevelFilter) *golog.Logger
- func NewStyledColorizer() *golog.StyledColorizer
- func Trace(text string) *golog.Message
- func TraceCtx(ctx context.Context, text string) *golog.Message
- func TraceWriter() *golog.LevelWriter
- func Tracef(format string, args ...any) *golog.Message
- func TracefCtx(ctx context.Context, format string, args ...any) *golog.Message
- func Warn(text string) *golog.Message
- func WarnCtx(ctx context.Context, text string) *golog.Message
- func WarnWriter() *golog.LevelWriter
- func Warnf(format string, args ...any) *golog.Message
- func WarnfCtx(ctx context.Context, format string, args ...any) *golog.Message
- func With() *golog.Message
- func WithCtx(ctx context.Context) *golog.Logger
- func WithLevelFilter(filter golog.LevelFilter) *golog.Logger
- func WithPrefix(prefix string) *golog.Logger
- func WithValues(values ...golog.Attrib) *golog.Logger
Constants ¶
This section is empty.
Variables ¶
var ( // Levels are the default log levels. Levels = &golog.DefaultLevels // Format is the default log message format. Format = *golog.NewDefaultFormat() // Colorizer is the default log message colorizer. Colorizer = *NewStyledColorizer() // Config is the default log configuration. Config = golog.NewConfig( Levels, Levels.LevelOfNameOrDefault(os.Getenv("LOG_LEVEL"), Levels.Debug).FilterOutBelow(), golog.NewTextWriterConfig(os.Stdout, &Format, &Colorizer), ) // Logger uses a golog.DerivedConfig referencing the // exported package variable Config. // This way Config can be changed after initialization of Logger // without the need to create and set a new golog.Logger. Logger = golog.NewLogger(golog.NewDerivedConfig(&Config)) )
Defaults
var ( // PackageRegistry holds package logger configurations. // See NewPackageLogger PackageRegistry golog.Registry // AddImportPathToPackageLogger controls weather the package import path // will be logged as value "pkg" with every package logger message. AddImportPathToPackageLogger = false )
Functions ¶
func DebugWriter ¶
func DebugWriter() *golog.LevelWriter
func ErrorWriter ¶
func ErrorWriter() *golog.LevelWriter
func FatalAndPanic ¶
func FatalAndPanic(p any)
FatalAndPanic is a shortcut for Fatal(fmt.Sprint(p)).LogAndPanic()
func FatalWriter ¶
func FatalWriter() *golog.LevelWriter
func HTTPMiddlewareFunc ¶
func HTTPMiddlewareFunc(level golog.Level, message string, onlyHeaders ...string) func(next http.Handler) http.Handler
HTTPMiddlewareFunc returns a HTTP middleware function that passes through a UUID requestID. The requestID will be added as UUID golog.Attrib to the http.Request before calling the next handler. If available the X-Request-ID or X-Correlation-ID HTTP request header will be used as requestID. It has to be a valid UUID in the format "994d5800-afca-401f-9c2f-d9e3e106e9ef". If the request has no requestID, then a random v4 UUID will be used. The requestID will also be set at the http.ResponseWriter as X-Request-ID header before calling the next handler, which has a chance to change it. If onlyHeaders are passed then only those headers are logged if available, or pass golog.HTTPNoHeaders to disable header logging. To disable logging of the request at all and just pass through the requestID pass golog.LevelInvalid as log level. Compatible with github.com/gorilla/mux.MiddlewareFunc. See also HTTPMiddlewareHandler.
func HTTPMiddlewareHandler ¶
func HTTPMiddlewareHandler(next http.Handler, level golog.Level, message string, onlyHeaders ...string) http.Handler
HTTPMiddlewareHandler returns a HTTP middleware handler that passes through a UUID requestID. The requestID will be added as UUID golog.Attrib to the http.Request before calling the next handler. If available the X-Request-ID or X-Correlation-ID HTTP request header will be used as requestID. It has to be a valid UUID in the format "994d5800-afca-401f-9c2f-d9e3e106e9ef". If the request has no requestID, then a random v4 UUID will be used. The requestID will also be set at the http.ResponseWriter as X-Request-ID header before calling the next handler, which has a chance to change it. If onlyHeaders are passed then only those headers are logged if available, or pass golog.HTTPNoHeaders to disable header logging. To disable logging of the request at all and just pass through the requestID pass golog.LevelInvalid as log level. See also HTTPMiddlewareFunc.
func InfoWriter ¶
func InfoWriter() *golog.LevelWriter
func NewLevelWriter ¶
func NewLevelWriter(level golog.Level) *golog.LevelWriter
func NewMessage ¶
NewMessage starts a new message
func NewMessageAt ¶
NewMessageAt starts a new message logged with the time t
func NewMessagef ¶
NewMessagef starts a new message formatted using fmt.Sprintf
func NewPackageLogger ¶
func NewPackageLogger(pkgName string, filters ...golog.LevelFilter) *golog.Logger
NewPackageLogger creates a logger for a package where every log message will be prefixed with pkgName. Note that pkgName is the name, not the import path of the package. It still has to be unique for all package loggers because the logger config is added to PackageRegistry by pkgName. The PackageRegistry can be used to change package logging configurations at runtime. If any filters are passed then they take precedence before the parent Config filter. But if an environment variable "LOG_LEVEL_PKG_" + pkgName is defined with a valid log level name, then this log level will be used as filter, instead of anything passed for filters. If AddImportPathToPackageLogger is true, then the package import path will be logged as value "pkg" with every message.
func NewStyledColorizer ¶
func NewStyledColorizer() *golog.StyledColorizer
NewStyledColorizer creates a new golog.StyledColorizer. Supports NO_COLOR (https://no-color.org/) and CLICOLOR/CLICOLOR_FORCE (https://bixense.com/clicolors/)
func TraceWriter ¶
func TraceWriter() *golog.LevelWriter
func WarnWriter ¶
func WarnWriter() *golog.LevelWriter
func With ¶
With returns a new Message that can be used to record the prefix for a sub-logger.
Example:
log := log.With().UUID("requestID", requestID).SubLogger()
func WithCtx ¶
WithCtx returns a new golog.Logger with the PerMessageValues from a context logger appended to this package's Logger.
func WithLevelFilter ¶
func WithLevelFilter(filter golog.LevelFilter) *golog.Logger
func WithPrefix ¶
Types ¶
This section is empty.