console-slog
console-slog copied to clipboard
Improve map and struct logging
Currently, it works with standard string formatter:
testMap := map[string]any{
"key1": "value1",
"key2": "value2",
}
logger.Info("message", slog.Any("test", testMap))
logger.Info("message", slog.Any("test", TestMap{Key1: "value1", Key2: "value2"}))
2025-01-30 12:31:23 INF message test=map[key1:value1 key2:value2]
2025-01-30 12:31:23 INF message test={value1 value2}
What about adding config parameter to the handler to allow json marshal with or without indentation It can looks like
marshaledMap, _ := json.MarshalIndent(testMap, "", " ")
logger.Info("message", slog.String("test", string(marshaledMap)))
2025-01-30 12:31:23 INF message test={
"key1": "value1",
"key2": "value2"
}