Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
logging
tests
TestComponent.cpp
Go to the documentation of this file.
1
#include "
logging/tests/TestComponent.hpp
"
2
#include <
rtt/rt_string.hpp
>
3
#include "
logging/Category.hpp
"
4
5
#include <
rtt/Logger.hpp
>
6
#include "
ocl/Component.hpp
"
7
8
#include <
log4cpp/HierarchyMaintainer.hh
>
9
10
namespace
OCL
{
11
namespace
logging {
12
namespace
test
{
13
14
static
const
char
*
parentCategory
=
"org.orocos.ocl.logging.tests"
;
15
16
Component::Component
(std::string name) :
17
RTT
::
TaskContext
(name),
18
categoryName
(parentCategory +
std
::string(
"."
) + name),
19
logger(dynamic_cast<
OCL
::logging::
Category
*>(
20
&
log4cpp
::
Category
::getInstance(
categoryName
)))
21
{
22
}
23
24
Component::~Component
()
25
{
26
}
27
28
bool
Component::startHook
()
29
{
30
bool
ok = (0 !=
logger
);
31
if
(!ok)
32
{
33
log(
Error
) <<
"Unable to find existing OCL category '"
34
<<
categoryName
<<
"'"
<< endlog();
35
}
36
37
return
ok;
38
}
39
40
void
Component::updateHook
()
41
{
42
static
int
i=0;
43
RTT::rt_ostringstream
str_a, str_b;
44
str_a <<
"A:"
<<
getName
() <<
" "
<< i;
45
str_b <<
"B:"
<<
getName
() <<
" "
<< i;
46
47
// existing logging
48
// log(Debug) << str.str() << endlog();
49
50
// new logging
51
logger
->
error
(
"ERROR "
+
RTT::rt_string
(str_a.str().c_str()));
52
logger
->
error
(
"ERROR "
+
RTT::rt_string
(str_b.str().c_str()));
53
logger
->
info
(
"INFO "
+
RTT::rt_string
(str_a.str().c_str()));
54
logger
->
info
(
"INFO "
+
RTT::rt_string
(str_b.str().c_str()));
55
logger
->
debug
(
"DEBUG "
+
RTT::rt_string
(str_a.str().c_str()));
56
logger
->
debug
(
"DEBUG "
+
RTT::rt_string
(str_b.str().c_str()));
57
58
// RTT logging
59
//log(Error) << std::string("RTT ERROR " + str.str()) << endlog();
60
//log(Warning) << std::string("RTT WARNING " + str.str()) << endlog();
61
//log(Info) << std::string("RTT INFO " + str.str()) << endlog();
62
63
// and trying to use the std::string versions ...
64
// logger->error(std::string("Hello")); // COMPILER error - not accessible!
65
// logger->debug("DEBUG"); // COMPILER error - not accessible with char*!
66
67
++i;
68
}
69
70
// namespaces
71
}
72
}
73
}
74
75
ORO_CREATE_COMPONENT_TYPE
();
76
ORO_LIST_COMPONENT_TYPE
(
OCL::logging::test::Component
);
77
78
79
OCL::logging::test::Component::Component
Component(std::string name)
Definition:
TestComponent.cpp:16
OCL::logging::Category::debug
void debug(const RTT::rt_string &message)
Definition:
Category.cpp:33
RTT::rt_ostringstream
std::basic_ostringstream< char, std::char_traits< char >, RTT::os::rt_allocator< char > > rt_ostringstream
RTT::rt_string
std::basic_string< char, std::char_traits< char >, RTT::os::rt_allocator< char > > rt_string
std
rt_string.hpp
test
void test(std::string pattern, log4cpp::PatternLayout *layout, log4cpp::Category &cat)
OCL::logging::Category::info
void info(const RTT::rt_string &message)
Definition:
Category.cpp:39
OCL::logging::test::Component::startHook
virtual bool startHook()
Definition:
TestComponent.cpp:28
Logger.hpp
HierarchyMaintainer.hh
Component.hpp
OCL::logging::test::categoryName
static const char * categoryName
Definition:
TestLoggingAvailability.cpp:14
ORO_LIST_COMPONENT_TYPE
ORO_LIST_COMPONENT_TYPE(OCL::logging::test::Component)
OCL::logging::test::Component::categoryName
std::string categoryName
Name of our category.
Definition:
TestComponent.hpp:25
OCL::logging::test::Component::updateHook
virtual void updateHook()
Definition:
TestComponent.cpp:40
log4cpp
OCL::logging::test::Component::~Component
virtual ~Component()
Definition:
TestComponent.cpp:24
OCL
Definition:
deployer-funcs.cpp:68
Error
Error
OCL::logging::Category
Definition:
Category.hpp:25
OCL::logging::Category::error
void error(const RTT::rt_string &message)
Definition:
Category.cpp:57
RTT::TaskContext
ORO_CREATE_COMPONENT_TYPE
ORO_CREATE_COMPONENT_TYPE()
Category.hpp
RTT
OCL::logging::test::Component::logger
OCL::logging::Category * logger
Our logging category.
Definition:
TestComponent.hpp:27
RTT::TaskContext::getName
virtual const std::string & getName() const
OCL::logging::test::Component
Definition:
TestComponent.hpp:14
OCL::logging::test::parentCategory
static const char * parentCategory
Definition:
TestComponent.cpp:14
TestComponent.hpp
ocl
Author(s): OCL Development Team
autogenerated on Wed Jun 26 2019 19:26:27