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 std::stringstream str; 00044 str << getName() << " " << i; 00045 00046 // existing logging 00047 // log(Debug) << str.str() << endlog(); 00048 00049 // new logging 00050 logger->error("ERROR " + RTT::rt_string(str.str().c_str())); 00051 logger->info( "INFO " + RTT::rt_string(str.str().c_str())); 00052 logger->debug("DEBUG " + RTT::rt_string(str.str().c_str())); 00053 00054 // RTT logging 00055 log(Error) << std::string("RTT ERROR " + str.str()) << endlog(); 00056 log(Warning) << std::string("RTT WARNING " + str.str()) << endlog(); 00057 log(Info) << std::string("RTT INFO " + str.str()) << endlog(); 00058 00059 // and trying to use the std::string versions ... 00060 // logger->error(std::string("Hello")); // COMPILER error - not accessible! 00061 // logger->debug("DEBUG"); // COMPILER error - not accessible with char*! 00062 00063 ++i; 00064 } 00065 00066 // namespaces 00067 } 00068 } 00069 } 00070 00071 ORO_CREATE_COMPONENT_TYPE(); 00072 ORO_LIST_COMPONENT_TYPE(OCL::logging::test::Component); 00073 00074 00075