Logging invocations
Before looking at how to properly integrate loggers into your application using some common patterns, let's see what a logger invocation will trigger.
A simple logger invocation, like logger.info(message)
, can be inspected to be represented as equivalent to the following steps:
- Check if the level of the logger is active; if not, exit
- Create a log record (set the message and level, initialize the source of the log, class, method, and so on)
- Check if the message is filtered with a
Filter
; if the filter filters it, then exit - For all handlers, publish the log record to the handler:
- Check the level of the handler versus the log record level, if not compatible then exit (note: this check is often done multiple times; it is fast because it is just an integer comparison)
- Format the log record (convert it to a
String
) - Write the formatted message to the actual backend (file, console, and so on)
This high-level drilling down of a single logger invocation shows many interesting things about...