Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Event ¶
func LogLevelToPrefixMapper ¶
LogLevelToPrefixMapper adds a prefix depending on the event level.
func StandardLogConsumer ¶
StandardLogConsumer writes an event by `log.Printf`.
type GlobalLogger ¶
type GlobalLogger interface {
Info(format string, v ...any)
Warn(format string, v ...any)
Error(format string, v ...any)
Debug(format string, v ...any)
Trace(format string, v ...any)
SetLevel(level Level)
Level() Level
}
GlobalLogger is a static logger instance. This filters logs by level, adds a prefix depending on event level and writes logs by `log.Printf`.
func G ¶
func G() GlobalLogger
G returns the `GlobalLogger`.
Example ¶
package main
import (
"log"
"os"
"github.com/berquerant/logger"
)
func main() {
log.SetFlags(0)
log.SetOutput(os.Stdout)
logger.G().Info("information")
logger.G().Error("error")
logger.G().Debug("debug")
logger.G().SetLevel(logger.Ldebug)
logger.G().Info("change level")
logger.G().Debug("last line")
}
Output: I | information E | error I | change level D | last line
type Logger ¶
type Logger struct {
Proxy
}
func NewDefault ¶
NewDefault returns a new logger with `LogLevelFilter`, `LogLevelToPrefixMapper` and `StandardLogConsumer`.
Example ¶
package main
import (
"log"
"os"
"github.com/berquerant/logger"
)
func main() {
log.SetFlags(0)
log.SetOutput(os.Stdout)
l := logger.NewDefault(logger.Lwarn)
l.Info("information")
l.Error("error")
l.Debug("debug")
l.Warn("warn")
l.Debug("last line")
}
Output: E | error W | warn
type MapperFunc ¶ added in v0.4.0
MapperFunc converts and/or filters the log event.
func LogLevelFilter ¶
func LogLevelFilter(level Level) MapperFunc
LogLevelFilter ignores an event with the lower level.
func MustNewMapperFunc ¶ added in v0.4.0
func MustNewMapperFunc(f any) MapperFunc
func NewMapperFunc ¶ added in v0.4.0
func NewMapperFunc(f any) (MapperFunc, error)
func (MapperFunc) Call ¶ added in v0.4.0
func (m MapperFunc) Call(event Event) (Event, error)
Call the function. Return ErrNilMapperFunc if it's nil. Return ErrNilEvent if event is nil.
func (MapperFunc) Next ¶ added in v0.4.0
func (m MapperFunc) Next(f any) MapperFunc
Next appends a MapperFunc. The returned function calls this, and f with the returned event of this, if no errors.
Available signatures of f:
func(Event) func(Event) Event func(Event) error func(Event) (Event, error)
Otherwise f is evaluated as nil MapperFunc.
func (MapperFunc) Via ¶ added in v0.4.0
func (m MapperFunc) Via(f any) MapperFunc
Via appends a MapperFunc. The returned function calls this, and f with the returned event of this, if no errors, but ignores the values from f.
Available signatures of f:
func(Event) func(Event) Event func(Event) error func(Event) (Event, error)
Otherwise f is evaluated as nil MapperFunc.