1 #include "logging/Appender.hpp" 4 #include <log4cpp/Appender.hh> 5 #include <log4cpp/BasicLayout.hh> 6 #include <log4cpp/SimpleLayout.hh> 7 #include <log4cpp/PatternLayout.hh> 12 Appender::Appender(std::string name) :
13 RTT::TaskContext(name,
RTT::TaskContext::PreOperational),
15 layoutName_prop(
"LayoutName",
"Layout name (e.g. 'simple', 'pattern')"),
16 layoutPattern_prop(
"LayoutPattern",
"Layout conversion pattern (for those layouts that use a pattern)"),
19 ports()->addEventPort(
"LogPort", log_port );
21 properties()->addProperty(layoutName_prop);
22 properties()->addProperty(layoutPattern_prop);
29 bool Appender::configureLayout()
32 const std::string& layoutName = layoutName_prop.rvalue();
33 const std::string& layoutPattern = layoutPattern_prop.rvalue();
37 (!layoutName.empty()))
40 if (0 == layoutName.compare(
"basic"))
42 appender->setLayout(
new log4cpp::BasicLayout());
44 else if (0 == layoutName.compare(
"simple"))
46 appender->setLayout(
new log4cpp::SimpleLayout());
48 else if (0 == layoutName.compare(
"pattern"))
50 log4cpp::PatternLayout *layout =
new log4cpp::PatternLayout();
52 layout->setConversionPattern(layoutPattern);
53 appender->setLayout(layout);
59 RTT::log(RTT::Error) <<
"Invalid layout '" << layoutName
60 <<
"' in configuration for category: " 61 << getName() << RTT::endlog();
69 bool Appender::startHook()
77 void Appender::stopHook()
90 ss <<
"# countMaxPopped=" << countMaxPopped;
91 log4cpp::LoggingEvent event(
"OCL.logging.Appender",
94 log4cpp::Priority::DEBUG);
95 appender->doAppend(event);
99 void Appender::drainBuffer()
104 void Appender::processEvents(
int n)
106 if (!log_port.connected())
return;
107 if (!appender)
return;
122 if (log_port.read( event ) == RTT::NewData)
129 again = (0 == n) || (count < n);
130 if ((0 != n) && (count == n)) ++countMaxPopped;
A mirror of log4cpp::LoggingEvent, except using real-time capable strings.
This file contains the macros and definitions to create dynamically loadable components.
The Orocos Component Library.
log4cpp::LoggingEvent toLog4cpp()
Convert to log4cpp class.