Guten Tag Nandan S,
am Samstag, 31. Mai 2014 um 15:31 schrieben Sie:

> I have used log4cxx static library in my threaded application and facing
> issues with respect to logging. I would like to log messages from each
> thread in a different file. To achieve this, i am calling log4cxx
> setfilename() method in each thread. 

There's no such generic method, therefore I expect you mean
setFileNamePattern from RollingPolicyBase for a RollingFileAppender.

> But each thread is not logging in it's specific file and the output is
> jumbled in different files. Is it that, log4cxx has static variables due to
> which i am observing this issue.

Besides using some static variables, from my understanding this is by
design, because one appender should always work the same in every
instance it is used. An appender is just a name or logical container
for some output behavior and I don't see why one and the same name or
logical container or however you want to call it should behave
differently under different contexts.

Best practice in threaded environments is to use different loggers and
appenders for each thread or Nested Diagnostic Contexts to
differentiate log statements to the same logger for different threads.

http://logging.apache.org/log4cxx/usage.html

If different loggers per thread are to much configuration overhead for
you, I would suggest configuring some template logger for every thread
and programmatically create new loggers with new appenders for each
thread based on the template logger. You would simply need to create
new logger and appender objects using LOG4CXX API and provide most of
the properties form the configured template logger and appender, just
changing logger and file names to be specific for each thread.

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail:thorsten.schoen...@am-soft.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon...........05151-  9468- 55
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow

Reply via email to