Explanation of Steps
-
Start
The logger is invoked through a method call likelogger.log("message", INFO)
.
- Check if log level is enabled
The logger checks if the given message level (e.g., DEBUG) is allowed based on the current configuration.
-
Ignore Message (if level is too low)
If the log level is lower than the configured threshold, the logger exits without logging.
-
Format the Message
If the message passes the log level filter, it is passed to a formatter that adds metadata (timestamp, level, etc.).
-
Pass to Handler
The formatted message is passed to one or more handlers (e.g., file handler, console handler).
-
Write the Log
The handler writes the log to the desired output destination.
-
End
The logging process ends after writing.
How to Explain to Students
- Emphasize conditional paths (e.g., level check).
- Highlight the separation of responsibilities: formatting and handling.
- Discuss how this flow supports extensibility and performance.