testPropertyConfig.cpp
Go to the documentation of this file.
1 // testConfig.cpp : Derived from testPattern.cpp.
2 //
3 
4 #include <log4cpp/Portability.hh>
5 
6 #ifdef WIN32
7 #include <windows.h>
8 #endif
9 #ifdef LOG4CPP_HAVE_UNISTD_H
10 #include <unistd.h>
11 #endif
12 
13 #include <stdlib.h>
14 
15 #include <log4cpp/Category.hh>
16 #include <log4cpp/Appender.hh>
18 #include <log4cpp/FileAppender.hh>
19 #include <log4cpp/Layout.hh>
20 #include <log4cpp/BasicLayout.hh>
21 #include <log4cpp/Priority.hh>
22 #include <log4cpp/NDC.hh>
23 #include <log4cpp/PatternLayout.hh>
24 
26 
27 double calcPi()
28 {
29  double denominator = 3.0;
30  double retVal = 4.0;
31  long i;
32  for (i = 0; i < 50000000l; i++)
33  {
34  retVal = retVal - (4.0 / denominator);
35  denominator += 2.0;
36  retVal = retVal + (4.0 /denominator);
37  denominator += 2.0;
38  }
39  return retVal;
40 }
41 
42 int main(int argc, char* argv[])
43 {
44  try {
45  /* looking for the init file in $srcdir is a requirement of
46  automake's distcheck target.
47  */
48  char* srcdir = getenv("srcdir");
49  std::string initFileName;
50  if (srcdir == NULL) {
51  initFileName = "./testConfig.log4cpp.properties";
52  }
53  else {
54  initFileName = std::string(srcdir) + "/testConfig.log4cpp.properties";
55  }
57  } catch(log4cpp::ConfigureFailure& f) {
58  std::cout << "Configure Problem " << f.what() << std::endl;
59  return -1;
60  }
61 
63 
64  log4cpp::Category& sub1 =
65  log4cpp::Category::getInstance(std::string("sub1"));
66 
67  log4cpp::Category& sub2 =
68  log4cpp::Category::getInstance(std::string("sub1.sub2"));
69 
70  log4cpp::Category& sub3 =
71  log4cpp::Category::getInstance(std::string("sub1.sub2.sub3"));
72 
73  root.error("root error");
74  root.warn("root warn");
75  sub1.error("sub1 error");
76  sub1.warn("sub1 warn");
77 
78  calcPi();
79 
80  sub2.error("sub2 error");
81  sub2.warn("sub2 warn");
82 
83  root.error("root error");
84  root.warn("root warn");
85  sub1.error("sub1 error");
86  sub1.warn("sub1 warn");
87 
88 #ifdef WIN32
89  Sleep(3000);
90 #else
91  sleep(3);
92 #endif
93 
94  sub2.error("sub2 error");
95  sub2.warn("sub2 warn");
96  sub2.error("%s %s %d", "test", "vform", 123);
97  sub2.warnStream() << "streamed warn";
98 
99  sub2 << log4cpp::Priority::WARN << "warn2.." << "..warn3..value=" << 0
100  << log4cpp::eol << "..warn4";
101 
102  sub3 << log4cpp::Priority::INFO << "Very long config string follows";
103 
105 
106  return 0;
107 }
108 
CategoryStream warnStream()
Definition: Category.hh:420
int main(int argc, char *argv[])
void warn(const char *stringFormat,...)
Definition: Category.cpp:333
LOG4CPP_EXPORT CategoryStream & eol(CategoryStream &os)
static Category & getInstance(const std::string &name)
Definition: Category.cpp:35
static void shutdown()
Definition: Category.cpp:48
static Category & getRoot()
Definition: Category.cpp:23
double calcPi()
void error(const char *stringFormat,...)
Definition: Category.cpp:347
static void configure(const std::string &initFileName)


log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Jun 23 2019 19:10:00