Search in sources :

Example 1 with SyslogAppender

use of org.apache.log4j.net.SyslogAppender in project cloudstack by apache.

the class AlertsSyslogAppender method append.

@Override
protected void append(LoggingEvent event) {
    if (!isAsSevereAsThreshold(event.getLevel())) {
        return;
    }
    if (_syslogAppenders != null && !_syslogAppenders.isEmpty()) {
        try {
            String logMessage = event.getRenderedMessage();
            if (logMessage.contains("alertType") && logMessage.contains("message")) {
                parseMessage(logMessage);
                String syslogMessage = createSyslogMessage();
                LoggingEvent syslogEvent = new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(), event.getLevel(), syslogMessage, null);
                for (SyslogAppender syslogAppender : _syslogAppenders) {
                    syslogAppender.append(syslogEvent);
                }
            }
        } catch (Exception e) {
            errorHandler.error(e.getMessage());
        }
    }
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) SyslogAppender(org.apache.log4j.net.SyslogAppender) UnknownHostException(java.net.UnknownHostException)

Example 2 with SyslogAppender

use of org.apache.log4j.net.SyslogAppender in project cloudstack by apache.

the class AlertsSyslogAppender method setSyslogAppenders.

void setSyslogAppenders() {
    if (_syslogAppenders == null) {
        _syslogAppenders = new ArrayList<SyslogAppender>();
    }
    if (_syslogHosts == null || _syslogHosts.trim().isEmpty()) {
        reset();
        return;
    }
    _syslogHostsList = parseSyslogHosts(_syslogHosts);
    if (!validateIpAddresses()) {
        reset();
        errorHandler.error(" Invalid format for the IP Addresses parameter ");
        return;
    }
    for (String syslogHost : _syslogHostsList) {
        _syslogAppenders.add(new SyslogAppender(getLayout(), syslogHost, SyslogAppender.getFacility(_facility)));
    }
}
Also used : SyslogAppender(org.apache.log4j.net.SyslogAppender)

Aggregations

SyslogAppender (org.apache.log4j.net.SyslogAppender)2 UnknownHostException (java.net.UnknownHostException)1 LoggingEvent (org.apache.log4j.spi.LoggingEvent)1