Documentation
¶
Index ¶
- Constants
- Variables
- type Attr
- type Formatter
- type Level
- type Logger
- func (l *Logger) AddTags(tags ...string)
- func (l *Logger) Debug(v ...any)
- func (l *Logger) Debugf(format string, v ...any)
- func (l *Logger) Error(v ...any)
- func (l *Logger) Errorf(format string, v ...any)
- func (l *Logger) Fatal(v ...any)
- func (l *Logger) Fatalf(format string, v ...any)
- func (l *Logger) Flag() int
- func (l *Logger) Info(v ...any)
- func (l *Logger) Infof(format string, v ...any)
- func (l *Logger) Level() Level
- func (l *Logger) Log(ctx context.Context, slogLevel slog.Level, msg string, args ...any)
- func (l *Logger) LogAttrs(ctx context.Context, slogLevel slog.Level, msg string, slogAttrs ...slog.Attr)
- func (l *Logger) New(tags ...string) *Logger
- func (l *Logger) NewJsonLogger(attrs ...Attr) StructLogger
- func (l *Logger) NewTextLogger(attrs ...Attr) StructLogger
- func (l *Logger) Output(level Level, msg string) error
- func (l *Logger) Panic(v ...any)
- func (l *Logger) Panicf(format string, v ...any)
- func (l *Logger) Print(v ...any)
- func (l *Logger) Printf(format string, v ...any)
- func (l *Logger) SetColor(colorful bool)
- func (l *Logger) SetFlag(flag int)
- func (l *Logger) SetLevel(level Level) error
- func (l *Logger) SetLevelByName(name string) error
- func (l *Logger) SetOutput(w io.Writer)
- func (l *Logger) SetSkip(depth int)
- func (l *Logger) SetTags(tags ...string)
- func (l *Logger) Skip() int
- func (l *Logger) Tags() []string
- func (l *Logger) Trace(v ...any)
- func (l *Logger) Warn(v ...any)
- func (l *Logger) Warnf(format string, v ...any)
- func (l *Logger) Write(b []byte) (int, error)
- type StructLogger
Constants ¶
const ( LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarn = slog.LevelWarn LevelError = slog.LevelError )
Variables ¶
var (
ErrLevel = errors.New("Invalid level")
)
Functions ¶
This section is empty.
Types ¶
type Attr ¶
type Attr func(as *attrs)
Attr for fields option
type Level ¶
type Level int
const ( Ldebug Level Linfo Lwarn Lerror Lfatal Lpanic Ltrace Llog )
func ResolveLevelByName ¶
Resolves level by name, returns lmin without definition by default
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func New ¶
New creates a logger with the requested output. (default to stderr) NOTE: available outputs are [stdout|stderr|null|nil|path/to/file]
func (*Logger) Debug ¶
Debug calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Print.
func (*Logger) Debugf ¶
Debugf calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Error ¶
Error calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Print.
func (*Logger) Errorf ¶
Errorf calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Fatal ¶
Fatal calls l.Output to print to the logger and exit process with sign 1. Arguments are handled in the manner of fmt.Print.
func (*Logger) Fatalf ¶
Fatalf calls l.Output to print to the logger and exit process with sign 1. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Info ¶
Info calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Print.
func (*Logger) Infof ¶
Infof calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Printf.
func (*Logger) LogAttrs ¶ added in v1.5.0
func (l *Logger) LogAttrs(ctx context.Context, slogLevel slog.Level, msg string, slogAttrs ...slog.Attr)
LogAttrs drops in of slog.LogAttrs
func (*Logger) NewJsonLogger ¶
func (l *Logger) NewJsonLogger(attrs ...Attr) StructLogger
NewJsonLogger returns a new StructLogger with json formatter.
func (*Logger) NewTextLogger ¶
func (l *Logger) NewTextLogger(attrs ...Attr) StructLogger
NewTextLogger returns a new StructLogger with text formatter.
func (*Logger) Output ¶
Output writes the output for a logging event. The string s contains the text to print after the tags specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline.
func (*Logger) Panic ¶
Panic calls l.Output to print to the logger and panic process. Arguments are handled in the manner of fmt.Print.
func (*Logger) Panicf ¶
Panicf calls l.Output to print to the logger and panic process. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Print ¶
Print calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Print.
func (*Logger) Printf ¶
Printf calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Printf.
func (*Logger) SetLevelByName ¶
SetLevelByName sets min level of output by name, available values are [debug|info|warn|error|fatal|panic|stack]. It returns ErrLevel for invalid name.
func (*Logger) Trace ¶
Trace calls l.Output to print to the logger and output process stacks, and exit process with sign 1 at last. Arguments are handled in the manner of fmt.Print.
func (*Logger) Warn ¶
Warn calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Print.
type StructLogger ¶
type StructLogger interface {
Str(key, value string) StructLogger
Bool(key string, value bool) StructLogger
Duration(key string, value time.Duration) StructLogger
Time(key string, value time.Time) StructLogger
Err(err error, stack bool) StructLogger
Any(key string, value any) StructLogger
Fields(fields map[string]any) StructLogger
Debug(msg string)
Debugf(format string, args ...any)
Info(msg string)
Infof(format string, args ...any)
Warn(msg string)
Warnf(format string, args ...any)
Error(msg string)
Errorf(format string, args ...any)
Fatal(msg string)
Fatalf(format string, args ...any)
Panic(msg string)
Panicf(format string, args ...any)
}
StructLogger for well formatted