MCPcopy
hub / github.com/redpanda-data/console / Example_withPrometheus

Function Example_withPrometheus

backend/pkg/logger/example_test.go:36–51  ·  view source on GitHub ↗

Example_withPrometheus demonstrates using the logger with Prometheus metrics.

()

Source from the content-addressed store, hash-verified

34
35// Example_withPrometheus demonstrates using the logger with Prometheus metrics.
36func Example_withPrometheus() {
37 // Create a Prometheus registry
38 registry := prometheus.NewRegistry()
39
40 // Create logger with Prometheus metrics
41 log := logger.NewSlogLogger(
42 logger.WithLevel(slog.LevelInfo),
43 logger.WithPrometheusRegistry(registry, "console"),
44 )
45
46 ctx := context.Background()
47 log.InfoContext(ctx, "server started", slog.Int("port", 8080))
48 log.ErrorContext(ctx, "connection failed", slog.String("err", "timeout"))
49
50 // The Prometheus registry now contains metrics about log messages
51}
52
53// Example_withContext demonstrates context-aware logging using structured attributes.
54func Example_withContext() {

Callers

nothing calls this directly

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…