use of com.cloudbees.syslog.SyslogMessage in project xipki by xipki.
the class SyslogAuditServiceImpl method logEvent0.
// method logEvent(AuditEvent)
@Override
protected void logEvent0(PciAuditEvent event) {
if (!initialized) {
LOG.error("syslog audit not initialiazed");
return;
}
CharArrayWriter msg = event.toCharArrayWriter(prefix);
final int n = msg.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.setSeverity(getSeverity(event.getLevel()));
sm.setMsg(msg);
try {
syslog.sendMessage(sm);
} catch (IOException ex) {
LOG.error("could not send syslog message: {}", ex.getMessage());
LOG.debug("could not send syslog message", ex);
}
}
use of com.cloudbees.syslog.SyslogMessage in project 2018 by DF-1317.
the class Logger method log.
// peg
public void log(String msg) {
init();
if (!peg())
return;
try {
SyslogMessage m = new SyslogMessage().withFacility(Fac).withSeverity(Sev).withHostname(ServerHost).withAppName(app).withProcId(proc).withMsg(msg);
syslog.sendMessage(m);
} catch (Exception e) {
System.err.println("Ouch: " + e.getMessage());
e.printStackTrace();
}
}
use of com.cloudbees.syslog.SyslogMessage in project 2018 by DF-1317.
the class Logger method log.
/*
* Simply send the message and flush it out. The flush is nice to help keep the messages as real-time as
* possible; yeah, it is less efficient.
* We always log 'info' messages, there are other choices like: debug, error, warn, crit...
*/
public void log(String msg) {
System.out.println("Sending: " + msg);
try {
SyslogMessage m = new SyslogMessage().withFacility(Fac).withSeverity(Sev).withHostname(ServerHost).withAppName("test-client").withProcId("Logger").withMsg(msg);
sl.sendMessage(m);
} catch (Exception e) {
System.err.println("Ouch: " + e.getMessage());
e.printStackTrace();
}
}
use of com.cloudbees.syslog.SyslogMessage 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