private void saveLog(Model model, String type){
//判断模型是否已经指定忽略记录增删改日志
if(!model.getClass().isAnnotationPresent(IgnoreBusinessLog.class)){
User user=UserHolder.getCurrentLoginUser();
String ip=UserHolder.getCurrentUserLoginIp();
OperateLog operateLog=new OperateLog();
if(user != null){
operateLog.setUsername(user.getUsername());
}
operateLog.setLoginIP(ip);
try {
operateLog.setServerIP(InetAddress.getLocalHost().getHostAddress());
} catch (UnknownHostException ex) {
LOG.error("无法获取服务器IP", ex);
}
operateLog.setAppName(SystemListener.getContextPath());
operateLog.setOperatingTime(new Date());
operateLog.setOperatingType(type);
operateLog.setOperatingModel(model.getMetaData());
operateLog.setOperatingID(model.getId());
//将日志加入内存缓冲区
BufferLogCollector.collect(operateLog);
}
}