title: How to read log4j output to a web page?
body: <p>I have a web page, used for admin purposes, which runs a task (image fetching from a remote site).<br>
  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.<br>
  The task boils down to:</p>
  
  <ol>
  <li>Changing log level for current thread at the beginning of the call and restore when the call is done.</li>
  <li>Reading all log output by current thread and storing it in a string.</li>
  </ol>
  
  <p>So in pseudocode my execute() method would look like this: (I'm using struts2)</p>
  
  <pre><code>public String execute() throws Exception {
    turnLoggingLevelToDebugOnlyForThisThread()
    ... do stuff...
    restoreLoggingLevelForThisThread()
    String logs = readAllLogsByThisThread();
  }
  </code></pre>
  
  <p>Can this be done with log4j?</p>
  
  <p>I'm using tomcat, struts2, log4j and slf4j.</p>
  
  <p>EDIT 1: I should note that the motivation is to be able to see the existing logs on a web page without needing to add new log lines in code. Think of a nice web debug interface that lets you run your operation and the result spits out the logs of the operation.<br>
  EDIT 2: I should also note that I'm already using log4j (via slf4j) and a log4j.xml, so the solution I'm seeking needs to live aside the currently logging system, not ruin it.</p>