Skip to content

Commit

Permalink
feat: add custom handler example
Browse files Browse the repository at this point in the history
  • Loading branch information
lvlcn-t committed Feb 24, 2024
1 parent c974a59 commit c6dc880
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions examples/custom-handler/main.go
Original file line number Diff line number Diff line change
@@ -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!")
}()
}

0 comments on commit c6dc880

Please sign in to comment.