log4j 2使用properties文件进行配置
2017-09-06 14:12
543 查看
网上不少文章给的都是用xml进行配置,也会提到无法使用properties文件对log4j进行配置,但那应该只是在他们写文章的时候才是如此,最新的2.8.2版本经过我试验后是可以做到的当然该文件最好放在特定的目录中才行,官方文档也提到了
1.Log4j will inspect the "log4j.configurationFile" system property and, if set, will attempt to load the configuration using the ConfigurationFactory that matches the file extension. 2.If no system property is set the YAML ConfigurationFactory will look for log4j2-test.yaml or log4j2-test.yml in the classpath. 3.If no such file is found the JSON ConfigurationFactory will look for log4j2-test.json or log4j2-test.jsn in the classpath. 4.If no such file is found the XML ConfigurationFactory will look for log4j2-test.xml in the classpath. 5.If a test file cannot be located the YAML ConfigurationFactory will look for log4j2.yaml or log4j2.yml on the classpath. 6.If a YAML file cannot be located the JSON ConfigurationFactory will look for log4j2.json or log4j2.jsn on the classpath. 7.If a JSON file cannot be located the XML ConfigurationFactory will try to locate log4j2.xml on the classpath. 8.If no configuration file could be located the DefaultConfiguration will be used. This will cause logging output to go to the console.
name = PropertiesConfig property.filename = target/logs #appenders = console, file #配置值是appender的类型,并不是具体appender实例的name appenders = rolling appender.rolling.type = RollingFile appender.rolling.name = RollingLogFile appender.rolling.fileName=${filename}/automationlogs.log appender.rolling.filePattern = ${filename}/automationlogs-%d{MM-dd-yy-HH-mm-ss}-%i.log appender.rolling.layout.type = PatternLayout appender.rolling.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n appender.rolling.policies.type = Policies appender.rolling.policies.size.type = SizeBasedTriggeringPolicy appender.rolling.policies.size.size=100MB appender.rolling.strategy.type = DefaultRolloverStrategy appender.rolling.strategy.max = 5 rootLogger.level = trace rootLogger.appenderRef.rolling.ref = rolling rootLogger.appenderRef.rolling.ref = RollingLogFile
相关文章推荐
- log4j的使用与java中properties配置文件加载
- log4j.properties文件的配置与使用
- 使用common-configuration进行对配置文件的操作(xml,properties)
- 复习课程jdbc:使用配置文件properties进行连接数据库,数据库存取图片,批处理,时间戳,事物回滚等等
- log4j的2.6.2版本properties配置文件的使用举例
- 用Properties读取配置文件后,使用TreeMap对keys进行排序
- Log4j学习(使用流程,Log4j.properties配置文件,配置到多个不同目标)
- java工程使用log4j和properties文件详细配置
- ArrayList 与HashSet的比较,及应用反射读取properties配置文件中的数据进行实例化再调用,以及类加载器的使用;还有HashCode的分析,及导致内存泄露,内存溢出的原因之一
- log4j的使用与java中properties配置文件加载
- 配置log4j.properties文件
- 一个比较全的的log4j配置文件(log4j.properties)转载
- 如何使用svconfigeditor.exe编辑WCF Service配置文件--配置Diagnostics进行WCF Service的log和Trace(三)
- 使用PHP对配置文件进行修改
- web 项目中 在spring中使用log4j 定时刷新log4j配置文件
- web 项目中 在spring中使用log4j 定时刷新log4j配置文件
- hibernate3 学习笔记(三) hibernate 日志配置文件 log4j.properties
- 谈Java Properties配置文件, 是J2EE容器的命令行绑定, 还是使用Deploy自适应的绑定?
- 《Pro Spring》学习笔记之使用properties文件进行依赖注入
- 谈Java Properties配置文件, 是J2EE容器的命令行绑定, 还是使用Deploy自适应的绑定?