这是我的.properties文件,
property.filename = logs/app.log
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = "%-5p %c{1} - %m%n
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = logs/app-%d{MM-dd-yy}-%i.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%-5level] %d{DATE} %-5p [%t] %c{1} - %msg%n
appender.rolling.append = true
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 = 5
logger.rolling.name = org.springframework.boot
logger.rolling.level = info
logger.rolling.additivity = false
logger.rolling.appenderRef.rolling.ref = RollingFile
logger.rolling.name = com.org.abc.package
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRef.rolling.ref = RollingFile
rootLogger.level = fatal
rootLogger.appenderRef.stdout.ref = STDOUT
问题是我试图明确设置两个包的日志记录。但是,此配置不适用于这两个程序包。如何使用log4j2属性或yaml文件配置多个包的日志记录。
答案 0 :(得分:3)
loggers = springframework,application
logger.springframework.name = org.springframework.boot
logger.springframework.level = info
logger.springframework.appenderRefs = RollingFile
logger.springframework.additivity = true
logger.springframework.appenderRef.rolling.ref = RollingFile
logger.application.name = com.abc.package
logger.application.level = debug
logger.application.appenderRefs = RollingFile
logger.application.additivity = false
logger.application.appenderRef.rolling.ref = RollingFile
答案 1 :(得分:0)
您必须在log4j2文件中定义记录器名称 例如: loggers = com.pkg,com.spring