fix #6: support LogValuer() attributes

This commit is contained in:
2024-01-22 13:44:19 +01:00
committed by T.v.Dein
parent 33798bddb3
commit 5c0aadd54a
3 changed files with 41 additions and 5 deletions

View File

@@ -16,6 +16,12 @@ type Ammo struct {
Range int
}
func (a *Ammo) LogValue() slog.Value {
return slog.GroupValue(
slog.String("Forweapon", a.Forweapon),
)
}
type Enemy struct {
Alive bool
Health int
@@ -24,6 +30,12 @@ type Enemy struct {
Ammo []Ammo
}
func (e *Enemy) LogValue() slog.Value {
return slog.GroupValue(
slog.String("name", e.Name),
)
}
func removeTime(_ []string, a slog.Attr) slog.Attr {
if a.Key == slog.TimeKey {
return slog.Attr{}
@@ -47,6 +59,7 @@ func main() {
}
slog.Info("info", "enemy", e, "spawn", 199)
slog.Info("info", "ammo", &Ammo{Forweapon: "axe", Impact: 1})
slog.Info("connecting", "enemies", 100, "players", 2, "world", "600x800")
slog.Debug("debug text")
slog.Error("error")