View RSS Feed

My Java Tips

log4j.properties file

Rate this Entry
by , 11-03-2011 at 12:34 PM (1711 Views)
log4j.properties file is a configuration file (not in XML format). If you have a stand alone application, then log4j.properties should be in the directory where you issued the java command. In case of web application (JSP/Servlet), place log4j.properties at /WEB-INF/classes/.



A sample properties file is given below:

log4j.appender.stdout=org.apache.log4j.ConsoleAppe nder
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.Patt ernLayout
log4j.appender.stdout.layout.ConversionPattern=[%d{MMM dd HH:mm:ss}] %-5p (%F:%L) - %m%n
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.file=C:\Log4J\src\tmp\logs \log.txt
log4j.appender.FILE.layout=org.apache.log4j.Patter nLayout
log4j.appender.FILE.layout.ConversionPattern=[%d{MMM dd HH:mm:ss}] %-5p (%F:%L) - %m%n
log4j.rootLogger=debug, FILE,stdout

We have used only two appenders (ConsoleAppender and FileAppender)in the example above. All the possible appender options are:

AppenderSkeleton, AsyncAppender, ConsoleAppender, DailyRollingFileAppender, ExternallyRolledFileAppender, FileAppender, JDBCAppender, JMSAppender, LF5Appender, NTEventLogAppender, NullAppender, RollingFileAppender, SMTPAppender, SocketAppender, SocketHubAppender, SyslogAppender, TelnetAppender, WriterAppender

Submit "log4j.properties file" to Facebook Submit "log4j.properties file" to Digg Submit "log4j.properties file" to del.icio.us Submit "log4j.properties file" to StumbleUpon Submit "log4j.properties file" to Google

Tags: None Add / Edit Tags
Categories
Java SE , XML

Comments