网上不少文章给的都是用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 2使用properties文件进行配置的更多相关文章

  1. jdbc.properties 文件的配置

    jdbc.properties文件的配置   使用配置文件访问数据库的优点是: 一次编写随时调用,数据库类型发生变化只需要修改配置文件. 配置文件的设置: 在配置文件中,key-value对应的方式编 ...

  2. java读取properties文件的配置信息

    项目开发中,我们一般来向 application.properties 文件中放一些全局配置变量,以便程序中读取使用,本篇内容来演示从properties配置文件中读取键值. 当然,我们不一定写入 a ...

  3. 每日一蠢 .kettle 下的kettle.properties文件内配置的内容不能被识别

    昨天装封装好的ETL 工具  窝将环境变量中的KETTLE_HOME删除了, 结果 .kettle 下的kettle.properties文件内配置的内容不能被识别 can't parse argum ...

  4. application.properties文件常用配置

    项目一直在用properties文件写配置,因为配置不是自己来写所以也从来没有研究过各个配置的含义,所以对很多配置也是一知半解,只是知道可以这样用,但是不知道为什么能这样用.自己抽空找了一下资料做个记 ...

  5. log4j.properties文件的配置

    Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综合使用这三个组件可以轻松 ...

  6. 【转】log4j.properties文件的配置

    一.前言 log4j使用的还是比较多的,但是对于其配置又很难描述清楚要怎么配置,说明我自己对于log4j的配置并不是非常熟悉,所以在网上找了一篇详尽的 博文转载,在此非常感谢原文作者的辛苦付出,如有需 ...

  7. Liferay SDK 6.2与7.0中build.[$username].properties 文件的配置

    这篇文章是针对刚开始开发Liferay的新手写的,希望能够帮到刚入门的开发者减少一些配置上的麻烦. 前提: 1. 下载了Liferay IDE(Liferay的官方开发工具) 2.下载了Liferay ...

  8. 将properties文件的配置设置为整个Web应用的全局变量。

    四种作用域: Web应用中的变量存放在不同的jsp对象中,会有不一样的作用域,四种不同的作用域排序是 pageContext < request < session < applic ...

  9. java工具类获取properties文件的配置

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.i ...

随机推荐

  1. laravel5.2总结--路由

      1 基本路由   1.1 定义路由的文件 app/Http/routes.php   1.2 最基本的路由: Route::get(''index", function () { ret ...

  2. Robotium接入到Jenkins持续集成自动化测试

    6.3 将测试用例接入到Jenkins 由于我是自己学习的手机自动化测试,没有实际投入到工作中使用,jenkins的接入也没有具体操作,现摘抄一下网页:http://www.tuicool.com/a ...

  3. PostgreSQL drop database 显示会话没有关闭 [已解决]

    错误重现 有时候需要删除某个数据库时,会报如下错误,显示有一个连接正在使用数据库,无法删除 ERROR: database "pilot" is being accessed by ...

  4. Java求职实战之继承和多态

    1.final修饰变量时,是引用不能变,还是引用的对象不能变? 是指引用变量不能变,引用对象的内容可以变. 2.==和equals有什么区别? 网上搜索一下,发现很多人解释的都比较清楚了.自己简单概括 ...

  5. 聊聊、Integer 封装特性

    前几天在公司内部群,有人分享出了一道题,问谁能口算出来,他就膜拜那个人.题目如下: Class cache = Integer.class.getDeclaredClasses()[0]: Field ...

  6. DFS和BFS遍历的问题

    来自https://github.com/soulmachine/leetcode 广度优先搜索 输入数据:没有什么特征,不像dfs需要有递归的性质.如果是树/图,概率更大. 状态转换图:数或者DAG ...

  7. nyoj 题目6 喷水装置

    喷水装置(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 现有一块草坪,长为20米,宽为2米,要在横中心线上放置半径为Ri的喷水装置,每个喷水装置的效果都会让以 ...

  8. MOS管使PIC单片机不能正常运行

    程序: #include "led.h" void InitLed(void) { TRISB &= ~0x70; ANSELB &= ~0x70; } void ...

  9. How Many to Be Happy?

    How Many to Be Happy? 时间限制: 1 Sec  内存限制: 128 MB 题目描述 Let G be a connected simple undirected graph wh ...

  10. [ARC082F] Sandglass(线段树)

    Description 有一个沙漏由两个上下相通玻璃球 \(A\) 和 \(B\) 构成,这两个玻璃球都含有一定量的沙子,我们暂且假定 \(AB\) 中位于上方的玻璃球的为 \(U\),下方的玻璃球为 ...