/** * Append a logging event. This is what log4j calls to log an event. */ @Override protected void append(LoggingEvent event) { if (!Thread.currentThread().getName().equals(messengerThreadName.get())) { eventBuffer.add(event); } // Else: drop event. Recursive message creation is thus blocked; even if // displaying the message would create new events, they will not lead to // endless reporting (unless the messenger creates new threads; we // cannot prevent this). // Also note that get() above is needed. ensureMessengerRuns(); }
/** * Display messages until none are left to display. Then reset the * registered thread name and die. */ @Override public void run() { while (!eventBuffer.isEmpty()) { showMessage(eventBuffer.poll()); } messengerThreadName.set(""); // If another thread has added new events just before the // messengerThreadName was reset here, then it could happen that the // messenger dies while there is still work to do. To avoid this, we // check again one last time, and create a new messenger if needed: if (!eventBuffer.isEmpty()) { ensureMessengerRuns(); } }