Log4j syslog appender

Ubuntu 10.04 Lucid rsyslogd

1) Uncomment
/etc/rsyslog.conf:
# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

2) sudo service rsyslog restart

3)

    
        
        
        
        
            
        
    

4)
public class TestSyslog {

  static Logger logger = Logger.getLogger("monitoring");

  @Test
  public void shouldLogToSyslog() throws Exception {
    // given
    String msg = "My message!!!";


    // when
    logger.error(message);


    // then
    if (isLinux()) {
      assertTrue(logContains("/var/log/syslog", msg));
      assertTrue(logContains("/var/log/user.log", msg));
    }
  }


  private boolean isLinux() {
    String os = System.getProperty("os.name");
    return "Linux".equals(os);
  }


  boolean logContains(String userLogFile, String msg) throws IOException {
    String fileAsString = FileUtils.readFileToString(new File(userLogFile));
    return fileAsString.contains(msg);
  }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s