~/ learn/ comp-348/ cards/ Logging a server
1 of 6

One logger per log, static final, thread-safe

One logger per log, static final, thread-safe

Answer

public final class AccessLog { private static final Logger AUDIT = Logger.getLogger("requests"); private static final Logger ERRORS = Logger.getLogger("errors"); static void bug(String where, Throwable ex) { ERRORS.log(Level.SEVERE, where, ex); } }

Two named logs, two loggers, one shared instance of each — safe because loggers are thread-safe. The three-argument `log` keeps the `Throwable`, and therefore the stack trace, which is the only part of an error-log entry anyone reads.

Harold 4e ch9 §Logging

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/7695b397-192f-4e02-8c32-67730754dbc1/flashcard utf-8 LF