0

I have a project and I work with threads in this project. I have the log4j file and thanks to this file I can write the logs to a log file but what I want is not to write to a log file.I want separate log files to be kept for each thread and they are not compatible with each other. Is it possible ?

I using this log4j.properties

#log4j.rootLogger = INFO, FILE
log4j.rootLogger = DEBUG, DAILY
# Define the FILE appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.R.File=Logfile.log

# Define the layout for FILE appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %t %-5p %c %M %x - %m%n 

# Define the DAILY appender
log4j.appender.DAILY=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DAILY.File=Logfile.log
log4j.appender.DAILY.DatePattern='.'yyyyMMdd

# Define the layout for DAILY appender
log4j.appender.DAILY.layout=org.apache.log4j.PatternLayout
log4j.appender.DAILY.layout.conversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %t %-5p %c %M %x - %m%n 

But I must change this now. For example, I have 2 classes extended from the thread running on the main class. these classes are called foo and bar. I want it to be written to the log file number 1 while the foo class is running, and to the log file number 2 while the bar class is running. What should I do ?

safa aytan
  • 431
  • 1
  • 6
  • 16
  • 1
    Does this answer your question? [How can I create 2 separate log files with one log4j config file?](https://stackoverflow.com/questions/9652032/how-can-i-create-2-separate-log-files-with-one-log4j-config-file) – fantaghirocco Oct 07 '20 at 06:52
  • Have yo check this? https://logging.apache.org/log4j/2.x/manual/thread-context.html – Habil Oct 07 '20 at 07:12

0 Answers0