Flogger: A new fluent logging API for Java
Self-documenting log statements may be what first caught our eye, but Flogger, a new fluent logging API for Java, has a lot to offer for developers looking to manage their logging better.
Managing logs isn’t easy. But thanks to a new fluent logging API for Java, Flogger makes it even easier to manage logs and find errors wherever they might be hiding.
Flogger joins a crowded field of Java logging APIs: there are lots of specialist debug logging APIs out there for Google’s codebase. So why add to the pile? Well, Flogger is intended to be a generalist logging API, suitable for most Java projects in Google.
Flogger is a somewhat verbose logging API, but don’t let the additional typing scare you. This API makes it even easier to gather more information from event logging than classical logging APIs.
With one method call, developers can:
- Specify the log level (via the choice the method itself)
- Optionally attach metadata to the log statement (the cause)
- Specify the log message and arguments
Flogger has a number of other benefits over other APIs. For one, logging at disabled levels is effectively free. Developers can add as many fine-grained log statements to their code as they want, without worry. It also has very high performance for enabled log statements.
Additionally, a fluent API accommodates a variety of present and future features without combinatorial explosion, and without requiring separate logging facades. There’s also less reliance on long parameter lists makes it harder to misuse and yields more self-documenting code.
Flogger brings readability to high performance logging, with extensibility and a reduced cost of disabled log statements.
It’s easy to start using this new logging API for Java in three simple steps:
- Add an import for
- Create a
private static finalinstance
- Start logging!
If you’re interested about learning more, head on over to their website – they have a lot of information available about Flogger, its benefits, best practices, and even the anatomy of a logging API for a deeper dive into the rationale behind this new logger. Head on over to their GitHub page to see more!