testPropertyConfig.cpp
Go to the documentation of this file.
00001 // testConfig.cpp : Derived from testPattern.cpp.
00002 //
00003 
00004 #include <log4cpp/Portability.hh>
00005 
00006 #ifdef WIN32
00007 #include <windows.h>
00008 #endif
00009 #ifdef LOG4CPP_HAVE_UNISTD_H
00010 #include <unistd.h>
00011 #endif
00012 
00013 #include <cstdlib>
00014 
00015 #include <log4cpp/Category.hh>
00016 #include <log4cpp/Appender.hh>
00017 #include <log4cpp/OstreamAppender.hh>
00018 #include <log4cpp/FileAppender.hh>
00019 #include <log4cpp/Layout.hh>
00020 #include <log4cpp/BasicLayout.hh>
00021 #include <log4cpp/Priority.hh>
00022 #include <log4cpp/NDC.hh>
00023 #include <log4cpp/PatternLayout.hh>
00024 
00025 #include <log4cpp/PropertyConfigurator.hh>
00026 
00027 double calcPi()
00028 {
00029     double denominator = 3.0;
00030     double retVal = 4.0;
00031     long i;
00032     for (i = 0; i < 50000000l; i++)
00033     {
00034         retVal = retVal - (4.0 / denominator);
00035         denominator += 2.0;
00036         retVal = retVal + (4.0 /denominator);
00037         denominator += 2.0;
00038     }
00039     return retVal;
00040 }
00041 
00042 int main(int argc, char* argv[])
00043 {
00044     try {
00045         /* looking for the init file in $srcdir is a requirement of
00046            automake's distcheck target.
00047         */
00048         char* srcdir = std::getenv("srcdir");
00049         std::string initFileName;
00050         if (srcdir == NULL) {
00051             initFileName = "./testConfig.log4cpp.properties";
00052         }
00053         else {
00054             initFileName = std::string(srcdir) + "/testConfig.log4cpp.properties";
00055         }
00056         log4cpp::PropertyConfigurator::configure(initFileName);
00057     } catch(log4cpp::ConfigureFailure& f) {
00058         std::cout << "Configure Problem " << f.what() << std::endl;
00059         return -1;
00060     }
00061 
00062     log4cpp::Category& root = log4cpp::Category::getRoot();
00063 
00064     log4cpp::Category& sub1 = 
00065         log4cpp::Category::getInstance(std::string("sub1"));
00066 
00067     log4cpp::Category& sub2 = 
00068         log4cpp::Category::getInstance(std::string("sub1.sub2"));
00069 
00070     root.error("root error");
00071     root.warn("root warn");
00072     sub1.error("sub1 error");
00073     sub1.warn("sub1 warn");
00074 
00075     calcPi();
00076 
00077     sub2.error("sub2 error");
00078     sub2.warn("sub2 warn");
00079 
00080     root.error("root error");
00081     root.warn("root warn");
00082     sub1.error("sub1 error");
00083     sub1.warn("sub1 warn");
00084 
00085 #ifdef WIN32
00086     Sleep(3000);
00087 #else
00088     sleep(3);
00089 #endif
00090 
00091     sub2.error("sub2 error");
00092     sub2.warn("sub2 warn");
00093     sub2.error("%s %s %d", "test", "vform", 123);
00094     sub2.warnStream() << "streamed warn";
00095 
00096     sub2 << log4cpp::Priority::WARN << "warn2.." << "..warn3..value=" << 0 
00097          << log4cpp::eol << "..warn4";
00098 
00099     log4cpp::Category::shutdown();
00100 
00101     return 0;
00102 }
00103 


log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Aug 14 2016 03:18:26