OrocosComponentLibrary  2.9.0
OstreamAppender.cpp
1 #include "logging/OstreamAppender.hpp"
2 #include "ocl/Component.hpp"
3 
4 #include <log4cpp/OstreamAppender.hh>
5 
6 using namespace RTT;
7 
8 namespace OCL {
9 namespace logging {
10 
11 OstreamAppender::OstreamAppender(std::string name) :
12  OCL::logging::Appender(name),
13  maxEventsPerCycle_prop("MaxEventsPerCycle", "Maximum number of log events to pop per cycle",1),
14  maxEventsPerCycle(1)
15 {
16  properties()->addProperty(maxEventsPerCycle_prop);
17 }
18 
19 OstreamAppender::~OstreamAppender()
20 {
21 }
22 
23 bool OstreamAppender::configureHook()
24 {
25  // verify valid limits
26  int m = maxEventsPerCycle_prop.rvalue();
27  if ((0 > m))
28  {
29  log(Error) << "Invalid maxEventsPerCycle value of "
30  << m << ". Value must be >= 0."
31  << endlog();
32  return false;
33  }
34  maxEventsPerCycle = m;
35 
36  if (!appender)
37  appender = new log4cpp::OstreamAppender(getName(), &std::cout);
38 
39  return configureLayout();
40 }
41 
42 void OstreamAppender::updateHook()
43 {
44  processEvents(1);
45 }
46 
47 void OstreamAppender::cleanupHook()
48 {
49  /* normally in log4cpp the category owns the appenders and deletes them
50  itself, however we don't associate appenders and categories in the
51  same manner. Hence, you have to manually manage appenders.
52  */
53  delete appender;
54  appender = 0;
55 }
56 
57 // namespaces
58 }
59 }
60 
61 ORO_LIST_COMPONENT_TYPE(OCL::logging::OstreamAppender);
This file contains the macros and definitions to create dynamically loadable components.
The Orocos Component Library.
Definition: Component.hpp:43
Definition: Category.hpp:10