日志无法记录

日志无法记录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package ms.global;
 
import ms.entity.Log;
import ms.entity.Staff;
import ms.service.LogService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
 
/**
 * Created by Raymond on 2018/11/25.
 */
@Component
@Aspect
public class LogAdvice {
    @Autowired
    private LogService logService;
 
    @After("execution(* ms.controller.*.*(..)) &&!execution(* ms.controller.SelfController.*(..)) &&!execution(* ms.controller.*.to*(..))")
    public void operationLog(JoinPoint joinPoint){
        Log log = new Log();
        log.setModule(joinPoint.getTarget().getClass().getSimpleName());
        log.setOperation(joinPoint.getSignature().getName());
        HttpServletRequest request =(HttpServletRequest) joinPoint.getArgs()[0];
        HttpSession session = request.getSession();
        Object object = session.getAttribute("USER");
        Staff staff = (Staff)object;
        System.out.println(staff);
        log.setOperator(staff.getAccount());
        log.setResult("成功");
        logService.addOperationLog(log);
    }
 
 
    @AfterThrowing(throwing = "e",pointcut = "execution(* ms.controller.*.*(..)) && !execution(* ms.controller.SelfController.*(..))")
    public void systemLog(JoinPoint joinPoint,Throwable e){
        Log log = new Log();
        log.setModule(joinPoint.getTarget().getClass().getSimpleName());
        log.setOperation(joinPoint.getSignature().getName());
        HttpServletRequest request =(HttpServletRequest) joinPoint.getArgs()[0];
        HttpSession session = request.getSession();
        Object object = session.getAttribute("USER");
        Staff staff = (Staff)object;
        log.setOperator(staff.getAccount());
        log.setResult(e.getClass().getSimpleName());
        logService.addSystemLog(log);
    }
 
    @After("execution(* ms.controller.SelfController.login(..))")
    public void loginLog(JoinPoint joinPoint) {
        log(joinPoint);
    }
 
    @Before("execution(* ms.controller.SelfController.logout(..))")
    public void loginOutLog(JoinPoint joinPoint){
        log(joinPoint);
    }
 
 
    private void log(JoinPoint joinPoint){
        Log log = new Log();
        log.setModule(joinPoint.getTarget().getClass().getSimpleName());
        log.setOperation(joinPoint.getSignature().getName());
        HttpServletRequest request = (HttpServletRequest) joinPoint.getArgs()[0];
        HttpSession session = request.getSession();
        Object object = session.getAttribute("USER");
        if (object == null) {
            log.setOperator(request.getParameter("account"));
            System.out.println("failure");
            log.setResult("失败");
        else {
            Staff staff = (Staff) object;
            System.out.println(staff);
            log.setOperator(staff.getAccount());
            log.setResult("成功");
        }
        logService.addLoginLog(log);
    }
}

http://img1.sycdn.imooc.com//climg/5bfaa6260001288312170406.jpg

http://img1.sycdn.imooc.com//climg/5bfaa626000156fe08290489.jpg

http://img1.sycdn.imooc.com//climg/5bfaa626000197de12420605.jpg

http://img1.sycdn.imooc.com//climg/5bfaa6280001fdf110750416.jpg

http://img1.sycdn.imooc.com//climg/5bfaa6280001e4cd10790509.jpg

http://img1.sycdn.imooc.com//climg/5bfaa6280001e62e10870482.jpg

http://img1.sycdn.imooc.com//climg/5bfaa629000124f110710401.jpg


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
一叶知秋519 2018-11-26 12:08:31

http://img1.sycdn.imooc.com//climg/5bfb7185000197a910640235.jpg

同学你好,红框内的内容就是日志,同学说的不记录是指的哪一部分没有记录呢? 

另外没有记录的这部分内容是不是没有调用。

祝学习愉快 !

  • 提问者 RaymondSH #1
    是自己写的那些登录、操作、系统日志不能记录
    2018-11-26 13:27:34
  • chrismorgen 回复 提问者 RaymondSH #2
    你好同学,哪部分是你自己的登陆操作呢?你的代码和老师的是一样的,同学可否具体说明一下问题呢?比如哪段代码,对应的哪部分效果是没有显示的呢?可以具体描述一下问题,方便老师具有针对性的为你解答,祝学习愉快~
    2018-11-26 17:30:05
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
SSM主流框架入门与综合项目实战2018版
  • 参与学习           人
  • 提交作业       205    份
  • 解答问题       4317    个

Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码