A Go library providing common formatters and helpers for custom attribute formatting with the slog logging library.
slog-formatter is a Go library that extends the standard `log/slog` package with a collection of formatters for transforming log attributes. It enables developers to customize how specific data types, keys, or groups are presented in logs, improving readability, security, and consistency.
Go developers using the standard `log/slog` package who need fine-grained control over log output formatting, especially those handling sensitive data or requiring structured logs for observability.
Developers choose slog-formatter for its extensive pre-built formatters for common types like errors, HTTP requests, and PII, along with flexible utilities for building custom formatters, all while maintaining seamless integration with `slog.Handler` and compatibility with middleware chaining via `slog-multi`.
🚨 slog: Attribute formatting
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Includes ready-to-use formatters for time, errors, HTTP requests/responses, PII, and IP addresses, reducing boilerplate code for common logging scenarios, as detailed in the README examples.
Provides utilities like FormatByKey, FormatByType, and FormatByGroup to build tailored formatters for any attribute, enabling fine-grained control over log output based on specific keys, types, or nested groups.
Works directly with standard `slog.Handler` and is compatible with `slog-multi` for middleware chaining, allowing easy drop-in usage without disrupting existing logging setups, as shown in the NewFormatterHandler and NewFormatterMiddleware sections.
Offers PIIFormatter and IPAddressFormatter to anonymize sensitive data in logs, helping teams meet compliance requirements by hiding personal information and IP addresses with configurable masking.
The README explicitly warns that log processing can be 'very costly' and recommends using `slog.LogValuer` instead where possible, indicating significant performance trade-offs for high-volume logging.
Introduces additional layers to logging configuration, which might be overkill for simple applications or increase maintenance burden compared to native `slog` features.
Only works with Go's `log/slog` package, making it unsuitable for projects using other logging libraries like Zap or Logrus without additional adapters, as highlighted in the related projects list.