File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Log4J - File appender in 2 or more files for the same package.

 
Dhana Sen
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

My requirement is i want to create 2 files for the same package level using file appender(Eg: com.foo.bar).

my code:

log4j.rootCategory= ALL, fileAppender,stdout

log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.File=c:\\temp\\test.log
log4j.appender.fileAppender.MaxFileSize=64KB
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.file1=org.apache.log4j.RollingFileAppender
log4j.appender.file1.File= file1.log
log4j.appender.file1.MaxFileSize=64KB
log4j.appender.file1.MaxBackupIndex=1
log4j.appender.file1.layout=org.apache.log4j.PatternLayout
log4j.appender.file1.layout.ConversionPattern=%p %t %c - %m%n

log4j.appender.file2=org.apache.log4j.RollingFileAppender
log4j.appender.file2.File= file2.log
log4j.appender.file2.MaxFileSize=64KB
log4j.appender.file2.MaxBackupIndex=1
log4j.appender.file2.layout=org.apache.log4j.PatternLayout
log4j.appender.file2.layout.ConversionPattern=%p %t %c - %m%n

log4j.appender.file3=org.apache.log4j.RollingFileAppender
log4j.appender.file3.File= file3.log
log4j.appender.file3.MaxFileSize=64KB
log4j.appender.file3.MaxBackupIndex=1
log4j.appender.file3.layout=org.apache.log4j.PatternLayout
log4j.appender.file3.layout.ConversionPattern=%p %t %c - %m%n

// THIS IS FOR ClIENT
log4j.logger.com.ls.es.service=DEBUG, file1
// THIS IS FOR SUPPORT
log4j.logger.com.ls.es.service=DEBUG, file2
// THIS IS ERROR MESSAGE
log4j.logger.com.ls.es.service=ERROR, file3

Here file1 is for Client(Client Admin)and file2 is for Support.

but am getting only file3.log file which is for Error Message..
some where configuration is missing...

Thanks,

by
dhana
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont think it possible to set more than one level to one logger(in your case, you are trying to set com.foo.bar package to DEBUG and ERROR levels). In your case, the com.foo.bar package will be set to ERROR level.
Also, instead of:

// THIS IS FOR ClIENT
log4j.logger.com.ls.es.service=DEBUG, file1
// THIS IS FOR SUPPORT
log4j.logger.com.ls.es.service=DEBUG, file2


You can do:



But if you specify


then it will override the above DEBUG settings and you wont get any DEBUG messages
 
Dhana Sen
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
log4j.rootCategory= INFO, fileAppender,stdout

i have changed the Log level to INFO in my log Root

now am getting 2 files- file2 & file3.. but file1 is not creating..
am using Weblogic..

by
dhana
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try out:



Instead of:
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not very sure about the requirement .If its like you want to have logs to be logged in two files then create 2 rolling file appender with different files and then add the appender to the logger.It possible in log4j to have 2 appenders for the same logger.Even with different set of appended properties.
It this your question ?
Hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic