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.
janaw...@geckosoftware.com
435-752-8026

Reply via email to