testFixedContextCategory.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <iostream>
4 #include "log4cpp/Appender.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 
19  root.addAppender(appender);
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 
62 
63  return 0;
64 }
CategoryStream warnStream()
Definition: Category.hh:420
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
virtual Priority::Value getPriority() const
static Category & getRoot()
Definition: Category.cpp:23
virtual Priority::Value getPriority() const
Definition: Category.cpp:67
virtual void setPriority(Priority::Value priority)
Definition: Category.cpp:71
int main(int argc, char **argv)
virtual void addAppender(Appender *appender)
Definition: Category.cpp:94
void error(const char *stringFormat,...)
Definition: Category.cpp:347
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:10:00