Redirect Log Messages to syslog

Martin Janzen janzen____pixelmetrix.com
Mon Jul 21 05:00:51 CEST 2003


Jochen Katz wrote:
> Hi,
> 
>> Is it possible to redirect all log messages from stdout to system log 
>> (syslog() function)?
>> How can i do it?
> 
> 
> you will have to patch snmp++/src/v3.cpp (functions debugprintf and 
> debughexcprintf) and agent++/src/log.cpp (class AgentLogImpl).
> 
> You could also use AgentLogImpl::set_dest() and debug_set_logfile() to 
> redirect the logs to a file.

Also, if you don't want to patch the standard Agent++ files, you can 
create your own logger class as a derived class of AgentLog (just like 
AgentLogImpl), overriding operator+= so that it writes the LogEntry to 
syslog.  When your agent starts up, just have it replace the usual 
AgentLogImpl instance pointed to by DefaultLog with an instance of your 
new class:

     delete Agentpp::DefaultLog::log;
     Agentpp::DefaultLog::log = new MySyslogLogger;

The joys of polymorphism...  :-)

-- 
Martin Janzen
janzen at pixelmetrix dot com




More information about the AGENTPP mailing list