logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <h...@visi.com>
Subject Re: log per thread questions
Date Thu, 28 Dec 2006 17:40:44 GMT

You could try using a custom repository selector 
that is keyed by thread.  Log4j-1.3 has one keyed 
by JNDI.  Others out there are keyed by 
ClassLoader, but that just leads to classloading 
issues.  Look up in your favorite search engine 
or in the Log4j Wiki.  The Log4j -sandbox used to 
have one that used JNDI  and was compatible with 
Log4j 1.2, but since an equivalent one was added 
to Log4j 1.3 (albeit incompatible with Log4j 
1.2), it was removed.  It was tagged as something 
like 0.[1|2|3|4]alpha, so you might find it by 
looking at that tags in SVN if the conversion from CVS to SVN saved the tags.

Jake

At 11:16 AM 12/28/2006, you wrote:
 >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,
 >JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
 >JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
 >        private JScrollBar vbar = ScrollTA.getVerticalScrollBar();
 >
 >        public taAppender(){
 >            System.out.println("constructor taAppender");
 >        }
 >
 >        protected void subAppend(LoggingEvent event){
 >            taLog.append(getLayout().format(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
 >process.
 >
 >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
 >time.
 >
 >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
 >subject.
 >
 >Any advice will be greatly appreciated.
 >Thanks in advance.
 >
 >
 >--
 >
 >Un Saludo,
 >Raúl Santiago Gómez
 >Virtual Software S.L.
 >mijac@virtualsw.com
 >
 >"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
 >
 >
 > 


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


Mime
View raw message