From c6dc880241c121a6af3dbe0bd36a18618bce37a1 Mon Sep 17 00:00:00 2001 From: lvlcn-t <75443136+lvlcn-t@users.noreply.github.com> Date: Sat, 24 Feb 2024 19:07:38 +0100 Subject: [PATCH] feat: add custom handler example --- examples/custom-handler/main.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 examples/custom-handler/main.go diff --git a/examples/custom-handler/main.go b/examples/custom-handler/main.go new file mode 100644 index 0000000..a4f2701 --- /dev/null +++ b/examples/custom-handler/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "os" + + "github.com/charmbracelet/log" + "github.com/lvlcn-t/loggerhead/logger" +) + +func main() { + // Setups a custom handler for the logger. + clog := log.New(os.Stdout) + clog.SetLevel(log.DebugLevel) + + // Create a new logger with the custom handler. + l := logger.NewLogger(clog) + + // Log some messages. + l.Debug("I'm not sure what's happening.") + l.Info("Hello, world in pretty colors!") + l.Warn("I'm warning you!") + l.Error("I'm sorry. I'm afraid you did something wrong.") + func() { + defer func() { + if r := recover(); r != nil { + l.Fatal("I'm dying!") + } + }() + l.Panic("I'm panicking!") + }() +}