Example_withPrometheus demonstrates using the logger with Prometheus metrics.
()
| 34 | |
| 35 | // Example_withPrometheus demonstrates using the logger with Prometheus metrics. |
| 36 | func 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. |
| 54 | func Example_withContext() { |
nothing calls this directly
no test coverage detected
searching dependent graphs…