[Java]Configuration of Log4j

本文详细解析了一个使用Log4j进行多日志记录的配置文件,包括控制台输出、滚动日志文件的设置及标准日志级别配置。
Here is a configuration file that uses multiple appenders.
=====================================================================
log4j.rootLogger=debug, stdout, R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=example.log

log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
=====================================================================

For the standard levels, we have DEBUG < INFO < WARN < ERROR < FATAL

If you wants more information of log4j, go to my blog in baidu to find what you need

Exception in thread "main" java.lang.AbstractMethodError: Receiver class org.springframework.boot.logging.log4j2.SpringBootConfigurationFactory does not define or inherit an implementation of the resolved method abstract getConfiguration(Lorg/apache/logging/log4j/core/config/ConfigurationSource;)Lorg/apache/logging/log4j/core/config/Configuration; of abstract class org.apache.logging.log4j.core.config.ConfigurationFactory. at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:509) at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:449) at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:257) at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:565) at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:582) at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:217) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45) at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194) at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:551) at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:537) at com.chinaway.execute.DeploymentListener.<clinit>(DeploymentListener.java:24)
最新发布
06-05
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值