Commit 4bbbc3f0 by fsn

日志记录的完善

parent b65eb887
......@@ -9,6 +9,7 @@ package com.stylefeng.guns.common.constant.state;
public enum LogType {
LOGIN("登录日志"),
LOGIN_FAIL("登录失败日志"),
EXIT("退出日志"),
EXCEPTION("异常日志"),
BUSSINESS("业务日志");
......
......@@ -2,7 +2,6 @@ package com.stylefeng.guns.common.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* 全局的控制器
......@@ -19,7 +18,7 @@ public class GlobalController {
*
* @author fengshuonan
*/
@RequestMapping(path = "/error", method = RequestMethod.GET)
@RequestMapping(path = "/error")
public String errorPage() {
return "/404.html";
}
......
......@@ -41,13 +41,14 @@ public class LogFactory {
* @author fengshuonan
* @Date 2017/3/30 18:46
*/
public static LoginLog createLoginLog(LogType logType, Integer userId) {
public static LoginLog createLoginLog(LogType logType, Integer userId, String msg) {
LoginLog loginLog = new LoginLog();
loginLog.setLogname(logType.getMessage());
loginLog.setUserid(userId);
loginLog.setCreatetime(new Date());
loginLog.setSucceed(LogSucceed.SUCCESS.getMessage());
loginLog.setIp(HttpKit.getRequest().getRemoteHost());
loginLog.setMessage(msg);
return loginLog;
}
}
......@@ -22,7 +22,7 @@ public class LogManager {
private static OperationLogMapper operationLogMapper = Db.getMapper(OperationLogMapper.class);
public static void loginLog(Integer userId) {
LoginLog loginLog = LogFactory.createLoginLog(LogType.LOGIN, userId);
LoginLog loginLog = LogFactory.createLoginLog(LogType.LOGIN, userId, null);
try {
loginLogMapper.insert(loginLog);
} catch (Exception e) {
......@@ -30,8 +30,17 @@ public class LogManager {
}
}
public static void loginLog(String username, String msg) {
LoginLog loginLog = LogFactory.createLoginLog(LogType.LOGIN_FAIL, null, "账号:" + username + "," + msg);
try {
loginLogMapper.insert(loginLog);
} catch (Exception e) {
logger.error("创建登录失败异常!", e);
}
}
public static void exitLog(Integer userId) {
LoginLog loginLog = LogFactory.createLoginLog(LogType.EXIT, userId);
LoginLog loginLog = LogFactory.createLoginLog(LogType.EXIT, userId, null);
try {
loginLogMapper.insert(loginLog);
} catch (Exception e) {
......@@ -50,7 +59,7 @@ public class LogManager {
public static void exceptionLog(Integer userId, Exception exception) {
String msg = ToolUtil.getExceptionMsg(exception);
OperationLog operationLog = LogFactory.createOperationLog(LogType.EXCEPTION, userId, "", "", msg);
OperationLog operationLog = LogFactory.createOperationLog(LogType.EXCEPTION, userId, null, null, msg);
try {
operationLogMapper.insert(operationLog);
} catch (Exception e) {
......
......@@ -49,8 +49,6 @@ public class MenuController extends BaseController {
@RequestMapping("")
public String index() {
int i = 1/0;
return PREFIX + "menu.html";
}
......
......@@ -64,7 +64,7 @@ public class ShiroConfig {
@Bean
public CookieRememberMeManager rememberMeManager(SimpleCookie rememberMeCookie) {
CookieRememberMeManager manager = new CookieRememberMeManager();
manager.setCipherKey(Base64.decode("ZGluZ2RpbmdtYW5hZ2VyAA=="));
manager.setCipherKey(Base64.decode("Z3VucwAAAAAAAAAAAAAAAA=="));
manager.setCookie(rememberMeCookie);
return manager;
}
......
//package project.config.web;
//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.EnableAspectJAutoProxy;
//
//import com.stylefeng.guns.core.intercept.SessionInterceptor;
//
///**
// * 保留类,如果控制器需要些aop在这里写
// *
// * @author fengshuonan
// * @date 2016年11月12日 下午4:48:10
// */
//@Configuration
//@EnableAspectJAutoProxy
//public class ControllerAopConfig {
//
// /**
// * session的拦截器,用在非controller层调用session
// */
// @Bean
// public SessionInterceptor sessionInterceptor() {
// return new SessionInterceptor();
// }
//
//}
package project.config.web;
import com.stylefeng.guns.core.intercept.SessionInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
/**
* 保留类,如果控制器需要些aop在这里写
*
* @author fengshuonan
* @date 2016年11月12日 下午4:48:10
*/
@Configuration
@EnableAspectJAutoProxy
public class ControllerAopConfig {
/**
* session的拦截器,用在非controller层调用session
*/
@Bean
public SessionInterceptor sessionInterceptor() {
return new SessionInterceptor();
}
}
......@@ -37,7 +37,7 @@ import java.util.List;
@EnableWebMvc
@ComponentScan(basePackages = {"com.stylefeng.guns.**.controller", "com.stylefeng.guns.common.controller"})
@EnableAspectJAutoProxy
//@Import(value = {ControllerAopConfig.class})
@Import({ControllerAopConfig.class})
public class SpringMvcConfig extends WebMvcConfigurerAdapter {
// beetl的配置
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment