Compare commits
No commits in common. "ea0c84547f0c07f58ae7148db20de44d8fda9ab7" and "000fe293ee17d94cfdbc7e425944c55e0614442b" have entirely different histories.
ea0c84547f
...
000fe293ee
|
@ -1,2 +1 @@
|
||||||
.aider*
|
.aider*
|
||||||
cmd/example/example
|
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log/slog"
|
|
||||||
|
|
||||||
_ "sneak.berlin/go/simplelog"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
|
|
||||||
// log structured data with slog as usual:
|
|
||||||
slog.Info(
|
|
||||||
"User login attempt",
|
|
||||||
slog.String("user", "JohnDoe"),
|
|
||||||
slog.Int("attempt", 3),
|
|
||||||
)
|
|
||||||
slog.Warn(
|
|
||||||
"Configuration mismatch",
|
|
||||||
slog.String("expected", "config.json"),
|
|
||||||
slog.String("found", "config.dev.json"),
|
|
||||||
)
|
|
||||||
slog.Error(
|
|
||||||
"Failed to save data",
|
|
||||||
slog.String("reason", "permission denied"),
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -16,10 +16,7 @@ func NewConsoleHandler() *ConsoleHandler {
|
||||||
return &ConsoleHandler{}
|
return &ConsoleHandler{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConsoleHandler) Handle(
|
func (c *ConsoleHandler) Handle(ctx context.Context, record slog.Record) error {
|
||||||
ctx context.Context,
|
|
||||||
record slog.Record,
|
|
||||||
) error {
|
|
||||||
timestamp := time.Now().UTC().Format("2006-01-02T15:04:05.000Z07:00")
|
timestamp := time.Now().UTC().Format("2006-01-02T15:04:05.000Z07:00")
|
||||||
var colorFunc func(format string, a ...interface{}) string
|
var colorFunc func(format string, a ...interface{}) string
|
||||||
|
|
||||||
|
@ -35,28 +32,16 @@ func (c *ConsoleHandler) Handle(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the caller information
|
// Get the caller information
|
||||||
_, file, line, ok := runtime.Caller(4)
|
_, file, line, ok := runtime.Caller(5)
|
||||||
if !ok {
|
if !ok {
|
||||||
file = "???"
|
file = "???"
|
||||||
line = 0
|
line = 0
|
||||||
}
|
}
|
||||||
fmt.Println(
|
fmt.Println(colorFunc("%s [%s] %s:%d: %s", timestamp, record.Level, file, line, record.Message))
|
||||||
colorFunc(
|
|
||||||
"%s [%s] %s:%d: %s",
|
|
||||||
timestamp,
|
|
||||||
record.Level,
|
|
||||||
file,
|
|
||||||
line,
|
|
||||||
record.Message,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConsoleHandler) Enabled(
|
func (c *ConsoleHandler) Enabled(ctx context.Context, level slog.Level) bool {
|
||||||
ctx context.Context,
|
|
||||||
level slog.Level,
|
|
||||||
) bool {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue