-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestPattern.cpp
More file actions
61 lines (49 loc) · 1.71 KB
/
Copy pathtestPattern.cpp
File metadata and controls
61 lines (49 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// testLog4CPP.cpp : Derived from testCategory.cpp
//
#include <iostream>
#include <log4cpp/Appender.hh>
#include <log4cpp/BasicConfigurator.hh>
#include <log4cpp/Category.hh>
#include <log4cpp/NDC.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/Priority.hh>
void test(std::string pattern, log4cpp::PatternLayout* layout, log4cpp::Category& cat) {
try {
layout->setConversionPattern(pattern);
cat.error("message");
} catch (log4cpp::ConfigureFailure& f) {
std::cerr << "configure failure: " << f.what() << std::endl;
}
}
int main(int argc, char* argv[]) {
log4cpp::BasicConfigurator::configure();
log4cpp::PatternLayout* layout = new log4cpp::PatternLayout();
log4cpp::Category::getRoot().getAppender()->setLayout(layout);
log4cpp::Category& cat = log4cpp::Category::getInstance("cat1");
log4cpp::NDC::push("ndc1");
test("%% %r %c:%d (%R / %r) [%p] %x %m %% (%u) %n", layout, cat);
// test format specifiers
test(">%10m<%n", layout, cat);
test(">%-10m<%n", layout, cat);
test(">%3.5m<%n", layout, cat);
test(">%.5m<%n", layout, cat);
// category test
test(">%c{2}<%n", layout, log4cpp::Category::getInstance("c1.c2.c3.c4"));
// test date format
test("%d{%d %b %Y %H:%M:%S.%l} %m %n", layout, cat);
test("%d{%d %b %Y %H:%M:%S.%l", layout, cat);
test("%d%n", layout, cat);
test("%m %d%n", layout, cat);
int i;
for (i = 0; i < 10; i++) {
cat.error("%d message", i);
}
test("%m %d{%H:%M:%S.%l %d %b %Y}%n", layout, cat);
for (i = 0; i < 10; i++) {
cat.error("%d message", i);
}
// test bug #688715
test("%.10m", layout, cat);
log4cpp::Category::shutdown();
return 0;
}