Documentation ¶
Index ¶
- Constants
- func Add(args ...Arg)
- func Debug(args ...Arg)
- func Error(err error, args ...Arg) bool
- func Info(args ...Arg)
- func Log(level Level, args ...Arg)
- func Reset()
- func SetLevel(level Level)
- func Warn(args ...Arg)
- type Arg
- func AddSkip(skip int) Arg
- func Bool(key string, value bool) Arg
- func Caller(key string, skip int) Arg
- func Duration(key string, v time.Duration) Arg
- func Err(err error) Arg
- func Float[N constraints.Float](key string, value N) Arg
- func IfDebug(producer _Producer) Arg
- func Int[N constraints.Integer](key string, value N) Arg
- func KeyValue(key, value string) Arg
- func Msg(format string, i ...any) Arg
- func Prefix(prefix string) Arg
- func Producer(fn func() Arg) Arg
- func Skip() Arg
- func String(key, value string) Arg
- func Time(key string, v time.Time) Arg
- func WithLevel(level Level) Arg
- func WithWriter(w io.Writer) Arg
- type Level
- type Logger
- func (l *Logger) Debug(args ...Arg)
- func (l *Logger) Error(err error, args ...Arg) bool
- func (l *Logger) GetLevel() Level
- func (l *Logger) Info(args ...Arg)
- func (l *Logger) Log(level Level, args ...Arg)
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) Warn(args ...Arg)
- func (l *Logger) With(args ...Arg) *Logger
- type Option
Constants ¶
const DebugCallerKey = "loc"
const ErrorKey = "error"
const LevelKey = "level"
const MsgKey = "msg"
const PrefixKey = "prefix"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Arg ¶
type Arg interface {
// contains filtered or unexported methods
}
Arg is something that can be printed in a log message or used to control its output.
func AddSkip ¶
AddSkip increments the skip value of a call to a log function. The log functions only call skip with the key DebugCallerKey when the Level LevelDebug is valid.
func Caller ¶
Caller creates a caller Arg with the given skip. skip == 0 represents the caller of Caller.
func Duration ¶
Duration is a key=value pair with a value as the unquoted output of time.Duration.String.
func Float ¶
func Float[N constraints.Float](key string, value N) Arg
Float is a key=value pair with a given float value.
func IfDebug ¶
func IfDebug(producer _Producer) Arg
IfDebug is for a func that produces an Arg when LevelDebug is valid. producer is only called if LevelDebug is valid.
func Int ¶
func Int[N constraints.Integer](key string, value N) Arg
Int is a key=value pair with a given integer value.
func Msg ¶
Msg is a trimmed and quoted message with the key MsgKey. Only the most recent given Msg will be used.
func String ¶
String creates a key=value pair with value being a string quoted with strconv.Quote.
func Time ¶
Time is a key=value pair with a value as the unquoted output of time.Time.Format with the format of time.RFC3339.
func WithLevel ¶
WithLevel creates a new shared level for this logger and child loggers until WithLevel is used again with Logger.With.
func WithWriter ¶
WithWriter sets the writer of Logger. The writer is shared with all children until Logger.With is called with [WithNewWriter]. Each write to the writer is locked until the message completes, errors are ignored. Default value is os.Stdout. If w is nil, os.Stdout will be used. Change the value of an existing logger with [WithNewWriter].
type Level ¶
type Level uint8
Level is the level to print log messages at.
const ( // LevelAll prints at all levels. LevelAll Level = iota // LevelDebug should be only used in dev. // Adds file and line number of log call to output. LevelDebug // LevelInfo verbose logging. LevelInfo // LevelWarn only warning and errors are printed. LevelWarn // LevelError only errors are printed. LevelError // LevelNone nothing is printed. LevelNone )
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger can be used to print a structured log to an output. All logging is done to a single output.
func (*Logger) Error ¶
Error logs a message at LevelError.