You could probably also stay with one appender but use a ThreadLocal
to get the ScrollPane in taAppender.  You would probably need to make
the ThreadLocal hold a wrapper classes that holds your 3 variables.

On 12/28/06, Raúl Santiago <[EMAIL PROTECTED]> 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.
[EMAIL PROTECTED]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to