TestComponent.cpp
Go to the documentation of this file.
2 #include <rtt/rt_string.hpp>
3 #include "logging/Category.hpp"
4 
5 #include <rtt/Logger.hpp>
6 #include "ocl/Component.hpp"
7 
9 
10 namespace OCL {
11 namespace logging {
12 namespace test {
13 
14 static const char* parentCategory = "org.orocos.ocl.logging.tests";
15 
16 Component::Component(std::string name) :
17  RTT::TaskContext(name),
18  categoryName(parentCategory + std::string(".") + name),
19  logger(dynamic_cast<OCL::logging::Category*>(
20  &log4cpp::Category::getInstance(categoryName)))
21 {
22 }
23 
25 {
26 }
27 
29 {
30  bool ok = (0 != logger);
31  if (!ok)
32  {
33  log(Error) << "Unable to find existing OCL category '"
34  << categoryName << "'" << endlog();
35  }
36 
37  return ok;
38 }
39 
41 {
42  static int i=0;
43  RTT::rt_ostringstream str_a, str_b;
44  str_a <<"A:" << getName() << " " << i;
45  str_b <<"B:" << getName() << " " << i;
46 
47  // existing logging
48 // log(Debug) << str.str() << endlog();
49 
50  // new logging
51  logger->error("ERROR " + RTT::rt_string(str_a.str().c_str()));
52  logger->error("ERROR " + RTT::rt_string(str_b.str().c_str()));
53  logger->info( "INFO " + RTT::rt_string(str_a.str().c_str()));
54  logger->info( "INFO " + RTT::rt_string(str_b.str().c_str()));
55  logger->debug("DEBUG " + RTT::rt_string(str_a.str().c_str()));
56  logger->debug("DEBUG " + RTT::rt_string(str_b.str().c_str()));
57 
58  // RTT logging
59  //log(Error) << std::string("RTT ERROR " + str.str()) << endlog();
60  //log(Warning) << std::string("RTT WARNING " + str.str()) << endlog();
61  //log(Info) << std::string("RTT INFO " + str.str()) << endlog();
62 
63  // and trying to use the std::string versions ...
64 // logger->error(std::string("Hello")); // COMPILER error - not accessible!
65 // logger->debug("DEBUG"); // COMPILER error - not accessible with char*!
66 
67  ++i;
68 }
69 
70 // namespaces
71 }
72 }
73 }
74 
77 
78 
79 
void debug(const RTT::rt_string &message)
Definition: Category.cpp:33
std::basic_ostringstream< char, std::char_traits< char >, RTT::os::rt_allocator< char > > rt_ostringstream
std::basic_string< char, std::char_traits< char >, RTT::os::rt_allocator< char > > rt_string
void test(std::string pattern, log4cpp::PatternLayout *layout, log4cpp::Category &cat)
void info(const RTT::rt_string &message)
Definition: Category.cpp:39
static const char * categoryName
ORO_LIST_COMPONENT_TYPE(OCL::logging::test::Component)
std::string categoryName
Name of our category.
Error
void error(const RTT::rt_string &message)
Definition: Category.cpp:57
ORO_CREATE_COMPONENT_TYPE()
OCL::logging::Category * logger
Our logging category.
virtual const std::string & getName() const
static const char * parentCategory


ocl
Author(s): OCL Development Team
autogenerated on Wed Jun 26 2019 19:26:27