Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
tests
testFixedContextCategory.cpp
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <iostream>
3
#include "
log4cpp/FixedContextCategory.hh
"
4
#include "
log4cpp/Appender.hh
"
5
#include "
log4cpp/OstreamAppender.hh
"
6
#include "
log4cpp/Layout.hh
"
7
#include "
log4cpp/BasicLayout.hh
"
8
#include "
log4cpp/Priority.hh
"
9
#include "
log4cpp/NDC.hh
"
10
11
int
main
(
int
argc,
char
** argv) {
12
log4cpp::Appender
* appender =
13
new
log4cpp::OstreamAppender
(
"default"
, &std::cout);
14
15
log4cpp::Layout
* layout =
new
log4cpp::BasicLayout
();
16
appender->
setLayout
(layout);
17
18
log4cpp::Category
& root =
log4cpp::Category::getRoot
();
19
root.
addAppender
(appender);
20
root.
setPriority
(
log4cpp::Priority::ERROR
);
21
22
log4cpp::FixedContextCategory
sub1(std::string(
"sub1"
), std::string(
"context1"
));
23
24
log4cpp::FixedContextCategory
sub1_2(std::string(
"sub1"
), std::string(
"context1_2"
));
25
26
log4cpp::FixedContextCategory
sub2(std::string(
"sub1.sub2"
), std::string(
"context2"
));
27
28
std::cout <<
" root priority = "
<< root.
getPriority
() << std::endl;
29
std::cout <<
" sub1 priority = "
<< sub1.
getPriority
() << std::endl;
30
std::cout <<
" sub2 priority = "
<< sub2.
getPriority
() << std::endl;
31
32
root.
error
(
"root error"
);
33
root.
warn
(
"root warn"
);
34
sub1.
error
(
"sub1 error"
);
35
sub1.
warn
(
"sub1 warn"
);
36
sub1_2.
error
(
"sub1 error"
);
37
sub1_2.
warn
(
"sub1 warn"
);
38
sub2.
error
(
"sub2 error"
);
39
sub2.
warn
(
"sub2 warn"
);
40
41
log4cpp::Category::getInstance
(std::string(
"sub1"
)).
42
setPriority(
log4cpp::Priority::INFO
);
43
44
std::cout <<
" root priority = "
<< root.
getPriority
() << std::endl;
45
std::cout <<
" sub1 priority = "
<< sub1.
getPriority
() << std::endl;
46
std::cout <<
" sub2 priority = "
<< sub2.
getPriority
() << std::endl;
47
48
std::cout <<
"priority info"
<< std::endl;
49
root.
error
(
"root error"
);
50
root.
warn
(
"root warn"
);
51
sub1.
error
(
"sub1 error"
);
52
sub1.
warn
(
"sub1 warn"
);
53
sub2.
error
(
"sub2 error"
);
54
sub2.
warn
(
"sub2 warn"
);
55
sub2.
error
(
"%s %s %d"
,
"test"
,
"vform"
, 123);
56
sub2.
warnStream
() <<
"streamed warn"
;
57
58
sub2 <<
log4cpp::Priority::WARN
<<
"warn2.."
<<
"..warn3..value="
<< 0
59
<<
log4cpp::eol
<<
"..warn4"
;
60
61
log4cpp::Category::shutdown
();
62
63
return
0;
64
}
log4cpp::Category::warnStream
CategoryStream warnStream()
Definition:
Category.hh:420
log4cpp::Priority::INFO
Definition:
Priority.hh:77
log4cpp::Category
Definition:
Category.hh:33
Layout.hh
log4cpp::Category::warn
void warn(const char *stringFormat,...)
Definition:
Category.cpp:333
OstreamAppender.hh
log4cpp::eol
LOG4CPP_EXPORT CategoryStream & eol(CategoryStream &os)
Definition:
CategoryStream.cpp:65
log4cpp::Category::getInstance
static Category & getInstance(const std::string &name)
Definition:
Category.cpp:35
Appender.hh
log4cpp::Category::shutdown
static void shutdown()
Definition:
Category.cpp:48
log4cpp::Layout
Definition:
Layout.hh:22
log4cpp::FixedContextCategory::getPriority
virtual Priority::Value getPriority() const
Definition:
FixedContextCategory.cpp:33
NDC.hh
log4cpp::BasicLayout
Definition:
BasicLayout.hh:21
log4cpp::Category::getRoot
static Category & getRoot()
Definition:
Category.cpp:23
log4cpp::Category::getPriority
virtual Priority::Value getPriority() const
Definition:
Category.cpp:67
log4cpp::Category::setPriority
virtual void setPriority(Priority::Value priority)
Definition:
Category.cpp:71
BasicLayout.hh
log4cpp::Appender
Definition:
Appender.hh:33
main
int main(int argc, char **argv)
Definition:
testFixedContextCategory.cpp:11
log4cpp::Category::addAppender
virtual void addAppender(Appender *appender)
Definition:
Category.cpp:94
log4cpp::Category::error
void error(const char *stringFormat,...)
Definition:
Category.cpp:347
log4cpp::Priority::ERROR
Definition:
Priority.hh:74
log4cpp::Priority::WARN
Definition:
Priority.hh:75
log4cpp::Appender::setLayout
virtual void setLayout(Layout *layout)=0
Priority.hh
log4cpp::OstreamAppender
Definition:
OstreamAppender.hh:23
FixedContextCategory.hh
log4cpp::FixedContextCategory
Definition:
FixedContextCategory.hh:29
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