log4j 日志正在写入控制台,但未写入日志文件

3df52oht  于 2022-11-06  发布在  其他
关注(0)|答案(1)|浏览(153)

最近我从log4j1.x迁移到了log4j2.x。我已经用www.example.com文件替换log4j.propertieslog4j2.properties。我在控制台中打印了日志,但在sac.log文件中没有打印日志。
Pom文件:

  • 日志4j-jcl:2.17.1
  • log4j内核:2.17.1
  • 日志4j-API:2.17.1
  • Jackson核心:2.13.1
  • Jackson注解:2.13.1
  • Jackson数据绑定:2.13.1

Log4j.properties:

log4j.rootLogger=INFO, stdout, RollingLog
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%C{0}.%M:(%L) - %m%n

log4j.appender.RollingLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingLog.Threshold=TRACE
log4j.appender.RollingLog.File=SD/sac.log
log4j.appender.RollingLog.Append=true
log4j.appender.RollingLog.DatePattern=.yyyy-MM-dd
log4j.appender.RollingLog.layout=net.logstash.log4j.JSONEventLayoutV1
log4j.appender.RollingLog.rolling.rollingPolicy = org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.RollingLog.rollingPolicy.FileNamePattern = SD/sac/sac-{yyyyMMdd}.log.gz

Log4j2.properties:

status = error
dest = err

filter.threshold.type = ThresholdFilter
filter.threshold.level = trace

appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern =%C{0}.%M:(%L) - %m%n

# File Appender for JSON log file.

appender.rolling.type = RollingFile
appender.rolling.name = RALLog
appender.rolling.fileName = SD/sac.log
appender.rolling.filePattern = SD/sac/sac-{yyyyMMdd}.log.gz
appender.rolling.layout.type = JsonLayout
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy

logger.rolling.name = SD
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRef.rolling.ref = RALLog

rootLogger.level = info
rootLogger.appenderRef.stdout.ref = STDOUT

A.java

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class A {

    private static final Log logger = LogFactory.getLog(A.class);
hwazgwia

hwazgwia1#

您的logger.rolling记录器配置的name是“SD”,因此只有记录器“SD”和名称以“SD.”开头的记录器将记录到您的文件。
A类中使用的记录器的名称是该类的完全限定名称。

相关问题