Hi all,
Am a fresher with logj4 and trying to configure my properties file.
My question is that how can i log differrent priorities of messages to different files using categories and appenders. help would me greatly appreciated.
This is my properties file. I ma not able to get the desired output even if i use a threshold value. Can anyone please explain me where i am going wrong???
This the code i am using for Java file---
package com.mobilefish;
import org.apache.log4j.Logger;
/**
*
* @author Mohd Raziuddin
*/
public class Log4jDemo {
static Logger log = Logger.getLogger(Log4jDemo.class.getName());
public static void main(String args[]){
//PropertyConfigurator.configure("log4j.properties");
log.debug("This is my debug message.");
log.info("This is my info message.");
log.error("This is my error message.");
log.warn("This is my warn message.");
log.fatal("This is my fatal message.");
}
}
And this is the properties file i have used to configure the log4j -
#log4j.threshold=ALL
#log4j.rootLogger= stdout,DebugAppender,InfoAppender,ErrorAppender,WarnAppender,FatalAppender
# Display all messages on console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n
log4j.category.com.mobilefish.Log4jDemo=DEBUG,DebugAppender
log4j.category.com.mobilefish.Log4jDemo.threshold=DEBUG
log4j.appender.DebugAppender=org.apache.log4j.FileAppender
log4j.appender.DebugAppender.File=debug.log
# Append to the end of the file or overwrites the file at start.
log4j.appender.DebugAppender.Append=false
log4j.appender.DebugAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.DebugAppender.layout.ConversionPattern=[%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n
log4j.appender.DebugAppender.threshold=DEBUG
log4j.category.com.mobilefish.Log4jDemo=INFO,InfoAppender
log4j.category.com.mobilefish.Log4jDemo.threshold=INFO
log4j.appender.InfoAppender=org.apache.log4j.FileAppender
log4j.appender.InfoAppender.File=Info.log
log4j.appender.InfoAppender.Append=false
log4j.appender.InfoAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.InfoAppender.layout.ConversionPattern=[%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n
log4j.appender.InfoAppender.threshold=INFO
log4j.category.com.mobilefish.Log4jDemo=ERROR,ErrorAppender
log4j.category.com.mobilefish.Log4jDemo.threshold=ERROR
log4j.appender.ErrorAppender=org.apache.log4j.FileAppender
log4j.appender.ErrorAppender.File=Error.log
log4j.appender.ErrorAppender.Append=false
log4j.appender.ErrorAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ErrorAppender.layout.ConversionPattern=[%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n
log4j.appender.ErrorAppender.threshold=ERROR
log4j.category.com.mobilefish.Log4jDemo=WARN,WarnAppender
log4j.category.com.mobilefish.Log4jDemo.threshold=WARN
log4j.appender.WarnAppender=org.apache.log4j.FileAppender
log4j.appender.WarnAppender.File=Warn.log
log4j.appender.WarnAppender.Append=false
log4j.appender.WarnAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.WarnAppender.layout.ConversionPattern=[%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n
log4j.appender.WarnAppender.threshold=WARN
log4j.category.com.mobilefish.Log4jDemo=FATAL,FatalAppender
log4j.category.com.mobilefish.Log4jDemo.threshold=FATAL
log4j.appender.FatalAppender=org.apache.log4j.FileAppender
log4j.appender.FatalAppender.File=Fatal.log
log4j.appender.FatalAppender.Append=false
log4j.appender.FatalAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.FatalAppender.layout.ConversionPattern=[%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n
log4j.appender.FatalAppender.threshold=FATAL
Now here's what i want --
ALL DEBUG messages should go to Debug.log...
All INFO messages should go to Info.log
All WARN messages should go to Warn.log
All ERROR messages should go to Error.log.... and so on ......@:~