下面是 log4j 属性和 Java 代码。所有日志都仅在调试中记录。我什至尝试添加阈值,但还没有运气。我需要根据日志级别将日志语句记录在单独的文件中。
所有日志都只记录在调试日志文件中,如果我删除调试日志,那么它会记录在信息日志文件中。
给予阈值选项也不起作用。
log4j.rootLogger = OFF
#define the console appender
log4j.appender.consoleAppender = org.apache.log4j.ConsoleAppender
# now define the layout for the appender
log4j.appender.consoleAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
# now define the rollingFIle appender
log4j.category.com=error, myErrorappender
log4j.additivity.com=false
log4j.appender.myErrorappender=org.apache.log4j.RollingFileAppender
log4j.appender.myErrorappender.File=/Users/uthaman/Documents/workspace/Logging/myErrorlog.log
log4j.appender.myErrorappender.MaxFileSize=2MB
log4j.appender.myErrorappender.MaxBackupIndex=2
log4j.appender.myErrorappender.layout = org.apache.log4j.PatternLayout
log4j.appender.myErrorappender.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c (%F:%L) - %m%n
log4j.category.com=info,myInfoappender
log4j.additivity.com=false
log4j.appender.myInfoappender=org.apache.log4j.RollingFileAppender
log4j.appender.myInfoappender.File=/Users/user/Documents/workspace/Logging/myInfolog.log
log4j.appender.myInfoappender.MaxFileSize=2MB
log4j.appender.myInfoappender.MaxBackupIndex=2
log4j.appender.myInfoappender.layout = org.apache.log4j.PatternLayout
log4j.appender.myInfoappender.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c (%F:%L) - %m%n
log4j.category.com=debug,myDebugappender
log4j.additivity.com=false
log4j.appender.myDebugappender=org.apache.log4j.RollingFileAppender
log4j.appender.myDebugappender.File=/Users/user/Documents/workspace/Logging/myDebuglog.log
log4j.appender.myDebugappender.MaxFileSize=2MB
log4j.appender.myDebugappender.MaxBackupIndex=2
log4j.appender.myDebugappender.layout = org.apache.log4j.PatternLayout
log4j.appender.myDebugappender.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c (%F:%L) - %m%n
这是记录日志语句的 java 代码:
public class Logging {
private static Logger logger = Logger.getLogger(Logging.class);
public static void main(String[] args) {
logger.error("This is error");
logger.info("This is info");
logger.debug("This is debug");
}
}