Commit 4bbbc3f0 by fsn

日志记录的完善

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