加入log4j.properties项目运行日志管理,将日志文件保存在硬盘文件夹中

如果想处理日志信息,可以通过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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值