
Hi all, I'm switching my first java desktop application from log4j to logback, mainly because we neede a reliable DailyRollingFileAppender, and we were told the log4j implementation is not. So far all ok, we simply changed the Logger declaration and all worked well. The problem is our custom TextAreaAppender we are currently using to log the events to a text area in the application. The log4j implementation is very simple: public class TextAreaAppender extends WriterAppender { static private JTextArea jTextArea = null; public static void setTextArea(JTextArea jTextArea) { TextAreaAppender.jTextArea = jTextArea; } /** * Format and then append the loggingEvent to the stored JTextArea. */ public void append(LoggingEvent loggingEvent) { if (layout != null) { final String message = layout.format(loggingEvent); StringBuilder sb = new StringBuilder(); if (loggingEvent.getThrowableInformation() != null) { String[] stackTrace = loggingEvent.getThrowableStrRep(); for (String s : stackTrace) { sb.append(s); sb.append(Layout.LINE_SEP); } } final String stackTrace = sb.toString(); SwingUtilities.invokeLater(new Runnable() { public void run() { if (jTextArea != null) { jTextArea.append(message); if (!stackTrace.isEmpty()) { jTextArea.append(stackTrace); } } } }); } } } I worked a couple of day but did not manage to get a logback version of this appender to work. Do you have any sample code available? thanks in advance Maurizio Questa e-mail ed i suoi allegati sono ad uso esclusivo di coloro ai quali � indirizzata e potrebbe contenere informazioni riservate, la cui diffusione, copia e/o distribuzione � proibita. Qualora riceveste questo messaggio per errore, scusandoci per l'accaduto, Vi preghiamo di avvertirci immediatamente, distruggendo quanto ricevuto.

Hi Maurizio, Logback appenders are very similar to log4j appenders. One major difference is that they need to be started (by calling the start() method) to become active. On 06.11.2012 10:55, m.lippa@ads.it wrote:
Hi all, I'm switching my first java desktop application from log4j to logback, mainly because we neede a reliable DailyRollingFileAppender, and we were told the log4j implementation is not. So far all ok, we simply changed the Logger declaration and all worked well. The problem is our custom TextAreaAppender we are currently using to log the events to a text area in the application. The log4j implementation is very simple:
public class TextAreaAppender extends WriterAppender {
static private JTextArea jTextArea = null; public static void setTextArea(JTextArea jTextArea) { TextAreaAppender.jTextArea = jTextArea; }
/** * Format and then append the loggingEvent to the stored JTextArea. */ public void append(LoggingEvent loggingEvent) { if (layout != null) { final String message = layout.format(loggingEvent); StringBuilder sb = new StringBuilder(); if (loggingEvent.getThrowableInformation() != null) { String[] stackTrace = loggingEvent.getThrowableStrRep(); for (String s : stackTrace) { sb.append(s); sb.append(Layout.LINE_SEP); } } final String stackTrace = sb.toString();
SwingUtilities.invokeLater(new Runnable() { public void run() { if (jTextArea != null) { jTextArea.append(message); if (!stackTrace.isEmpty()) { jTextArea.append(stackTrace); } } } }); } } }
I worked a couple of day but did not manage to get a logback version of this appender to work. Do you have any sample code available?
thanks in advance Maurizio
-- Ceki 65% of statistics are made up on the spot
participants (2)
-
ceki
-
m.lippa@ads.it