Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( String = slog.String Int = slog.Int Int64 = slog.Int64 Uint64 = slog.Uint64 Float64 = slog.Float64 Bool = slog.Bool Any = slog.Any Time = slog.Time Duration = slog.Duration )
Aliases for slog package types
View Source
var ( // Aliases for slog package levels LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarn = slog.LevelWarn LevelError = slog.LevelError )
Functions ¶
func Discard ¶ added in v0.0.4
Example ¶
package main
import (
"github.com/matthewmueller/logs"
)
func main() {
log := logs.Discard()
log.WithGroup("hello").Debug("world", "args", 10)
log.Info("hello", "planet", "world", "args", 10)
log.Warn("hello", "planet", "world", "args", 10)
log.Error("hello world", logs.String("planet", "world"), "args", 10)
}
Output:
Types ¶
type ConsoleHandler ¶
type ConsoleHandler struct {
Color color.Writer
Source bool
// contains filtered or unexported fields
}
ConsoleHandler handler for printing logs to the terminal
func Console ¶
func Console(w io.Writer) *ConsoleHandler
Example ¶
package main
import (
"errors"
"os"
"github.com/livebud/color"
"github.com/matthewmueller/logs"
)
func main() {
console := logs.Console(os.Stdout)
console.Color = color.Ignore()
log := logs.New(console)
log.WithGroup("grouped").Debug("debug line", "path", "console_test.go")
log.Info("some info")
log.Warn("some warning")
log.Error("an error", "err", errors.New("oh no"))
}
Output: debug: debug line grouped.path=console_test.go info: some info warn: some warning error: an error err="oh no"
func (*ConsoleHandler) Enabled ¶
Enabled is always set to true. Use log.Filter to filter out log levels
type Level ¶ added in v0.0.7
func MustParseLevel ¶ added in v0.0.7
MustParseLevel parses a string into a log level and panics if it fails
func ParseLevel ¶
ParseLevel parses a string into a log level
type Logger ¶
Example ¶
package main
import (
"os"
"github.com/livebud/color"
"github.com/matthewmueller/logs"
)
func main() {
console := logs.Console(os.Stdout)
console.Color = color.Ignore()
log := logs.New(console)
log.WithGroup("hello").Debug("world", "args", 10)
log.Info("hello", "planet", "world", "args", 10)
log.Warn("hello", "planet", "world", "args", 10)
log.Error("hello world", logs.String("planet", "world"), "args", 10)
}
Output: debug: world hello.args=10 info: hello planet=world args=10 warn: hello planet=world args=10 error: hello world planet=world args=10
type MultiHandler ¶
func Multi ¶
func Multi(handlers ...slog.Handler) MultiHandler
Example ¶
package main
import (
"log/slog"
"os"
"github.com/matthewmueller/logs"
)
func main() {
console := logs.Console(os.Stderr)
log := slog.New(logs.Multi(
logs.Filter(slog.LevelInfo, console),
slog.NewJSONHandler(os.Stderr, nil),
))
log.WithGroup("hello").Debug("world", "args", 10)
log.Info("hello", "planet", "world", "args", 10)
log.Warn("hello", "planet", "world", "args", 10)
log.Error("hello world", "planet", "world", "args", 10)
}
Output:
Click to show internal directories.
Click to hide internal directories.