Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j and syslogappender

Tags:

java

log4j

syslog

I have a java application using log4j SyslogAppender (facility=USER) and I can see using tcpdump on port 514 that my application is sending intended log message as a datagram and also netstat shows me that syslogd (red hat) is running and listening on 0.0.0.0:514 but I do not see any logging happening in /var/log/messages.

In my syslog.conf, I have

*.info         /var/log/messages

My conversion pattern for SyslogAppender is

%d{MMM dd HH:mm:ss} %F %L %5p [%t] %m %n"

I am clueless as why it is failing to log or where exactly should I look for to see what is failing. And I don't have enough permissions on the machine to start/stop syslogd or run manually to have verbose debug logs enabled.

Any pointers as how I proceed?

Edit:

The Appender below

private void initSyslog() { 
    SyslogAppender syslogAppender = new SyslogAppender();   
    syslogAppender.setName("syslog");
    syslogAppender.setLayout(new PatternLayout("%d{MMM dd HH:mm:ss} %F %L %5p [%t] %m %n")); 
    syslogAppender.setFacility("USER"); 
    syslogAppender.setFacilityPrinting(true);
    syslogAppender.setSyslogHost("localhost");
    syslogAppender.activateOptions(); 
    Logger.getRootLogger().addAppender(syslogAppender);
    Logger.getRootLogger.info("Syslogdone");
} 
like image 812
Prasanna Avatar asked Dec 01 '11 23:12

Prasanna


People also ask

What is Syslogappender?

The syslog appender writes to a syslogd deamon. The syslogd deamon is the standard logging utility on most UNIX systems.

What is the difference between Log4j and Log4j2?

Community support: Log4j 1. x is not actively maintained, whereas Log4j 2 has an active community where questions are answered, features are added and bugs are fixed. Automatically reload its configuration upon modification without losing log events while reconfiguring.

Is Log4j and Apache Log4j different?

Log4j is part of the Apache Logging Services Project -- an open source effort within the Apache Software Foundation. The Apache Logging Services Project includes multiple variations of the Log4j logging framework for different programming deployments and use cases.

Which is better Log4j or Log4j2?

Log4j, Logback, and Log4j2 are good logging frameworks that are broadly used. So which one should you use? I recommend using Log4j2 because it's the fastest and most advanced of the three frameworks. Logback is still a good option, if performance is not your highest priority.


1 Answers

Remote logging was not enabled in syslog. Weird, because it still opens and listens on 514. Once I started with syslog -r, everything started logging.

like image 181
Prasanna Avatar answered Sep 22 '22 03:09

Prasanna