Documentation ¶
Overview ¶
Package log is inspired by apex/log.
Index ¶
- Variables
- func Buffer() *buffer
- func Middleware(log Log, next http.Handler, options ...func(*middlewareOption)) http.Handler
- func WithRequestId(fn func(r *http.Request) string) func(*middlewareOption)
- type Entry
- type Fields
- type Handler
- type Level
- type Log
- type Logger
- func (l *Logger) Debug(args ...interface{}) error
- func (l *Logger) Debugf(msg string, args ...interface{}) error
- func (l *Logger) Error(args ...interface{}) error
- func (l *Logger) Errorf(msg string, args ...interface{}) error
- func (l *Logger) Field(key string, value interface{}) Log
- func (l *Logger) Fields(fields map[string]interface{}) Log
- func (l *Logger) Info(args ...interface{}) error
- func (l *Logger) Infof(msg string, args ...interface{}) error
- func (l *Logger) Notice(args ...interface{}) error
- func (l *Logger) Noticef(msg string, args ...interface{}) error
- func (l *Logger) Warn(args ...interface{}) error
- func (l *Logger) Warnf(msg string, args ...interface{}) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Debug message is written to the console Debug = stderr.Debug // Debugf message is written to the console Debugf = stderr.Debugf // Info message is written to the console Info = stderr.Info // Infof message is written to the console Infof = stderr.Infof // Notice message is written to the console Notice = stderr.Notice // Noticef message is written to the console Noticef = stderr.Noticef // Warn message is written to the console Warn = stderr.Warn // Warnf message is written to the console Warnf = stderr.Warnf // Error message is written to the console Error = stderr.Error // Errorf message is written to the console Errorf = stderr.Errorf )
View Source
var ErrNotInContext = fmt.Errorf("log: not in context")
ErrNotInContext is returned when a log is not in the context
View Source
var Now = time.Now
Now returns the current time.
Functions ¶
func Middleware ¶ added in v0.0.7
Middleware uses the logger to log requests and responses
func WithRequestId ¶ added in v0.0.7
WithRequestId sets the request id function for generating a unique request id for each request
Types ¶
type Entry ¶ added in v0.0.3
type Entry struct { Time time.Time `json:"ts,omitempty"` Level Level `json:"lvl,omitempty"` Message string `json:"msg,omitempty"` Fields Fields `json:"fields,omitempty"` }
func (*Entry) MarshalJSON ¶ added in v0.0.3
type Handler ¶
func Console ¶
Console handler
Example ¶
package main import ( "os" "github.com/livebud/color" "github.com/livebud/log" ) func main() { log := log.New(log.Console(color.Ignore(), os.Stdout)) log.Debug("world", "args", 10) log.Info("hello", "planet", "world", "args", 10) log.Warn("hello", "planet", "world", "args", 10) // log.Error("hello world", slog.String("planet", "world"), "args", 10)
Output:
type Log ¶ added in v0.0.3
type Log interface { Field(key string, value interface{}) Log Fields(fields map[string]interface{}) Log Debug(args ...interface{}) error Debugf(msg string, args ...interface{}) error Info(args ...interface{}) error Infof(msg string, args ...interface{}) error Notice(args ...interface{}) error Noticef(msg string, args ...interface{}) error Warn(args ...interface{}) error Warnf(msg string, args ...interface{}) error Error(args ...interface{}) error Errorf(msg string, args ...interface{}) error }
func Discard ¶ added in v0.0.3
func Discard() Log
Discard logger is a logger that discards all messages.
func From ¶ added in v0.0.6
From gets the log from the context. If the logger isn't in the middleware, we warn and discards the logs
func Multi ¶
Multi logs to multiple places
Example ¶
package main import ( "os" "github.com/livebud/color" "github.com/livebud/log" ) func main() { log := log.Multi( log.Filter(log.LevelDebug, log.Console(color.Default(), os.Stderr)), log.Json(os.Stderr), ) log.Debug("world", "args", 10) log.Field("planet", "world").Field("args", 10).Info("hello") log.Warnf("hello %s", "world") log.Error("hello world", "planet", "world", "args", 10) }
Output:
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.