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