org.apache.log4j.net.SyslogAppender Java Examples
The following examples show how to use
org.apache.log4j.net.SyslogAppender.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AlertsSyslogAppender.java From cloudstack with Apache License 2.0 | 6 votes |
@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()); } } }
Example #2
Source File: AlertsSyslogAppender.java From cloudstack with Apache License 2.0 | 6 votes |
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))); } }
Example #3
Source File: AlertsSyslogAppender.java From cloudstack with Apache License 2.0 | 6 votes |
public void setFacility(String facility) { if (facility == null) { return; } _facility = facility; if (_syslogAppenders != null && !_syslogAppenders.isEmpty()) { for (SyslogAppender syslogAppender : _syslogAppenders) { syslogAppender.setFacility(facility); } } }
Example #4
Source File: TestSyslogUdpSource.java From mt-flume with Apache License 2.0 | 5 votes |
@Test public void testAppend() throws InterruptedException { Logger logger = Logger.getLogger(getClass()); // use the Apache syslog appender to write to syslog source SyslogAppender appender = new SyslogAppender(null, "localhost:"+TEST_SYSLOG_PORT, SyslogAppender.LOG_FTP); logger.addAppender(appender); Event e = null; Event e2 = null; source.start(); // write to syslog logger.info("test flume syslog"); logger.info(""); Transaction txn = channel.getTransaction(); try { txn.begin(); e = channel.take(); e2 = channel.take(); txn.commit(); } finally { txn.close(); } source.stop(); logger.removeAppender(appender); Assert.assertNotNull(e); Assert.assertEquals(String.valueOf(SyslogAppender.LOG_FTP / 8), e.getHeaders().get(SyslogUtils.SYSLOG_FACILITY)); Assert.assertArrayEquals(e.getBody(), "test flume syslog".getBytes()); Assert.assertNotNull(e2); Assert.assertEquals(String.valueOf(SyslogAppender.LOG_FTP / 8), e2.getHeaders().get(SyslogUtils.SYSLOG_FACILITY)); Assert.assertArrayEquals(e2.getBody(), "".getBytes()); }
Example #5
Source File: AlertsSyslogAppender.java From cloudstack with Apache License 2.0 | 4 votes |
@Override synchronized public void close() { for (SyslogAppender syslogAppender : _syslogAppenders) { syslogAppender.close(); } }