TestComponent.cpp
Go to the documentation of this file.
00001 #include "logging/tests/TestComponent.hpp"
00002 #include <rtt/rt_string.hpp>
00003 #include "logging/Category.hpp"
00004 
00005 #include <rtt/Logger.hpp>
00006 #include "ocl/Component.hpp"
00007 
00008 #include <log4cpp/HierarchyMaintainer.hh>
00009 
00010 namespace OCL {
00011 namespace logging {
00012 namespace test {
00013 
00014 static const char* parentCategory = "org.orocos.ocl.logging.tests";
00015 
00016 Component::Component(std::string name) :
00017                 RTT::TaskContext(name),
00018         categoryName(parentCategory + std::string(".") + name),
00019         logger(dynamic_cast<OCL::logging::Category*>(
00020                    &log4cpp::Category::getInstance(categoryName)))
00021 {
00022 }
00023 
00024 Component::~Component()
00025 {
00026 }
00027 
00028 bool Component::startHook()
00029 {
00030     bool ok = (0 != logger);
00031     if (!ok)
00032     {
00033         log(Error) << "Unable to find existing OCL category '" 
00034                    << categoryName << "'" << endlog();
00035     }
00036     
00037     return ok;
00038 }
00039         
00040 void Component::updateHook()
00041 {
00042         static int i=0;
00043         RTT::rt_ostringstream   str_a, str_b;
00044         str_a <<"A:" << getName() << " " << i;
00045         str_b <<"B:" << getName() << " " << i;
00046 
00047     // existing logging
00048 //      log(Debug) << str.str() << endlog();
00049 
00050     // new logging
00051     logger->error("ERROR " + RTT::rt_string(str_a.str().c_str()));
00052     logger->error("ERROR " + RTT::rt_string(str_b.str().c_str()));
00053     logger->info( "INFO  " + RTT::rt_string(str_a.str().c_str()));
00054     logger->info( "INFO  " + RTT::rt_string(str_b.str().c_str()));
00055     logger->debug("DEBUG " + RTT::rt_string(str_a.str().c_str()));
00056     logger->debug("DEBUG " + RTT::rt_string(str_b.str().c_str()));
00057 
00058     // RTT logging
00059     //log(Error)   << std::string("RTT ERROR " + str.str())   << endlog();
00060     //log(Warning) << std::string("RTT WARNING " + str.str()) << endlog();
00061     //log(Info)    << std::string("RTT INFO " + str.str())    << endlog();
00062 
00063     // and trying to use the std::string versions ...
00064 //    logger->error(std::string("Hello")); // COMPILER error - not accessible!
00065 //    logger->debug("DEBUG"); // COMPILER error - not accessible with char*!
00066 
00067         ++i;
00068 }
00069 
00070 // namespaces
00071 }
00072 }
00073 }
00074 
00075 ORO_CREATE_COMPONENT_TYPE();
00076 ORO_LIST_COMPONENT_TYPE(OCL::logging::test::Component);
00077 
00078 
00079 


ocl
Author(s): OCL Development Team
autogenerated on Mon Sep 14 2015 14:21:47