Skip to content

Improve map and struct logging #18

@taraktikos

Description

@taraktikos

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"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions