|
| 1 | +Flume [](https://godoc.org/github.com/ThalesGroup/flume/v2) [](https://goreportcard.com/report/ThalesGroup/flume) [](https://github.com/ThalesGroup/flume/actions?query=branch%3Amaster+workflow%3ABuild+) |
| 2 | +===== |
| 3 | + |
| 4 | +Flume is a handler for the log/slog package. A flume handler has a couple nifty capabilities: |
| 5 | + |
| 6 | +- It enables different levels based on the value of a special `logger` attribute in the record. |
| 7 | + For example, the default level might be INFO, but records with the attribute `logger=http` can be enabled at the debug level. (The attribute name is configurable). |
| 8 | +- Flume handlers forward records to another, "sink" Handler. The sink can be changed at runtime, |
| 9 | + in an atomic, concurrency-safe way, even after loggers are created and while they are being used. |
| 10 | + So you can switch from text to json at runtime without re-creating loggers, enable/disable the source |
| 11 | + attribute, or add/remove ReplaceAttr functions. |
| 12 | +- Middleware: you can configure Handler middleware, which can do things like augmenting |
| 13 | + log records with additional attributes from the context. As with the sink handler, middleware |
| 14 | + can be added or swapped at runtime. |
| 15 | +- Flume's HandlerOptions can be configured from a JSON configuration spec, and has convenience |
| 16 | + methods for reading this configuration from environment variables. |
| 17 | +- Integrates with [github.com/ansel1/console-slog](https://github.com/ansel1/console-slog), providing |
| 18 | + a very human-friendly output format |
| 19 | + |
| 20 | +Migration from v1 |
| 21 | +----------------- |
| 22 | + |
| 23 | +Flume v1 was based on zap internally, but its logging functions (e.g. `log.Info()`) had the same signatures as `slog.Logger`. |
| 24 | + |
| 25 | +Migration steps: |
| 26 | + |
| 27 | +- Replace flume imports with flume/v2 |
| 28 | +- Replace `flume.New(` with `flume.New(` (or with calls to `slog.New()` passing a flume/v2 handler) |
| 29 | +- Replace `.IsDebug()` with `.Enabled(ctx, slog.LevelDebug)` |
| 30 | +- Compiler errors: fix unmatched arguments to logging function (e.g. `l.Info("temp", temp)` -> `l.Info("temp", "value", temp)` |
| 31 | +- Consider [zap2slog](https://github.com/ansel1/zap2slog) to do the transition incrementally |
| 32 | + |
| 33 | +Contributing |
| 34 | +------------ |
| 35 | + |
| 36 | +To build, be sure to have a recent go SDK, golangci-lint, and [just](https://github.com/casey/just). Then run `just`. |
| 37 | + |
| 38 | +Merge requests are welcome! |
0 commit comments