博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
log4j2配置
阅读量:7086 次
发布时间:2019-06-28

本文共 2135 字,大约阅读时间需要 7 分钟。

Log4j2

Apache Log4j 2 is an upgrade to Log4j that provides significant improvements over its predecessor

Table of contents

环境搭建

一般java工程:

下载

apache官网给的链接是清华镜像网站的,国外的很多开源的在国内太慢的话不妨尝试一下国内的最大镜像站,下载地址,

配置到环境

To use Log4j 2 in your application make sure that both the API and Core jars are in the application’s classpath. Add the dependencies listed below to your classpath. -----这是官网的原话,翻译过来就是,使用log4j2的方式是,将接口jar和实现jar放到所需项目的classpath中,并添加依赖,具体就是log4j-api-2.11.0.jar和log4j-core-2.11.0.jar

配置文件路径

log4j2.xml可以放在任意的地方,只要你最后把它放到了classpath里,上面的项目中新建一个resources目录用于放置log4j2.xml,如果在未加入classpath时尝试运行时会报如下错误:

ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See 
for instructions on how to configure Log4j 2

大义就是运行的项目没有在classpath 中找到你的配置文件

以Eclipse环境为例,可以在Run—Run Configurations对应项目的Classpath中选择User Entries,点击Advanced,选择Add Folder,把resources文件夹添加进来。

idea环境

熟悉idea的话点击右上方放大镜图标左侧的图标

1394862-20180616215217477-1697213702.png

再点击左侧边栏Project Settings下的Modules

1394862-20180616215332359-324087624.png

扩展一下,点了之后,右侧边栏区域

1394862-20180616215400976-1899710376.png

表示的是已作为classpath的文件夹,这里可以从已设置为classpath的文件夹中取消选择,

取消掉以后记得按下下方的apply保存一下

选中右侧出现的工程目录中你用来存放配置文件log4j2.xml中的文件夹,点击一下选中,再点击resource,右侧边栏就会多出一下你选中的文件,点下方的apply即可

配置详解

testlog/mylog

转载于:https://www.cnblogs.com/selton/p/9191537.html

你可能感兴趣的文章
测试用例编写规范
查看>>
Linux vsftpd服务器
查看>>
使用ADRCI打oracle故障包
查看>>
简易更改win系统的连接
查看>>
Apache+PHP+SSL 安装步骤
查看>>
IPSEC ***学习笔记 (二)
查看>>
JQuery学习笔记-操作DOM元素
查看>>
【远程医疗专题】远程医疗论文30篇及解决方案10篇
查看>>
crondtab 定时任务
查看>>
【ios】导航跳转
查看>>
linux下建立回收站防止误删除及定期清空
查看>>
动态安全模型
查看>>
liuux/ Unix 文件管理命令(五)
查看>>
Hadoop学习笔记之二:HDFS体系架构
查看>>
foreman架构的引入4-安装Foreman1.6.3架构(foreman与puppetmaster分离)
查看>>
W和L
查看>>
TCP/IP协议解析
查看>>
德国罗森伯格推出MU Uniboot数据中心高密度布线系统
查看>>
Centos以及windows2003server系统下的密码重置
查看>>
CCNA学习笔记 一 基础方面
查看>>