testPattern.cpp
Go to the documentation of this file.
1 // testLog4CPP.cpp : Derived from testCategory.cpp
2 //
3 #include <log4cpp/Category.hh>
4 #include <log4cpp/Appender.hh>
5 #include <log4cpp/Priority.hh>
6 #include <log4cpp/NDC.hh>
9 #include <iostream>
10 
11 void test(std::string pattern, log4cpp::PatternLayout* layout, log4cpp::Category& cat)
12 {
13  try {
14  layout->setConversionPattern(pattern);
15  cat.error("message");
16  } catch(log4cpp::ConfigureFailure& f) {
17  std::cerr << "configure failure: " << f.what() << std::endl;
18  }
19 }
20 
21 int main(int argc, char* argv[])
22 {
26 
28 
29  log4cpp::NDC::push("ndc1");
30 
31  test("%% %r %c:%d (%R / %r) [%p] %x %m %% (%u) %n", layout, cat);
32 
33  // test format specifiers
34  test(">%10m<%n", layout, cat);
35  test(">%-10m<%n", layout, cat);
36  test(">%3.5m<%n", layout, cat);
37  test(">%.5m<%n", layout, cat);
38 
39  // category test
40  test(">%c{2}<%n", layout, log4cpp::Category::getInstance("c1.c2.c3.c4"));
41 
42  // test date format
43  test("%d{%d %b %Y %H:%M:%S.%l} %m %n", layout, cat);
44  test("%d{%d %b %Y %H:%M:%S.%l", layout, cat);
45  test("%d%n", layout, cat);
46 
47  test("%m %d%n", layout, cat);
48  int i;
49  for (i = 0; i < 10; i++) {
50  cat.error("%d message", i);
51  }
52  test("%m %d{%H:%M:%S.%l %d %b %Y}%n", layout, cat);
53  for (i = 0; i < 10; i++) {
54  cat.error("%d message", i);
55  }
56 
57  // test bug #688715
58  test("%.10m", layout, cat);
59 
61 
62  return 0;
63 }
64 
virtual Appender * getAppender() const
Definition: Category.cpp:122
static Category & getInstance(const std::string &name)
Definition: Category.cpp:35
void test(std::string pattern, log4cpp::PatternLayout *layout, log4cpp::Category &cat)
Definition: testPattern.cpp:11
static void shutdown()
Definition: Category.cpp:48
virtual void setConversionPattern(const std::string &conversionPattern)
static Category & getRoot()
Definition: Category.cpp:23
static void push(const std::string &message)
Definition: NDC.cpp:61
void error(const char *stringFormat,...)
Definition: Category.cpp:347
int main(int argc, char *argv[])
Definition: testPattern.cpp:21
virtual void setLayout(Layout *layout)=0


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:14:17