logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Raúl Santiago <mi...@virtualsw.com>
Subject log per thread questions
Date Thu, 28 Dec 2006 17:16:33 GMT
Hello. I think this question has been asked before, but not exactly with 
the same intentions.
I have extended ConsoleAppender to log to a ScrollArea. This way:

public class taAppender extends ConsoleAppender{
        private JTextArea taLog=new JTextArea();
        public JScrollPane ScrollTA= new JScrollPane(taLog, 
        private JScrollBar vbar = ScrollTA.getVerticalScrollBar();
        public taAppender(){
            System.out.println("constructor taAppender");

        protected void subAppend(LoggingEvent event){
            taLog.setCaretPosition( taLog.getDocument().getLength() );

The JScrollPane is public so it can referenced to add it to a JPane.
Everything worked smoothly... until my boss decided "to multithread" the 

So now the app creates several threads on startup, and I want a 
taAppender per thread, every of them with it own ScrollTA, added to the 
main app JTabbedPane.

The problem is that the taAppender is only instantiated once, and 
everytime I reference its scrollTA it is the one created the very first 

So my question is: How can I get a new instance of my appender, in a 
different logger per thread (to get as many loggers as threads) and be 
able to add these to main app panel?
bear in mind that besides this thread independent taAppender, I will 
probably need a filelog per thread and a console shared log, too.

I've been reading some clues about using ThreadLocal and/or 
LoggerFactory, but I have not been able to find any good example on the 

Any advice will be greatly appreciated.
Thanks in advance.


Un Saludo,
Raúl Santiago Gómez
Virtual Software S.L.

"El programador crea aplicaciones a prueba de tontos; Dios crea tontos a prueba de programadores"

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message