Log4j 日志记录
关于Log4j的简单示例
<!--手动配置log4j.properties文件内容:-->
1 #level:debug/info/warn/error
log4j.rootLogger=OFF,stdout,file
log4j.logger.isoft=ERROR,file
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.layout=org.apache.log4j.SimpleLayout
log4j.appender.file.File=D: \\error.log
<!--log4j.proerties由tomcat自动获取内容,不需要用户代码实现-->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd ">
<!--bean...-->
<bean id="exceptionlogger" class="isoft.aop.ExceptionLogger"></bean> <!-- 定义方法的切入点 -->
<aop:config>
<aop:pointcut id="servicepointcut"
expression="execution(* isoft.serviceImpl.*.*(..))"></aop:pointcut>
<aop:aspect id="loggeraspect" ref="exceptionlogger">
<aop:after-throwing throwing="e" method="loggerException"
pointcut-ref="servicepointcut"/>
</aop:aspect>
</aop:config>
</beans>
import java.util.Date;
import org.apache.log4j.Logger;
/**
* 批注:
* org.apache.log4j.Logger中包含日志相关函数,
* 存在于log4j-xxx.jar中
*/
/**
* @author Sufeng
*
*/
/*descripation:该类是在发生异常时触发
* 保存到错误信息到指定目录
*/
public class ExceptionLogger {
Logger logger=logger = Logger.getLogger(ExceptionLogger.class);
public void loggerException(Exception e) {
StringBuilder Buf=new StringBuilder();
Buf.append("================="+new Date()+"==============");
StackTraceElement[] elements=e.getStackTrace();
for(StackTraceElement element:elements) {
Buf.append(element+"\n");
}
logger.error(Buf.toString());
}
}
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import isoft.service.UserService;
public class Test {
private static final String CONFIG = "aop.xml";
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext(CONFIG);
UserService userService = (UserService) ac.getBean("userserviceImpl");
userService.update();
userService.save();
userService.delete();
}
}
Log4j 日志记录的更多相关文章
- ELK环境配置+log4j日志记录
ELK环境配置+log4j日志记录 1. 背景介绍 在大数据时代,日志记录和管理变得尤为重要. 以往的文件记录日志的形式,既查询起来又不方便,又造成日志在服务器上分散存储,管理起来相当麻烦, 想根据一 ...
- Hibernate 使用log4j日志记录
日志记录使程序员能够将日志详细信息永久写入文件.这是我们以后在开发当中非常重要的一步. Hibernate使用log4j日志记录,我们需要以下几个步骤: 1.导入jar包: (1)这是hibernat ...
- java Web应用配置log4j日志记录
公司启动全国支票影像系统,有这样一个功能是和消息中间件打交道,需要记录每一个报文出错情况,因为方便后期开发人员的调试,我选用了log4j作为日志记录,好了废话不多说了! 第一步:首先建立一个WEB工程 ...
- log4j日志记录级别是如何工作?
级别p的级别使用q,在记录日志请求时,如果p>=q启用.这条规则是log4j的核心.它假设级别是有序的.对于标准级别它们关系如下:ALL < DEBUG < INFO < WA ...
- ELK菜鸟手记 (一) 环境配置+log4j日志记录
1. 背景介绍 在大数据时代,日志记录和管理变得尤为重要. 以往的文件记录日志的形式,既查询起来又不方便,又造成日志在服务器上分散存储,管理起来相当麻烦, 想根据一个关键字查询日志中某个关键信息相当困 ...
- 在android中配置 slf4j + log4j 日志记录框架
需求: 在项目开发中,需要记录 操作日志 .起初自己写了个简单的日志记录文本写入到文本的方法,后来随着项目的膨胀,需要考虑更多的操作,开始考虑性能问题. 实现: 考虑使用 slf4j + log4j ...
- Hibernate使用Log4j日志记录(使用properties文件)
我们知道,Log4j和Logback框架可用于支持日志记录hibernate,使用log4j有两种执行日志记录的方法: 通过log4j.xml文件(或) 通过log4j.properties文件 在这 ...
- Hibernate使用Log4j日志记录(使用xml文件)
日志记录使程序员能够将日志详细信息永久写入文件. Log4j和Logback框架可以在hibernate框架中使用来支持日志记录. 使用log4j执行日志记录有两种方法: 通过log4j.xml文件( ...
- Log4j日志记录
1.导入log4j的jar包 2.写log4j.properties文件,配置日志记录参数,一般参数如下所示: 第二行指定了输出日志的目录,此处用的相对路径,也可换成绝对路径: 第三行指定了输出的记录 ...
- SpringBoot-整合log4j日志记录
新建log4j配置文件 文件名称log4j.properties #log4j.rootLogger=CONSOLE,info,error,DEBUG log4j.rootLogger=info,er ...
随机推荐
- 线性代数 | Linear Algebra
网上说<线性代数应该这样学>非常不错,再配合大学教材,把线性代数的基本知识点过一遍. 线性代数 - 知乎 最近在跟一个教程:李宏毅的线性代数 基本知识: Rn :We denote the ...
- jquery父、子、兄弟节点查找
js var test = document.getElementById("test"); var parent = test.parentNode; // 父节点 var ch ...
- PHP如何定义类及其成员属性与操作
1.类的定义: 类的关键字定义使用class 1.定义一个空类 Class Person{}; 2.定义一个有成员属性和操作的类 Class Person{ //成员属性 $name = ' ...
- JUnit 4.0学习笔记
JUnit命令整理 @Test(timeout= ) : 测试时间超过范围即失败 @Test(expected=) : 申明出会发生的异常 @Before : 在每一个测试方法前执行 @After ...
- Integer To Roman leetcode java
问题描述: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range fr ...
- js事件流 事件捕获 及时间冒泡详解
Javascript与HTML之间的交互是通过事件实现. 一.事件流 事件,是文档或浏览器窗口中发生的一些特定的交互瞬间.事件流,描述的是页面中接受事件的顺序.IE9,chrome,Firefox,O ...
- python-django rest framework框架之dispatch方法源码分析
1.Django的 CBV 中在请求到来之后,都要执行dispatch方法,dispatch方法根据请求方式不同触发 get/post/put等方法 class APIView(View): def ...
- python-day1笔记
# 1.编程语言的作用及与操作系统和硬件的关系:#编程语言就是人与电脑之间沟通的介质. # 2.应用程序->操作系统->硬件:#应用程序通过操作系统来控制计算机硬件. #3. cpu-&g ...
- Linux上部署多个tomcat端口设置
在Linux上部署多个tomcat主要是防止端口冲突的问题, tomcat服务器需配置三个端口才能启动,安装时默认启用了这三个端口,当要运行多个tomcat服务时需要修改这三个端口,不能相同.端口一: ...
- spring boot 之如何在两个页面之间传递值(转)
原文地址:spring boot 之如何在两个页面之间传递值 问题:页面之间的跳转,通常带有值的传输,但是,在现在比较流行的SPRING MVC WEB 开发模型中,设计机制导致页面之间的直接接跳转和 ...