An Entry Example of Log4j
The log4j can be configured both programmatically and externally using special configuration files. External configuration is most preferred, because
to take effect it doesn’t require change in application code, recompilation, or redeployment. Configuration files can be XML files or Java property files that can be created and edited using any text editor or XML editor, respectively.
1. Programmatically configure log4j
This example is from this site, the code is messy, so why not make it clean.
|
Here is the snapshot of output:
2. Configure Log4j externally
Create a file named “log4j.properties” in the “src” directory of your project.
# Define the root logger with appender file
log = /home/ryan/Desktop/log4j
log4j.rootLogger = DEBUG, FILE # Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${log}/log.out # Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n
Here is the java code.
|
The log will be printed on the log.out file in /home/ryan/Desktop/log4j directory.
An Entry Example of Log4j的更多相关文章
- lucene构建restful风格的简单搜索引擎服务
来自于本人博客: lucene构建restful风格的简单搜索引擎服务 本人的博客如今也要改成使用lucene进行全文检索的功能,因此在这里把代码贴出来与大家分享 一,文件夹结构: 二,配置文件: 总 ...
- Jetty启动报Error scanning entry META-INF/versions/9/org/apache/logging/log4j/util/ProcessIdUtil.class
近日在项目中集成Elasticsearch后,Jetty启动报错. 错误日志如下: Suppressed: |java.lang.RuntimeException: Error scanning en ...
- log4j 文档
log4j中文文档 中文详细教程 log4j中文文档 这篇文章描述了Log4j的API.独一无二的特色和设计原理.Log4j是一个聚集了许多作者劳动成果的开源软件项目.它允许开发人眼以任意的粒度 ...
- Log4J基础详解及示例大全
去年这个时候,为做软件工程的大作业就详细学过Log4J的用法了,时隔一年想要在新的项目中好好使用一下的时候,发现几乎全忘了,悲催啊-- 再上网查资料,总是不能找到一篇符合我的口味,拿来就能轻松上手,方 ...
- Log4j的ConversionPattern无缝适配到Logback
为了能将log4j的ConversionPattern无缝应用到logback上来,需要对两个Conversion做适配,具体可以参考:Log4j 与 Logback的ConversionPatter ...
- log4j使用教程详解(怎么使用log4j2)
1. 去官方下载log4j 2,导入jar包,基本上你只需要导入下面两个jar包就可以了(xx是乱七八糟的版本号): log4j-core-xx.jar log4j-api-xx.jar 2. 导入到 ...
- Log4j 2使用教程
Log4j 2的好处就不和大家说了,如果你搜了2,说明你对他已经有一定的了解,并且想用它,所以这里直接就上手了. 1. 去官方下载log4j 2,导入jar包,基本上你只需要导入下面两个jar包就可以 ...
- log4j 总结 精华
去年这个时候,为做软件工程的大作业就详细学过Log4J的用法了,时隔一年想要在新的项目中好好使用一下的时候,发现几乎全忘了,悲催啊…… 再上网查资料,总是不能找到一篇符合我的口味,拿来就能轻松上手,方 ...
- log4j.properties文件配置--官方文档
Default Initialization Procedure The log4j library does not make any assumptions about its environme ...
- Log4j 2.0 使用说明
原文地址:http://blog.csdn.net/welcome000yy/article/details/7962447 Log4j 2.0 使用说明(1) 之HelloWorld 最近刚接触 ...
随机推荐
- psutil 检测exe是否已经运行
安装依赖 pip install psutil 代码 import psutil def check_if_process_running(process_name): ''' Check if th ...
- python 读取mysqlDB中指定的表名的DDL语句
注意: 1. 此python文件不要起名为mysql,会跟import的包名重复,python mysql.py运行报错 2.如果需要带端口号,请加database后加上, port="33 ...
- MRO, mixin的解读
本文试着将python中类继承中方法解析顺序MRO(method resolution order)和mixin梳理清楚 先MARK 类的继承中,super()的使用还是蛮多讲究的,因为看pytorc ...
- 使用Hexo主题搭建个人博客(markdown)
依赖环境 安装node.js:node.js下载可以从其官方界面开始https://nodejs.org/zh-cn/ 安装git:git下载则可以从其官方界面开始https://git-scm.co ...
- Spring —— bean实例化
bean 实例化 bean本质上就是对象,创建bean使用构造方法完成(反射) 构造方法(常用) 静态工厂* 实例工厂* FactoryBean(实 ...
- 加入 Flutter Engage,Pick 您的专属 Dash 形象!
Flutter Engage 活动精彩来袭 对 Flutter 团队的开发者们来说,交流的重要性不言而喻,和您一样,我们也希望开发者们能够在不同的情境下进行互动分享.于是我们为您准备了一场特别的线上活 ...
- kaggle入门 随机森林求解Titanic
# kaggle Titanic # 导入需要的库 import pandas as pd import numpy as np import sys import sklearn import ra ...
- Docker基本操作(端口?网络模式?)(五)
一.端口暴露 Docker 容器更多情况下是用来运行 Web 应用的,所以要如何访问到容器中的 Web 服务呢?比如我们现在运行一个 nginx 容器服务: $ docker run --name w ...
- php生成验证码类
php生成验证码类 直接看代码 <?php session_start(); class Code{ //资源 private $img; //画布宽度 private $width=100; ...
- Android :安卓学习笔记之 Handler机制 的简单理解和使用
目录 Handler机制 1.Handler使用的引出 2.背景和定义 3.作用和意义 4.主要参数 5.工作原理及流程 5.1.对应关系 6.深入分析 Handler机制源码 6.1.Handler ...