diff --git a/len-sys/src/main/java/com/len/core/annotation/LogAspect.java b/len-sys/src/main/java/com/len/core/annotation/LogAspect.java index 7f40c34..30c5ae2 100644 --- a/len-sys/src/main/java/com/len/core/annotation/LogAspect.java +++ b/len-sys/src/main/java/com/len/core/annotation/LogAspect.java @@ -9,6 +9,10 @@ import com.len.util.IpUtil; import java.lang.reflect.Method; import java.util.Date; import javax.servlet.http.HttpServletRequest; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.UnavailableSecurityManagerException; +import org.apache.shiro.mgt.SecurityManager; +import org.apache.shiro.subject.Subject; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.AfterThrowing; @@ -17,6 +21,7 @@ import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -45,12 +50,15 @@ public class LogAspect { } private void addLog(JoinPoint jp,String text){ - HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - CurrentUser currentUser= ShiroUtil.getCurrentUse(); - String ip= IpUtil.getIp(request); Log.LOG_TYPE type=getType(jp); SysLog log=new SysLog(); - log.setIp(ip); + RequestAttributes requestAttributes=RequestContextHolder.getRequestAttributes(); + //一些系统监控 + if(requestAttributes!=null){ + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + String ip= IpUtil.getIp(request); + log.setIp(ip); + } log.setCreateTime(new Date()); log.setType(type.toString()); log.setText(text); @@ -65,10 +73,13 @@ public class LogAspect { } } log.setParam(buffer.toString()); - if(currentUser!=null){ + try { + CurrentUser currentUser = ShiroUtil.getCurrentUse(); log.setUserName(currentUser.getUsername()); - logMapper.insert(log); + }catch (UnavailableSecurityManagerException e){ + } + logMapper.insert(log); } /** @@ -79,7 +90,7 @@ public class LogAspect { @AfterThrowing(value="pointcut()",throwing="e") public void afterException(JoinPoint joinPoint,Exception e){ System.out.print("-----------afterException:"+e.getMessage()); - // addLog(joinPoint,getDesc(joinPoint)+e.getMessage()); + addLog(joinPoint,getDesc(joinPoint)+e.getMessage()); } diff --git a/len-sys/src/main/java/com/len/core/quartz/CustomQuartz/JobDemo2.java b/len-sys/src/main/java/com/len/core/quartz/CustomQuartz/JobDemo2.java index 5d45513..ad2c31a 100644 --- a/len-sys/src/main/java/com/len/core/quartz/CustomQuartz/JobDemo2.java +++ b/len-sys/src/main/java/com/len/core/quartz/CustomQuartz/JobDemo2.java @@ -1,5 +1,6 @@ package com.len.core.quartz.CustomQuartz; +import com.len.core.annotation.Log; import com.len.entity.SysUser; import com.len.service.SysUserService; import com.len.service.impl.SysUserServiceImpl; diff --git a/len-sys/src/main/java/com/len/core/quartz/JobTask.java b/len-sys/src/main/java/com/len/core/quartz/JobTask.java index 4a041e1..804ebdc 100644 --- a/len-sys/src/main/java/com/len/core/quartz/JobTask.java +++ b/len-sys/src/main/java/com/len/core/quartz/JobTask.java @@ -60,7 +60,7 @@ public class JobTask { /** * 开启 */ - //@Log(desc = "开启定时任务") + @Log(desc = "开启定时任务") public boolean startJob(SysJob job) { Scheduler scheduler = schedulerFactoryBean.getScheduler(); try {