Receive Log4J Events in Application

Hi everybody,

what is the best way to receive log-events of another application running log4j.

my plan is, to create an application which shows all log-events fired by an runing application an for example use syntax highlighting an other stuff to help the user to read these events.

thank you for help

my first idea was to upload a log-file and reload it if there are any changes. but i think this is not possible or am i wrong?!

Hey P h,

I would implement a custom log4j appender (extend org.apache.log4j.AppenderSkeleton). So you are able to recieve all LoggingEvent objects and have to update your UIs. If you want to have a persistent view you indeed have to save your recieved logging events into your database/your file system.

Hey Wolfgang,

i´ve also thought about this solution but i´m not really familar with custom log4j appender writing. do you have a good example for me?

Greetings

Hey P h,

I’m sorry I never did this :slight_smile:
But basically somehting like this:
In your log4j.xml

[font=courier new]
<appender name="myAppender" class="p.h.MyAppender" />
[/font]
[font=courier new]
<logger name="p.h">
  <level value="DEBUG"/>
  <appender-ref ref="myAppender" />
</logger>
[/font]

And now your appender

[code]
Class MyAppender extends AppenderSkeleton {
void append(LoggingEvent event) {
Broadcaster.broadcast(event);
}

}
[/code]Broadcaster like in https://vaadin.com/book/-/page/advanced.push.html

Nothing tested, good luck! :slight_smile:

ps: Please show results