1 #include "logging/Log4cxxAppender.hpp" 2 #include "log4cxx/spi/loggingevent.h" 3 #include "rtt/Component.hpp" 4 #include <rtt/Logger.hpp> 12 log4cxx::LevelPtr tolog4cxxLevel( log4cpp::Priority::Value priority) {
16 case log4cpp::Priority::FATAL :
17 return Level::getFatal();
18 case log4cpp::Priority::ALERT :
19 return Level::getError();
20 case log4cpp::Priority::CRIT :
21 return Level::getError();
22 case log4cpp::Priority::ERROR :
23 return Level::getError();
24 case log4cpp::Priority::WARN :
25 return Level::getWarn();
26 case log4cpp::Priority::NOTICE :
27 return Level::getInfo();
28 case log4cpp::Priority::INFO :
29 return Level::getInfo();
30 case log4cpp::Priority::DEBUG :
31 return Level::getDebug();
32 case log4cpp::Priority::NOTSET :
33 return Level::getDebug();
35 return Level::getDebug();
38 spi::LoggingEventPtr tolog4cxx(logging::LoggingEvent
const& e, log4cxx::helpers::Pool & pool)
40 return spi::LoggingEventPtr(
new spi::LoggingEvent(makeString( e.categoryName ), tolog4cxxLevel(e.priority), makeString( e.message ), log4cxx::spi::LocationInfo(
"filename",
"functionname", 0)));
43 Log4cxxAppender::Log4cxxAppender(std::string name) :
44 RTT::TaskContext(name,
RTT::TaskContext::PreOperational),
46 hostname_prop(
"localhost"), port_prop(4560),
47 maxEventsPerCycle_prop(0),
51 ports()->addEventPort(
"LogPort", log_port );
52 properties()->addProperty(
"Hostname",hostname_prop).doc(
"Host name where ChainSaw or other logging server runs.");
53 properties()->addProperty(
"MaxEventsPerCycle",maxEventsPerCycle_prop).doc(
"Maximum number of log events to pop per cycle");
54 properties()->addProperty(
"Port", port_prop).doc(
"Logging server port to use on Hostname. ChainSaw uses port 4560.");
57 Log4cxxAppender::~Log4cxxAppender()
61 bool Log4cxxAppender::configureHook()
64 int m = maxEventsPerCycle_prop;
67 log(Error) <<
"Invalid maxEventsPerCycle value of " 68 << m <<
". Value must be >= 0." 72 maxEventsPerCycle = m;
75 if ( hostname_prop ==
"localhost")
76 address = helpers::InetAddress::getLocalHost();
78 address = helpers::InetAddress::getByName( hostname_prop );
80 if ( socketAppender ) {
81 socketAppender->close();
82 delete socketAppender;
85 net::SocketAppender::DEFAULT_RECONNECTION_DELAY = 3000;
88 log4cxx::net::SocketAppender( address, port_prop );
90 socketAppender->activateOptions(p);
95 void Log4cxxAppender::updateHook()
97 if (!log_port.connected())
return;
104 assert(socketAppender);
105 assert(0 <= maxEventsPerCycle);
106 if (0 == maxEventsPerCycle)
111 if (log_port.read( event ) == NewData)
113 spi::LoggingEventPtr e2 = tolog4cxx( event, p );
114 socketAppender->doAppend(e2, p);
126 int n = maxEventsPerCycle;
129 if (log_port.read( event ) == NewData)
131 spi::LoggingEventPtr e2 = tolog4cxx( event, p );
132 socketAppender->doAppend(e2, p);
144 void Log4cxxAppender::cleanupHook()
150 socketAppender->close();
151 delete socketAppender;
A mirror of log4cpp::LoggingEvent, except using real-time capable strings.
Interoperability component which translates our log4cpp events to log4cxx events and sends them to a ...
The Orocos Component Library.