加入log4j.properties项目运行日志管理,将日志文件保存在硬盘文件夹中
来源:互联网 发布:索康尼跑鞋矩阵 编辑:程序博客网 时间:2024/06/13 04:15
如果想处理日志信息,可以通过SVN来保存版本更新日志,通过log4j来保存运行日志。
1) 版本更新日志:是开发过程中才产生,当每次有新功能加入时,都会编写日志,记录下来更新的内容。
2) 运行日志:主要用来保存用户进行的操作等信息。可以使用数据库保存,也可以通过Log4j保存。
首先先修改log4j.properties属性
再添加公共日志方法
package com.kane.util;
import org.apache.log4j.Logger;
public class LogUtils {
private static Logger logger;
static {
logger = Logger.getLogger(LogUtils.class);
}
/**
* 添加操作信息日志
* @param message
*/
public static void addInfo(String message) {
logger.info(message);
}
/**
* 添加错误日志
* @param message
*/
public static void addError(String message) {
logger.error(message);
}
}
最后在需要的地方调用添加日志信息,或错误信息的方法
public String list() throws Exception {
Map<String,Object> map=productServiceImpl.findAll(pageNo, pageSize, column, keyword);
list=(List<Product>)map.get("allProduct");
count=(Integer)map.get("allCount");//这是装箱,取的时候拆箱成int
LogUtils.addInfo("查看了产品列表");
return "list";
}
最后在D:\ssh.log显示结果
[20140312 12:19:17-INFO][ContextLoader.java:186][main]-- Root WebApplicationContext: initialization started
[20140312 12:19:17-INFO][AbstractApplicationContext.java:454][main]-- Refreshing Root WebApplicationContext: startup date [Wed Mar 12 12:19:17 CST 2014]; root of context hierarchy
[20140312 12:19:17-INFO][XmlBeanDefinitionReader.java:315][main]-- Loading XML bean definitions from ServletContext resource [/WEB-INF/classes/applicationContext.xml]
[20140312 12:19:18-INFO][DefaultListableBeanFactory.java:537][main]-- Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@15e2ccd: defining beans [dataSource,jdbcTemplate,productImpl,productServiceImpl,transactionManager,transactionInterceptor,org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator#0,productAction]; root of factory hierarchy
[20140312 12:19:18-INFO][ContextLoader.java:213][main]-- Root WebApplicationContext: initialization completed in 518 ms
[20140312 12:19:18-INFO][CommonsLogger.java:31][main]-- Parsing configuration file [struts-default.xml]
[20140312 12:19:18-INFO][CommonsLogger.java:31][main]-- Parsing configuration file [struts-plugin.xml]
[20140312 12:19:18-INFO][CommonsLogger.java:31][main]-- Parsing configuration file [struts.xml]
[20140312 12:19:18-INFO][CommonsLogger.java:31][main]-- Initializing Struts-Spring integration...
[20140312 12:19:18-INFO][CommonsLogger.java:31][main]-- Setting autowire strategy to name
[20140312 12:19:18-INFO][CommonsLogger.java:31][main]-- ... initialized Struts-Spring integration successfully
[20140312 12:19:23-INFO][LogUtils.java:17][http-8080-1]-- 查看了产品列表
Log4j资源:http://download.csdn.net/detail/u010026901/7027905
- 加入log4j.properties项目运行日志管理,将日志文件保存在硬盘文件夹中
- NLog日志——将日志保存在文件中
- 使用Log4j在程序中加入日志
- 使用Log4j在程序中加入日志
- 在工程中加入log4j日志
- 在WEB项目中使用log4j日志管理
- 在WEB项目中使用log4j日志管理
- 日志文件详解log4j.properties
- 设置Log4j 的properties文件,将日志写入数据库
- log4j配置多个日志文件,将日志分类的配置样例log4j.properties
- Java日志 - 如何在项目中指定log4j.properties路径
- Maven项目中添加log4j.properties实现日志功能工具
- log4j日志文件保存位置
- 将日志保存到文件中
- log4j日志在web项目中使用
- web开发中log4j.properties日志文件的使用
- NLog日志——将日志保存在数据库中
- Web开发加入Log4j日志管理
- Android之unable to execute dex java heap space解决方案
- Javawebservice例子
- 深入浅出JSONP--解决ajax跨域问题
- 领衔无线测量行业 MVG将参与IWS2014国际无线会议及展览
- 蓝桥杯-代码填空之一
- 加入log4j.properties项目运行日志管理,将日志文件保存在硬盘文件夹中
- Matlab函数
- Java面向对象——JDK 1.5新特性
- [资源] 【VOL】Office 2013 with SP1 官方ISO
- 第一章实验作业
- c代码应用之 解析配置文件:libconfig
- android UI droiddraw的打开
- UITextField垂直居中对齐
- Linux 入门笔记(根据传智韩顺平整理的(一))