Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
tests
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
>
7
#include <
log4cpp/PatternLayout.hh
>
8
#include <
log4cpp/BasicConfigurator.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
{
23
log4cpp::BasicConfigurator::configure
();
24
log4cpp::PatternLayout
* layout =
new
log4cpp::PatternLayout
();
25
log4cpp::Category::getRoot
().
getAppender
()->
setLayout
(layout);
26
27
log4cpp::Category
& cat =
log4cpp::Category::getInstance
(
"cat1"
);
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
60
log4cpp::Category::shutdown
();
61
62
return
0;
63
}
64
log4cpp::Category
Definition:
Category.hh:33
log4cpp::Category::getAppender
virtual Appender * getAppender() const
Definition:
Category.cpp:122
log4cpp::Category::getInstance
static Category & getInstance(const std::string &name)
Definition:
Category.cpp:35
Appender.hh
test
void test(std::string pattern, log4cpp::PatternLayout *layout, log4cpp::Category &cat)
Definition:
testPattern.cpp:11
log4cpp::Category::shutdown
static void shutdown()
Definition:
Category.cpp:48
log4cpp::ConfigureFailure
Definition:
Configurator.hh:21
log4cpp::PatternLayout::setConversionPattern
virtual void setConversionPattern(const std::string &conversionPattern)
Definition:
PatternLayout.cpp:299
PatternLayout.hh
NDC.hh
log4cpp::Category::getRoot
static Category & getRoot()
Definition:
Category.cpp:23
log4cpp::NDC::push
static void push(const std::string &message)
Definition:
NDC.cpp:61
Category.hh
log4cpp::Category::error
void error(const char *stringFormat,...)
Definition:
Category.cpp:347
log4cpp::BasicConfigurator::configure
static void configure()
Definition:
BasicConfigurator.cpp:25
main
int main(int argc, char *argv[])
Definition:
testPattern.cpp:21
log4cpp::Appender::setLayout
virtual void setLayout(Layout *layout)=0
log4cpp::PatternLayout
Definition:
PatternLayout.hh:25
Priority.hh
BasicConfigurator.hh
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