Best web site - The log4j configuration file shown in Example 15-5
The log4j configuration file shown in Example 15-5 sends log messages to only a single destination, the console. However, you can configure the log messages to go to multiple locations and also have certain messages go to certain locations based on the level of the message and other parameters. Example 15-6 shows a simple example using two appenders. Example 15-6. A log4j configuration file using two appenders # A sample log4j configuration file # Create two appenders, one called stdout and the other calledrollinglog4j.rootLogger=DEBUG, stdout, rolling # Configure the stdout appender to go to the consolelog4j.appender.stdout=org.apache.log4j.ConsoleAppender # Configure the stdout appender to use the PatternLayoutlog4j.appender.stdout.layout=org.apache.log4j.PatternLayout # Pattern to output the caller’s filename and line numberlog4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) -%m%n # Configure the rolling appender to be a RollingFileAppenderlog4j.appender.rolling=org.apache.log4j.RollingFileAppender # Configure the name of the logout for the rolling appenderlog4j.appender.rolling.File=output.log # Set up the maximum size of the rolling log filelog4j.appender.rolling.MaxFileSize=100KB # Keep one backup file of the rolling appenderlog4j.appender.rolling.MaxBackupIndex=1 # Configure the layout pattern and conversion pattern for therolling appenderlog4j.appender.rolling.layout=org.apache.log4j.PatternLayoutlog4j.appender.rolling.layout.ConversionPattern=%d{ABSOLUTE} - %p %c - %m%n The log4j configuration file in Example 15-6 creates one appender that logs messages to the console, just as in Example 15-5, and another appender that logs messages to a log file called output.log. Again, we won’t try to cover all of the configuration settings for log4j; you can learn more from the log4j web site. 15.4.5.2 Initializing using an XML file The second approach to initializing the configuration properties for the log4j environment is to use an XML file. Example 15-7 illustrates an XML file that configures the same information as in Example 15-5.
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.