Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4J Swing Appender

Tags:

java

swing

log4j

I need to append log4j content to a Swing component (JTextArea or similar). Is there a common way to do this?

like image 302
Nate Avatar asked Aug 31 '09 19:08

Nate


People also ask

What is Appender in log4j?

Apache log4j provides Appender objects which are primarily responsible for printing logging messages to different destinations such as consoles, files, sockets, NT event logs, etc. Each Appender object has different properties associated with it, and these properties indicate the behavior of that object.

What is async Appender in log4j?

The AsyncAppender lets users log events asynchronously. The AsyncAppender will collect the events sent to it and then dispatch them to all the appenders that are attached to it. You can attach multiple appenders to an AsyncAppender. The AsyncAppender uses a separate thread to serve the events in its buffer.

What is an Appender in Java?

Appenders (also called Handlers in some logging frameworks) are responsible for recording log events to a destination. Appenders use Layouts to format events before sending them to an output.

What is a routing Appender?

The routing appender evaluates a pattern which, thanks to log4j2 placeholding support, can be an environment variable with a default. Then the pattern allows to select the Route to use to actually log the log event. In other words, the router (or routing appender) behaves as a proxy in front of other appenders :).


1 Answers

Instead of introducing an external library, I ended up editing the log4j.properties file to include the following:

log4j.rootCategory=DEBUG, app
log4j.appender.app=path.to.class.extending.WriterAppender

Then I employed an observer pattern to post the data into my GUI's JTextArea.

like image 173
Nate Avatar answered Sep 21 '22 10:09

Nate