security veteran | 16 Feb 2011 10:09
Picon

SyslogAppender not working

Hi,

I'm trying to use log4cxx to log messages to a remote syslog server.
To begin with, I tried to log the message to the local syslog server for a simple testing.

I made the following configuration in my log4cxx configuration, but nothing had been logged to /var/log/message.

I tried DAEMON, SYSLOG, LOCAL1, LOCAL7 for the log4j.appender.Syslog.Facility but none of them was working.

Did I miss something?
Any suggestions are greatly appreciated.

Thank you very much.

####################
log4j.rootLogger=INFO, Console, Syslog

log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%5p [%d] [%t](%F:%L)- %m%n


log4j.appender.Syslog=org.apache.log4j.net.SyslogAppender
log4j.appender.Syslog.syslogHost=localhost
log4j.appender.Syslog.Facility=DAEMON
log4j.appender.Syslog.layout=org.apache.log4j.PatternLayout
log4j.appender.Syslog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS} %p [%c] %m%n

Jacob L. Anawalt | 16 Feb 2011 18:40

Re: SyslogAppender not working

On 2/16/2011 2:09 AM, security veteran wrote:
> Hi,
>
> I'm trying to use log4cxx to log messages to a remote syslog server.
> To begin with, I tried to log the message to the local syslog server
> for a simple testing.
>

I use a SyslogAppender, but my configuration is different so I can't 
do a quick apples to apples comparison.

Verify that you can log locally and remotely using the logger command 
(assuming some kind of UNIX like environment) or similar.

http://unixhelp.ed.ac.uk/CGI/man-cgi?logger+1

Try a simple log4cxx program that configures it all programatically. 
The following works for me:

// g++ -o syslogAppender syslogAppender.cpp -llog4cxx
//
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/patternlayout.h>
#include <log4cxx/net/syslogappender.h>

int
main(void)
{
         log4cxx::BasicConfigurator::configure();

         log4cxx::LayoutPtr l(new log4cxx::PatternLayout(
                 "%-4r %-5p %c %x - %m"));
         log4cxx::net::SyslogAppenderPtr a(
                 new log4cxx::net::SyslogAppender(l
                 ,log4cxx::net::SyslogAppender::getFacility("DAEMON")));
         a->setSyslogHost("127.0.0.1");
         a->activateOptions();

         log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("MyApp"));
         logger->addAppender(a);

         while(true) {
                 LOG4CXX_INFO(logger,"beep");
                 sleep(15);
         }

         return EXIT_SUCCESS;
}

--

-- 
Jacob Anawalt
Gecko Software, Inc.
janawalt <at> geckosoftware.com
435-752-8026


Gmane