You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by � <em...@yahoo.com> on 2003/11/14 19:19:28 UTC
Logging multiple threads to multiple files
I'm using log4j 1.2.8. I have a class that starts off 4 other threads. So I have 5 threads running, all at the same time. What I would like to do is log the 5 threads into their own log files.
The first time I tackled this, I got 5 files with the same output (all output from all threads). Then I got it to where the 5 files show different things, however, it seems like the threads are stepping over each other. thread1 would have a log entry in thread2's log, thread2's log will have some entries in thread3's log, and so on.
I've done some poking around and found that I can set a threshhold to log specific log levels to different files, but that's not what I need. I want to log ALL levels from a thread to its own log file.
Can this even be done?
---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
Re: Logging multiple threads to multiple files
Posted by � <em...@yahoo.com>.
Do�you have any insights to�how I can accomplish this,
or maybe someone has done this before?
Ceki G�lc� <ce...@qos.ch> wrote:
Not without touching the core of log4j. But it can be
done.
At 10:19 AM 11/14/2003 -0800, wrote:
>I'm using log4j 1.2.8. I have a class that starts off
4 other threads. So
>I have 5 threads running, all at the same time. What
I would like to do is
>log the 5 threads into their own log files.
>
>The first time I tackled this, I got 5 files with the
same output (all
>output from all threads). Then I got it to where the
5 files show
>different things, however, it seems like the threads
are stepping over
>each other. thread1 would have a log entry in
thread2's log, thread2's log
>will have some entries in thread3's log, and so on.
>
>I've done some poking around and found that I can set
a threshhold to log
>specific log levels to different files, but that's
not what I need. I want
>to log ALL levels from a thread to its own log file.
>
>Can this even be done?
--
Ceki G�lc�
For log4j documentation consider "The complete log4j
manual"
ISBN: 2970036908
http://www.qos.ch/shop/products/clm_t.jsp
import org.apache.Facetime;
ApacheCon US 2003, 18-21 November
http://apachecon.com/
---------------------------------------------------------------------
To unsubscribe, e-mail:
log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail:
log4j-user-help@jakarta.apache.org
__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: Logging multiple threads to multiple files
Posted by Ceki Gülcü <ce...@qos.ch>.
Not without touching the core of log4j. But it can be done.
At 10:19 AM 11/14/2003 -0800, wrote:
>I'm using log4j 1.2.8. I have a class that starts off 4 other threads. So
>I have 5 threads running, all at the same time. What I would like to do is
>log the 5 threads into their own log files.
>
>The first time I tackled this, I got 5 files with the same output (all
>output from all threads). Then I got it to where the 5 files show
>different things, however, it seems like the threads are stepping over
>each other. thread1 would have a log entry in thread2's log, thread2's log
>will have some entries in thread3's log, and so on.
>
>I've done some poking around and found that I can set a threshhold to log
>specific log levels to different files, but that's not what I need. I want
>to log ALL levels from a thread to its own log file.
>
>Can this even be done?
--
Ceki Gülcü
For log4j documentation consider "The complete log4j manual"
ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp
import org.apache.Facetime;
ApacheCon US 2003, 18-21 November http://apachecon.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: Logging multiple threads to multiple files
Posted by � <em...@yahoo.com>.
Okay, I've been playing around some more and came up with this.
I have a method that creates a properties object containing the Log4J key/value pairs:
/**
* Sets up a {@link Properties} object with the logger's information.
*
* @param sClass the name of the class to log
* sFilename the file to write the log to
* @return a Properties object with the logger's information.
*/
public Properties getLoggerProperties(String sClass, String sFilename) {
File dir;
Properties logProperties;
// Create the log directory if it does not exist.
dir = new File(sFilename.substring(0, sFilename.lastIndexOf("/")));
if (! dir.exists())
dir.mkdirs();
logProperties = new Properties();
// log4j.logger.<sClass value> = debug, logfile
logProperties.setProperty("log4j.logger." + sClass, "debug, logfile");
// log4j.appender.logfile = org.apache.log4j.RollingFileAppender
logProperties.setProperty("log4j.appender.logfile", "org.apache.log4j.RollingFileAppender");
// log4j.appender.logfile.Append = true
logProperties.setProperty("log4j.appender.logfile.Append", "true");
// log4j.appender.logfile.File = <sFilename value>
logProperties.setProperty("log4j.appender.logfile.File", sFilename);
// log4j.appender.logfile.MaxFileSize = 1MB
logProperties.setProperty("log4j.appender.logfile.MaxFileSize", "1MB");
// log4j.appender.logfile.MaxBackupIndex = 100
logProperties.setProperty("log4j.appender.logfile.MaxBackupIndex", "100");
// log4j.appender.logfile.layout = org.apache.log4j.PatternLayout
logProperties.setProperty("log4j.appender.logfile.layout", "org.apache.log4j.PatternLayout");
// log4j.appender.logfile.ConversionPattern = %d %-5p [%c] %x - %m%n
logProperties.setProperty("log4j.appender.logfile.layout.ConversionPattern", "%d %-5p [%c] %x - %m%n");
return logProperties;
} // End method getLoggerProperties()
The caller is written similar to this:
final private static String sClass = DataDump.class.getName();
static Logger logger = Logger.getLogger(sClass);
String sRootLogDir = "log";
String sLogFile = "DataDump.log";
PropertyConfigurator.configure(getLoggerProperties(sClass, sRootLogDir + "/" + sLogFile));
With this, I am able to log each thread into their own files, but I lose the ability to roll the file once it reaches 1MB. I actually tested this using 10KB rather than 1MB so I won't have to wait for my logs to fill up to 1MB before rolling over.
How can I log each thread to their own files, while preserving the roll over?
Thanks in advance...
Ed
<em...@yahoo.com> wrote:
I'm using log4j 1.2.8. I have a class that starts off 4 other threads. So I have 5 threads running, all at the same time. What I would like to do is log the 5 threads into their own log files.
The first time I tackled this, I got 5 files with the same output (all output from all threads). Then I got it to where the 5 files show different things, however, it seems like the threads are stepping over each other. thread1 would have a log entry in thread2's log, thread2's log will have some entries in thread3's log, and so on.
I've done some poking around and found that I can set a threshhold to log specific log levels to different files, but that's not what I need. I want to log ALL levels from a thread to its own log file.
Can this even be done?
---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard