Log4j syslog appender

Ubuntu 10.04 Lucid rsyslogd

1) Uncomment
# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

2) sudo service rsyslog restart



public class TestSyslog {

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

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

    // when

    // 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);


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s