[Logo]
Forums Register Login
Log4J - File appender in 2 or more files for the same package.
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
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
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
Did you try out:



Instead of:
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.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Oct 21, 2017 08:52:36.