我正在尝试使用slf4j和log4j2一次登录到多个记录器。我有两个问题。
这是我的.properties文件的内容:
status = error
dest = err
name = PropertiesConfig
property.filename = mylogfile.log
filter.threshold.type = ThresholdFilter
filter.threshold.level = all
appenders = console,rolling,smtp
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %m%n
appender.console.filter.threshold.type = ThresholdFilter
appender.console.filter.threshold.level = error
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = mylogfile-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d %p %C{1.} [%t] %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 2
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=100MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 15
appender.smtp=org.apache.log4j.net.SMTPAppender
appender.smtp.type=smtp
appender.smtp.name=Email
appender.smtp.from=xxxxx@gmail.com
appender.smtp.to=xxxx@gmail.com
appender.smtp.subject=Log of messages
appender.smtp.bufferSize=512
appender.smtp.smtpProtocol=smtps
appender.smtp.smtpHost=smtp.gmail.com
appender.smtp.smtpPort=465
appender.smtp.filter= error
appender.smtp.smtpPassword=xxxxx
appender.smtp.smtpUsername=xxxxx
loggers = rolling,email
logger.rolling.name = com.axx
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRef.rolling.ref = RollingFile
logger.email.name = com.axx
logger.email.level = error
logger.email.additivity = false
logger.email.appenderRef.smtp.ref = Email
rootLogger.level = info
rootLogger.appenderRef.stdout.ref = STDOUT
这是pom文件的依赖项
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.8.0-beta2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j18-impl</artifactId>
<version>2.11.1</version>
</dependency>
如果“ loggers”行如下所示:
loggers = rolling,email
然后我收到电子邮件,但没有任何内容写入日志文件。如果我倒过来,像这样:
loggers = email,rolling
然后我已登录文件,但没有电子邮件。
我的目标是将所有内容记录在文件中,并将错误发送到预定义的电子邮件中。
感谢所有提示和帮助。