关于springMVC的日志管理

主要是基于在spring aop特性.

1. 创建一个系统日志的操作类,类里面提供一个方法,可以向数据库或者表中写入:访问用户名,访问IP,操作时间,访问包名,具体函数名.

 1 /**
 2  * @Name SystemLogUtils
 3  * @Descr 系统日志工具
 4  * @author lne
 5  */
 6 public class SystemLogUtils {
 7     private ISystemLogService logService;
 8 
 9     public void setLogService(ISystemLogService logService) {
10         this.logService = logService;
11     }
12 
13     public void writeLog(JoinPoint joinPoint) throws Exception {
14         Object serviceObj = joinPoint.getTarget();
15 
16         if ((serviceObj instanceof ISystemLogService)) {
17             return;
18         }
19         @SuppressWarnings("rawtypes")
20         Class serviceClz = joinPoint.getTarget().getClass();
21 
22         String methodName = joinPoint.getSignature().getName();
23 
24         // 创建日志对象
25         SystemLog log = new SystemLog();
26         // 封装日志属性
27         log.setOpUser(UserContextUtil.getUser());
28         log.setOpTime(new Date());
29         log.setOpIp(UserContextUtil.getRequest().getRemoteAddr());
30 
31         String function = serviceClz.getName();
32         log.setMethod(function);
33         log.setParams(methodName);
34 
35         // 保存日志
36         logService.save(log);
37     }
38 }

 

2. 在sping配置文件中加入系统日志的配置

 1     <!-- 系统日志工具类 -->
 2     <bean id="logUtils" class="cn.crmx.crm.util.SystemLogUtils">
 3         <property name="logService" ref="systemLogServiceImpl"></property>
 4     </bean>
 5 
 6     <!-- 切入点配置 -->
 7     <aop:config>
 8         <aop:pointcut expression="execution(* cn.crmx.crm.service..*.*(..))" id="logPointcut" />
 9         <aop:aspect ref="logUtils">
10             <aop:after method="writeLog" pointcut-ref="logPointcut" />
11         </aop:aspect>
12     </aop:config>

 

3.然后提供相关系统日志的其它层文件.

  这种方法的好处在与,可以相信配置操作系统日志的权限.

 

第二种是纯基于框架配置,引入jar支持包,然后在固定位置,输出文件.

 

就到这.

 

转载于:https://www.cnblogs.com/applerosa/p/5981099.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值