use of org.xipki.audit.AuditEventData in project xipki by xipki.
the class SyslogAuditServiceImpl method logEvent0.
@Override
protected void logEvent0(AuditEvent event) {
if (!initialized) {
LOG.error("syslog audit not initialized");
return;
}
CharArrayWriter sb = new CharArrayWriter(150);
if (notEmpty(prefix)) {
sb.append(prefix);
}
AuditStatus status = event.getStatus();
if (status == null) {
status = AuditStatus.UNDEFINED;
}
sb.append("\tstatus: ").append(status.name());
long duration = event.getDuration();
if (duration >= 0) {
sb.append("\tduration: ").append(Long.toString(duration));
}
List<AuditEventData> eventDataArray = event.getEventDatas();
for (AuditEventData m : eventDataArray) {
if (duration >= 0 && "duration".equalsIgnoreCase(m.getName())) {
continue;
}
sb.append("\t").append(m.getName()).append(": ").append(m.getValue());
}
final int n = sb.size();
if (n > maxMessageLength) {
LOG.warn("syslog message exceeds the maximal allowed length: {} > {}, ignore it", n, maxMessageLength);
return;
}
SyslogMessage sm = new SyslogMessage();
sm.setFacility(syslog.getDefaultFacility());
if (notEmpty(localname)) {
sm.setHostname(localname);
}
sm.setAppName(event.getApplicationName());
sm.setSeverity(getSeverity(event.getLevel()));
Date timestamp = event.getTimestamp();
if (timestamp != null) {
sm.setTimestamp(timestamp);
}
sm.setMsgId(event.getName());
sm.setMsg(sb);
try {
syslog.sendMessage(sm);
} catch (IOException ex) {
LOG.error("could not send syslog message: {}", ex.getMessage());
LOG.debug("could not send syslog message", ex);
}
}
Aggregations