簡體   English   中英

獲取 Log4j2 錯誤

[英]Getting Log4j2 errors

我的 log4j2 屬性文件:

status = warn
name= properties_configuration

#Directory path where log files will be stored
property.basePath = ./log/

#File logger
appender.rolling.type = RollingFile
appender.rolling.name = fileLogger
appender.rolling.fileName= ${basePath}app.log
appender.rolling.filePattern= ${basePath}app_%d{yyyyMMdd}.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %msg%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.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.delete.type = Delete
appender.rolling.strategy.delete.basePath = ${basePath}
appender.rolling.strategy.delete.maxDepth = 1
appender.rolling.strategy.delete.ifLastModified.type = IfLastModified
appender.rolling.strategy.delete.ifLastModified.age = 30d

#Root logger configuration
rootLogger.level = info
rootLogger.additivity = false
rootLogger.appenderRef.rolling.ref = fileLogger

我正在使用 Lombok @Log4j2 注釋:

@Log4j2
public class BotApplication {
    public static void main(String[] args) {
        ApiContextInitializer.init();
        TelegramBotsApi telegram = new TelegramBotsApi();
        Bot bot = new Bot();
        try {
            telegram.registerBot(bot);
            log.info("Bot successfully connected.");
        } catch (TelegramApiRequestException e) {
            log.error("Can't start Bot. Error: {}", e.getMessage());
        }
    }
}

應用程序正確地將日志寫入文件,但總是在我運行我的應用程序時,我的控制台出現錯誤:

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

似乎這些錯誤不會影響記錄器,但我想以某種方式刪除它們。

帶有“log4j:WARN”的錯誤消息來自 log4j 1.x。 此錯誤意味着您的類路徑中有 log4j 1.x jar,但不存在 Log4j 1.x 配置。

如果您不想使用 log4j 1(並且您不應該使用),則將 Log4j 2 中的 log4j-1.2-api jar 添加到您的項目中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM