This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes Log4J - File appender in 2 or more files  for the same package. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Log4J - File appender in 2 or more files  for the same package." Watch "Log4J - File appender in 2 or more files  for the same package." New topic
Author

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

Dhana Sen
Ranch Hand

Joined: Mar 05, 2006
Posts: 33
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

Joined: Jul 20, 2005
Posts: 9317
    
109

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


[My Blog] [JavaRanch Journal]
Dhana Sen
Ranch Hand

Joined: Mar 05, 2006
Posts: 33
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

Joined: Jul 20, 2005
Posts: 9317
    
109

Did you try out:



Instead of:
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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.


Rahul Bhattacharjee
LinkedIn - Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Log4J - File appender in 2 or more files for the same package.
 
Similar Threads
Log4j output files
Log4j - log in different files, same jar , different Main classes
Log4j - Compress Log Files
thread safe logging in a servlet
Logging