Documentation ¶
Index ¶
- Constants
- func Debug(a ...any)
- func Debugf(format string, a ...any)
- func Error(a ...any)
- func ErrorAt(err error, a ...any) error
- func ErrorAtf(err error, format string, a ...any) error
- func Errorf(format string, a ...any)
- func Fatal(a ...any)
- func Fatalf(format string, a ...any)
- func GetWriter(level Level) io.Writer
- func Info(a ...any)
- func Infof(format string, a ...any)
- func Panic(a ...any)
- func Panicf(format string, a ...any)
- func Print(a ...any)
- func Printf(format string, a ...any)
- func Println(a ...any)
- func Printlnf(format string, a ...any)
- func S(json bool) *slog.Logger
- func SetGlobalLogger(l ILogger)
- func SetGlobalVerbose(v int) int
- func Warn(a ...any)
- func Warnf(format string, a ...any)
- type ILogger
- type Level
- type Logger
- func (l *Logger) Clone() *Logger
- func (l *Logger) Debug(a ...any)
- func (l *Logger) Debugf(format string, a ...any)
- func (l *Logger) Error(a ...any)
- func (l *Logger) ErrorAt(err error, a ...any) error
- func (l *Logger) ErrorAtf(err error, format string, a ...any) error
- func (l *Logger) Errorf(format string, a ...any)
- func (l *Logger) Fatal(a ...any)
- func (l *Logger) Fatalf(format string, a ...any)
- func (l *Logger) Format() LoggerFormat
- func (l *Logger) GetWriter(level Level) io.Writer
- func (l *Logger) Info(a ...any)
- func (l *Logger) Infof(format string, a ...any)
- func (l *Logger) Panic(a ...any)
- func (l *Logger) Panicf(format string, a ...any)
- func (l *Logger) Print(a ...any)
- func (l *Logger) Printf(format string, a ...any)
- func (l *Logger) Println(a ...any)
- func (l *Logger) Printlnf(format string, a ...any)
- func (l *Logger) S(json bool) *slog.Logger
- func (l *Logger) SetFormat(format LoggerFormat)
- func (l *Logger) SetOutput(w io.Writer)
- func (l *Logger) V(v int) ILogger
- func (l *Logger) Warn(a ...any)
- func (l *Logger) Warnf(format string, a ...any)
- func (l *Logger) With(prefix string) ILogger
- type LoggerFormat
- type LoggerFormatDateTime
- type TeeLogger
- func (tee *TeeLogger) Debug(a ...any)
- func (tee *TeeLogger) Debugf(format string, a ...any)
- func (tee *TeeLogger) Error(a ...any)
- func (tee *TeeLogger) ErrorAt(err error, a ...any) error
- func (tee *TeeLogger) ErrorAtf(err error, format string, a ...any) error
- func (tee *TeeLogger) Errorf(format string, a ...any)
- func (tee *TeeLogger) Fatal(a ...any)
- func (tee *TeeLogger) Fatalf(format string, a ...any)
- func (tee *TeeLogger) GetWriter(level Level) io.Writer
- func (tee *TeeLogger) Info(a ...any)
- func (tee *TeeLogger) Infof(format string, a ...any)
- func (tee *TeeLogger) Panic(a ...any)
- func (tee *TeeLogger) Panicf(format string, a ...any)
- func (tee *TeeLogger) Print(a ...any)
- func (tee *TeeLogger) Printf(format string, a ...any)
- func (tee *TeeLogger) Println(a ...any)
- func (tee *TeeLogger) Printlnf(format string, a ...any)
- func (tee *TeeLogger) S(json bool) *slog.Logger
- func (tee *TeeLogger) V(v int) ILogger
- func (tee *TeeLogger) Warn(a ...any)
- func (tee *TeeLogger) Warnf(format string, a ...any)
- func (tee *TeeLogger) With(prefix string) ILogger
Examples ¶
Constants ¶
View Source
const ( LevelDebug = Level(slog.LevelDebug) LevelInfo = Level(slog.LevelInfo) LevelWarn = Level(slog.LevelWarn) LevelError = Level(slog.LevelError) LevelPanic = Level(slog.LevelError + 1) LevelFatal = Level(slog.LevelError + 2) LevelNone = Level(-99) LevelAll = Level(99) )
Variables ¶
This section is empty.
Functions ¶
func Print ¶
func Print(a ...any)
Example ¶
package main import ( "os" "github.com/jopbrown/gobase/log" ) func main() { log.SetGlobalLogger(log.NewLogger(os.Stdout, log.LevelInfo, log.LevelFatal)) log.SetGlobalVerbose(1) log.Print("Print\n") log.Printf("%s\n", "Printf") log.Println("Println") log.Printlnf("%s", "Printlnf") v1 := log.V(1) v1.Print("v1: Print\n") v1.Printf("v1: %s\n", "Printf") v1.Println("v1: Println") v1.Printlnf("v1: %s", "Printlnf") v2 := log.V(2) v2.Print("v2: Print\n") v2.Printf("v2: %s\n", "Printf") v2.Println("v2: Println") v2.Printlnf("v2: %s", "Printlnf") }
Output: Print Printf Println Printlnf v1: Print v1: Printf v1: Println v1: Printlnf
func SetGlobalLogger ¶
func SetGlobalLogger(l ILogger)
func SetGlobalVerbose ¶
Types ¶
type ILogger ¶
type ILogger interface { GetWriter(level Level) io.Writer V(v int) ILogger With(prefix string) ILogger S(json bool) *slog.Logger Print(a ...any) Printf(format string, a ...any) Println(a ...any) Printlnf(format string, a ...any) Debug(a ...any) Debugf(format string, a ...any) Info(a ...any) Infof(format string, a ...any) Warn(a ...any) Warnf(format string, a ...any) Error(a ...any) Errorf(format string, a ...any) ErrorAt(err error, a ...any) error ErrorAtf(err error, format string, a ...any) error Fatal(a ...any) Fatalf(format string, a ...any) Panic(a ...any) Panicf(format string, a ...any) // contains filtered or unexported methods }
func ConsoleLogger ¶
func DefaultLogger ¶
func FileLogger ¶
func FileLogger(w io.Writer, format LoggerFormat, debug bool) ILogger
type Level ¶
func (Level) MarshalJSON ¶
func (Level) MarshalText ¶
func (*Level) UnmarshalJSON ¶
func (*Level) UnmarshalText ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func NewLoggerWithFormat ¶
func NewLoggerWithFormat(out io.Writer, minLevel, maxLevel Level, format LoggerFormat) *Logger
func (*Logger) Format ¶
func (l *Logger) Format() LoggerFormat
func (*Logger) SetFormat ¶
func (l *Logger) SetFormat(format LoggerFormat)
type LoggerFormat ¶
type LoggerFormat struct { AddLevel bool AddVerbose bool AddPrefix bool AddCaller bool AddSource bool AddDateTime bool LongCaller bool SourceDepth int DateTimeFormat LoggerFormatDateTime }
func DefaultLoggerFormat ¶
func DefaultLoggerFormat() LoggerFormat
func FileLoggerFormat ¶
func FileLoggerFormat() LoggerFormat
func FullLoggerFormat ¶
func FullLoggerFormat() LoggerFormat
func SimpleLoggerFormat ¶
func SimpleLoggerFormat() LoggerFormat
func TestLoggerFormat ¶
func TestLoggerFormat() LoggerFormat
type LoggerFormatDateTime ¶
Click to show internal directories.
Click to hide internal directories.