log4j:Appender to print the log Statements
Asked Answered
N

2

1

Hello sir: When server is started ,the log files print the output statement..how can i print the log files in my own file?

Noll answered 25/5, 2011 at 12:2 Comment(0)
L
1

Configure a log4j properties file with file appender. Something like this -

log4j.rootLogger=WARN, fileAppender
log4j.logger.myPackage=DEBUG, fileAppender
log4j.additivity.myPackage=false
log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.File= C://Myfile.log
log4j.appender.fileAppender.MaxFileSize=1024KB 
log4j.appender.fileAppender.MaxBackupIndex=5 
log4j.appender.fileAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.fileAppender.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
Landside answered 25/5, 2011 at 12:10 Comment(2)
Actually my Question is creating one own appender in that i have to catch log details and send it through web service...how can i do please guide meNoll
Go thorugh these links, hope it helps. avajava.com/tutorials/lessons/… blog.idleworx.com/2010/01/…Landside
O
2

You can try using a properties file

log4j.rootLogger=INFO, ERRORFILE

#ERRORFILE - used to log error messages
log4j.appender.ERRORFILE=org.apache.log4j.RollingFileAppender
log4j.appender.ERRORFILE.Threshold=ERROR
log4j.appender.ERRORFILE.File=errorLog.log
log4j.appender.ERRORFILE.MaxFileSize=200KB
log4j.appender.ERRORFILE.MaxBackupIndex=5
log4j.appender.ERRORFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ERRORFILE.layout.ConversionPattern=%d{DATE} %t - %m%n

In this example, I configured a properties file to log error messages to my own file, errorLog.log. Here's another sample.

Orme answered 25/5, 2011 at 12:7 Comment(0)
L
1

Configure a log4j properties file with file appender. Something like this -

log4j.rootLogger=WARN, fileAppender
log4j.logger.myPackage=DEBUG, fileAppender
log4j.additivity.myPackage=false
log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.File= C://Myfile.log
log4j.appender.fileAppender.MaxFileSize=1024KB 
log4j.appender.fileAppender.MaxBackupIndex=5 
log4j.appender.fileAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.fileAppender.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
Landside answered 25/5, 2011 at 12:10 Comment(2)
Actually my Question is creating one own appender in that i have to catch log details and send it through web service...how can i do please guide meNoll
Go thorugh these links, hope it helps. avajava.com/tutorials/lessons/… blog.idleworx.com/2010/01/…Landside

© 2022 - 2024 — McMap. All rights reserved.