testConfig.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 = "./log4cpp.init";
52  }
53  else {
54  initFileName = std::string(srcdir) + "/log4cpp.init";
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  root.error("root error");
71  root.warn("root warn");
72  sub1.error("sub1 error");
73  sub1.warn("sub1 warn");
74 
75  calcPi();
76 
77  sub2.error("sub2 error");
78  sub2.warn("sub2 warn");
79 
80  root.error("root error");
81  root.warn("root warn");
82  sub1.error("sub1 error");
83  sub1.warn("sub1 warn");
84 
85 #ifdef WIN32
86  Sleep(3000);
87 #else
88  sleep(3);
89 #endif
90 
91  sub2.error("sub2 error");
92  sub2.warn("sub2 warn");
93  sub2.error("%s %s %d", "test", "vform", 123);
94  sub2.warnStream() << "streamed warn";
95 
96  sub2 << log4cpp::Priority::WARN << "warn2.." << "..warn3..value=" << 0
97  << log4cpp::eol << "..warn4";
98 
100 
101  return 0;
102 }
103 
static void configure(const std::string &initFileName)
CategoryStream warnStream()
Definition: Category.hh:420
double calcPi()
Definition: testConfig.cpp:27
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
int main(int argc, char *argv[])
Definition: testConfig.cpp:42
void error(const char *stringFormat,...)
Definition: Category.cpp:347


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