testlogging.cpp
Go to the documentation of this file.
00001 // test mix of log4cpp and OCL::logging implementations
00002 
00003 #include <iostream>
00004 #include <log4cpp/HierarchyMaintainer.hh>
00005 #include "logging/Category.hpp"
00006 
00007 using namespace RTT;
00008 
00009 int main(int argc, char** argv)
00010 {
00011     // use only OCL::logging Category's
00012     log4cpp::HierarchyMaintainer::set_category_factory(
00013         OCL::logging::Category::createOCLCategory);
00014 
00015     std::string name = "org.test.c1";
00016 
00017     // what types do we get from the category itself?
00018     std::cout << "\nFrom category???\n";
00019     log4cpp::Category& category2 = log4cpp::Category::getInstance(name);
00020     std::cout << "category2 type " << typeid(category2).name() << std::endl;
00021     std::cout << "category2 ptype " << typeid(&category2).name() << std::endl;
00022 
00023     OCL::logging::Category* category = 
00024         dynamic_cast<OCL::logging::Category*>(&category2);
00025     if (0 != category)
00026     {
00027         std::cout << "category type " << typeid(*category).name() << std::endl;
00028     }
00029     else
00030     {
00031         std::cout << "Unable cast" << std::endl;
00032     }
00033 
00034     // and directly?
00035     std::cout << "\nDirectly ...\n";
00036     category = dynamic_cast<OCL::logging::Category*>(
00037         &log4cpp::Category::getInstance(name));
00038     if (0 != category)
00039     {
00040         std::cout << "category type " << typeid(*category).name() << std::endl;
00041     }
00042     else
00043     {
00044         std::cout << "Unable cast" << std::endl;
00045     }
00046 
00047     // and through hierarchy maintainer?
00048     std::cout << "\nThrough hierarchy maintainer ...\n";
00049     log4cpp::Category* p = log4cpp::HierarchyMaintainer::getDefaultMaintainer().getExistingInstance(name);
00050     std::cout << "category ptype " << typeid(p).name() << std::endl;
00051     std::cout << "category type  " << typeid(*p).name() << std::endl;
00052     category = dynamic_cast<OCL::logging::Category*>(p);
00053     if (0 != category)
00054     {
00055         std::cout << "category type " << typeid(*category).name() << std::endl;
00056     }
00057     else
00058     {
00059         std::cout << "Unable cast" << std::endl;
00060     }
00061         
00062     category = dynamic_cast<OCL::logging::Category*>(
00063         log4cpp::HierarchyMaintainer::getDefaultMaintainer().getExistingInstance(name));
00064     if (0 != category)
00065     {
00066         std::cout << "category type " << typeid(*category).name() << std::endl;
00067     }
00068     else
00069     {
00070         std::cout << "Unable cast" << std::endl;
00071     }
00072     
00073     return 0;
00074 }


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