testFixedContextCategory.cpp
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <iostream>
00003 #include "log4cpp/FixedContextCategory.hh"
00004 #include "log4cpp/Appender.hh"
00005 #include "log4cpp/OstreamAppender.hh"
00006 #include "log4cpp/Layout.hh"
00007 #include "log4cpp/BasicLayout.hh"
00008 #include "log4cpp/Priority.hh"
00009 #include "log4cpp/NDC.hh"
00010 
00011 int main(int argc, char** argv) {    
00012     log4cpp::Appender* appender = 
00013         new log4cpp::OstreamAppender("default", &std::cout);
00014 
00015     log4cpp::Layout* layout = new log4cpp::BasicLayout();
00016     appender->setLayout(layout);
00017 
00018     log4cpp::Category& root = log4cpp::Category::getRoot();
00019     root.addAppender(appender);
00020        root.setPriority(log4cpp::Priority::ERROR);
00021     
00022     log4cpp::FixedContextCategory sub1(std::string("sub1"), std::string("context1"));
00023 
00024     log4cpp::FixedContextCategory sub1_2(std::string("sub1"), std::string("context1_2"));
00025 
00026     log4cpp::FixedContextCategory sub2(std::string("sub1.sub2"), std::string("context2"));
00027 
00028     std::cout << " root priority = " << root.getPriority() << std::endl;
00029     std::cout << " sub1 priority = " << sub1.getPriority() << std::endl;
00030     std::cout << " sub2 priority = " << sub2.getPriority() << std::endl;
00031     
00032     root.error("root error");
00033     root.warn("root warn");
00034     sub1.error("sub1 error");
00035     sub1.warn("sub1 warn");
00036     sub1_2.error("sub1 error");
00037     sub1_2.warn("sub1 warn");
00038     sub2.error("sub2 error");
00039     sub2.warn("sub2 warn");
00040     
00041     log4cpp::Category::getInstance(std::string("sub1")).
00042                setPriority(log4cpp::Priority::INFO);
00043 
00044     std::cout << " root priority = " << root.getPriority() << std::endl;
00045     std::cout << " sub1 priority = " << sub1.getPriority() << std::endl;
00046     std::cout << " sub2 priority = " << sub2.getPriority() << std::endl;
00047    
00048     std::cout << "priority info" << std::endl;
00049     root.error("root error");
00050     root.warn("root warn");
00051     sub1.error("sub1 error");
00052     sub1.warn("sub1 warn");
00053     sub2.error("sub2 error");
00054     sub2.warn("sub2 warn");
00055     sub2.error("%s %s %d", "test", "vform", 123);
00056     sub2.warnStream() << "streamed warn";
00057 
00058     sub2 << log4cpp::Priority::WARN << "warn2.." << "..warn3..value=" << 0 
00059          << log4cpp::eol << "..warn4";
00060 
00061     log4cpp::Category::shutdown();
00062 
00063     return 0;
00064 }


log4cpp
Author(s): Stephen Roderick
autogenerated on Mon Oct 6 2014 03:13:14