Package: liblog4cpp5
Version: 1.1.1-3~bpo8+1

I used the examples that I found online to instantiate
RemoteSyslogHandler and BasicLayout

I observed that the UDP messages sent to the Syslog host don't include
the Syslog header information in either the RFC-3164 or RFC-5424 formats.

I was able to workaround this by manually adding the header information
in a PatternLayout (see below)

As this header information is mandatory for the Syslog protocol, it
should probably be implemented in RemoteSyslogHandler.cpp


log4cpp::Appender *appender1 =
  new log4cpp::RemoteSyslogAppender("default", argv[0], "log-host");

// Configure pattern for log messages
bool useRfc5424 = true;
std::stringstream logpattern;
const char* progname = rindex(argv[0], '/');
if(progname == 0) {
   progname = argv[0];
} else {
   progname++;
}
if(useRfc5424) {

   // create a Syslog RFC-5424 compliant layout for log strings
   char _hostname[512];
   if(gethostname(_hostname, 510) < 0) {
      strcpy(_hostname, "unknown-hostname");
   }
   logpattern << "%d{%Y-%m-%dT%H:%M:%SZ} "
      << _hostname << " " << progname << " " << getpid()
      << " - - %m";
} else {
   // create a Syslog RFC-3164 compliant layout for log strings
   logpattern << progname << '[' << getpid() << "]: %m";
}
log4cpp::PatternLayout *pl = new log4cpp::PatternLayout();
pl->setConversionPattern(logpattern.str());
appender1->setLayout(pl);

Reply via email to