0

我的部分代码:

public class TestContext {
    
    private static TestContext textContext = null;
    private  WebDriver driver;
    static ConfigFileReader configFileReader = new ConfigFileReader();
    private static Logger log = LogManager.getLogger(TestContext.class.getName());
    
     public static void main(String[] args) 
        {
         log.debug("Debug Message Logged !!!");
         log.info("Info Message Logged !!!");
         log.error("Error Message Logged !!!");
        }

当我运行它时在控制台中:

17:17:49.037 [main] ERROR Util.TestContext - 记录错误消息!!!

属性文件:

status = error
name = PropertiesConfig
 
#Make sure to change log file path as per your need
property.filename = C:/logs/debug.log
 
filters = threshold
 
filter.threshold.type = ThresholdFilter
filter.threshold.level = debug
 
appenders = rolling
 
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = debug-backup-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 20
 
loggers = rolling
 
#Make sure to change the package structure as per your application
 
logger.rolling.name = com.howtodoinjava
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRef.rolling.ref = RollingFile

配置文件所在: 在此处输入图片描述

依赖项:

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.14.1</version>
  </dependency>
  
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.14.1</version>
  </dependency>

是不是因为找不到属性文件???

4

1 回答 1

0

当我将属性文件直接放在 src/test/resources 下时,问题就解决了。

于 2021-08-13T14:19:20.380 回答