try { |
|
LogManager logMgr = SecurityDatabase.getLogManager(); |
//以下是以一个quartz任务执行日志记录为实例说明日志组件的使用方法 |
AccessControl control = AccessControl.getAccessControl(); |
String userAccount = ""; //操作账号 |
String operContent = ""; //操作内容 |
String machineID = ""; //操作主机标识 |
String orgID = ""; //操作员所属部门id |
if (control == AccessControl.getGuest()) //匿名用户-guest,登录用户直接忽略这个条件进入下一个环节 |
{ |
|
machineID = SimpleStringUtil.getHostIP(); |
userAccount = "Quartz定时任务"; |
operContent = userAccount + "同步用户数据开始"; |
} |
else //登录用户 |
{ |
userAccount = control.getUserAccount(); |
String userName = control.getUserName(); //操作员中文名称 |
String subsystem = control.getCurrentSystemName(); //操作系统名称 |
machineID = control.getMachinedID(); //客户端ip信息 |
Organization org = control.getChargeOrg(); //获取当前用户所属机构 |
if (org != null ) |
{ |
orgID = org.getOrgId(); |
} |
operContent = userAccount + "(" + userName + ") 从[" + subsystem + "]同步用户数据开始"; |
} |
String operModle = "主数据同步"; //日志所属模块 |
logMgr.log(userAccount,orgID,operModle, machineID, |
operContent ,"", Log.INSERT_OPER_TYPE); |
|
} catch (Exception e) { |
e.printStackTrace(); |
} |