How to read log4j output to a web page?
Posted
by Ran
on Stack Overflow
See other posts from Stack Overflow
or by Ran
Published on 2010-03-31T19:27:31Z
Indexed on
2010/03/31
19:43 UTC
Read the original article
Hit count: 247
I have a web page, used for admin purposes, which runs a task (image fetching from a remote site).
In order to be able to debug the task using the browser only, no ssh etc, I'd like to be able to read all log output from the executing thread and spit it out to the web page.
The task boils down to:
- Changing log level for current thread at the beginning of the call and restore when the call is done.
- Reading all log output by current thread and storing it in a string.
So in pseudocode my execute() method would look like this: (I'm using struts2)
public String execute() throws Exception {
turnLoggingLevelToDebugOnlyForThisThread()
... do stuff...
restoreLoggingLevelForThisThread()
String logs = readAllLogsByThisThread();
}
Can this be done with log4j?
I'm using tomcat, struts2, log4j and slf4j.
© Stack Overflow or respective owner