use of j.db.JactionLog in project JFramework by gugumall.
the class JUtilBean method main.
public static void main(String[] args) {
JactionLog log1 = new JactionLog();
log1.setActionHandler("111");
log1.setEventTime(new Timestamp(SysUtil.getNow()));
JactionLog log2 = new JactionLog();
log2.setActionHandler("222");
log2.setEventTime(new Timestamp(SysUtil.getNow()));
List beans = new LinkedList();
beans.add(log1);
beans.add(log2);
String xml = JUtilBean.beans2Xml(beans, null);
System.out.println(xml);
List beans2 = JUtilBean.xml2Beans(xml, null);
for (int i = 0; i < beans2.size(); i++) {
JactionLog o = (JactionLog) beans2.get(i);
System.out.println(o.getActionHandler());
System.out.println(o.getEventTime());
}
}
use of j.db.JactionLog in project JFramework by gugumall.
the class ActionLogger method run.
/*
* (non-Javadoc)
*
* @see java.lang.Runnable#run()
*/
public void run() {
while (true && !shutdown) {
try {
Thread.sleep(100);
} catch (Exception e) {
}
if (this.events.isEmpty())
continue;
try {
long now = SysUtil.getNow();
List keys = this.events.listKeys();
for (int i = 0; i < keys.size(); i++) {
String uuid = (String) keys.get(i);
JactionLog log = (JactionLog) this.events.get(uuid);
if (log == null) {
this.events.remove(uuid);
continue;
}
if (log.getActionResult() != null || now - log.getEventTime().getTime() > Handlers.getActionTimeout()) {
if (log.getActionResult() == null) {
log.setActionResult("ACTION_EXECUTION_TIMEOUT");
log.setEventStat("ERROR");
}
this.events.remove(uuid);
if (log.getActionResult() != null && log.getActionResult().length() > 1024) {
// throw new Exception("action result too long to save in action log:"+log.getActionHandler()+","+log.getActionId());
log.setActionResult(log.getActionResult().substring(0, 1024));
}
QueryPool.getPool(j.Properties.getLogDatabase()).insert(null, log);
log = null;
}
}
keys.clear();
keys = null;
} catch (Exception e) {
logger.log(e, Logger.LEVEL_ERROR);
try {
Thread.sleep(5000);
} catch (Exception ex) {
}
}
}
}
use of j.db.JactionLog in project JFramework by gugumall.
the class ActionLogger method after.
/**
* @param action
* @param uuid
*/
public void after(Action action, HttpSession session, String uuid) {
// 对象为空或日志关闭
if (action == null || action.isLogEnabled() == 0)
return;
// 日志未设置且默认未开启
if (action.isLogEnabled() == -1 && !Handlers.isLoggerOn())
return;
JactionLog log = (JactionLog) events.get(uuid);
if (log == null)
return;
if (log.getAuId() == null) {
User user = (User) session.getAttribute(Constants.SSO_USER);
String userId = (user == null ? null : user.getUserId());
if (userId == null) {
LoginStatus status = (LoginStatus) session.getAttribute(Constants.SSO_STAT_CLIENT);
userId = (status == null ? null : status.getUserId());
}
log.setAuId(userId);
}
log.setEventStat("TRACE");
log.setActionResult("");
}
use of j.db.JactionLog in project JFramework by gugumall.
the class ActionLogger method after.
/**
* @param action
* @param uuid
* @param e
*/
public void after(Action action, HttpSession session, String uuid, Exception e) {
// 对象为空或日志关闭
if (action == null || action.isLogEnabled() == 0)
return;
// 日志未设置且默认未开启
if (action.isLogEnabled() == -1 && !Handlers.isLoggerOn())
return;
JactionLog log = (JactionLog) events.get(uuid);
if (log == null)
return;
if (e == null) {
log.setActionResult("");
return;
}
String ex = SysUtil.getException(e);
if (log.getAuId() == null) {
User user = (User) session.getAttribute(Constants.SSO_USER);
String userId = (user == null ? null : user.getUserId());
if (userId == null) {
LoginStatus status = (LoginStatus) session.getAttribute(Constants.SSO_STAT_CLIENT);
userId = (status == null ? null : status.getUserId());
}
log.setAuId(userId);
}
log.setEventStat("ERROR");
log.setActionResult(ex == null ? "" : ex);
}
use of j.db.JactionLog in project JFramework by gugumall.
the class ActionLogger method before.
/**
* @param action
* @param uuid
* @param session
* @param request
*/
public void before(Action action, String uuid, HttpSession session, HttpServletRequest request) {
// 对象为空或日志关闭
if (action == null || action.isLogEnabled() == 0)
return;
// 日志未设置且默认未开启
if (action.isLogEnabled() == -1 && !Handlers.isLoggerOn())
return;
User user = (User) session.getAttribute(Constants.SSO_USER);
String userId = (user == null ? null : user.getUserId());
if (userId == null) {
LoginStatus status = (LoginStatus) session.getAttribute(Constants.SSO_STAT_CLIENT);
userId = (status == null ? null : status.getUserId());
}
if (userId == null) {
userId = SysUtil.getHttpParameter(request, Constants.SSO_USER_ID);
}
JactionLog log = new JactionLog();
log.setEventId(uuid);
log.setAsvrId(SysConfig.getMachineID());
log.setAsysId(SysConfig.getSysId());
log.setAdomain(JUtilString.getHost(request.getRequestURL().toString()));
log.setAurl(request.getRequestURI());
log.setAuIp(JHttp.getRemoteIp(request));
log.setAuId(userId);
log.setActionHandler(log.getAurl());
log.setActionId(action.getId());
Document doc = DocumentHelper.createDocument();
doc.setXMLEncoding(SysConfig.sysEncoding);
Element root = doc.addElement("root");
if (action.isLogAllParameters()) {
Enumeration parameters = request.getParameterNames();
while (parameters.hasMoreElements()) {
String parameter = (String) parameters.nextElement();
String value = SysUtil.getHttpParameter(request, parameter);
if (value == null)
value = "_null";
Element pEle = root.addElement("p");
pEle.addAttribute("name", parameter);
pEle.setText(value);
}
} else {
List temp = action.getLogParams();
for (int i = 0; i < temp.size(); i++) {
String p = (String) temp.get(i);
String value = SysUtil.getHttpParameter(request, p);
if (value == null)
value = "_null";
Element pEle = root.addElement("p");
pEle.addAttribute("name", p);
pEle.setText(value);
}
}
try {
String ps = JUtilDom4j.toString(doc);
doc = null;
log.setActionParameters(ps);
} catch (Exception e) {
logger.log(e, Logger.LEVEL_ERROR);
}
log.setActionResult(null);
log.setEventTime(new Timestamp(SysUtil.getNow()));
log.setDelBySys("N");
events.put(uuid, log);
}
Aggregations