Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
logging
GenerationalFileAppender.cpp
Go to the documentation of this file.
1
#include "
logging/GenerationalFileAppender.hpp
"
2
#include "
ocl/Component.hpp
"
3
#include <
rtt/Logger.hpp
>
4
5
#include <
log4cpp/GenerationalFileAppender.hh
>
6
7
using namespace
RTT
;
8
9
namespace
OCL
{
10
namespace
logging {
11
12
GenerationalFileAppender::GenerationalFileAppender(std::string name) :
13
OCL
::logging::
Appender
(name),
14
advanceGeneration_op(
"advanceGeneration"
, &
GenerationalFileAppender
::advanceGeneration, this,
RTT
::
OwnThread
),
15
filename_prop(
"Filename"
,
"Name of file to log to"
),
16
maxEventsPerCycle_prop(
"MaxEventsPerCycle"
,
17
"Maximum number of log events to pop per cycle"
,
18
1),
19
maxEventsPerCycle(1)
20
{
21
provides
()->addOperation(
advanceGeneration_op
).doc(
"Advance to the next logfile generation"
);
22
23
properties
()->
addProperty
(
filename_prop
);
24
properties
()->
addProperty
(
maxEventsPerCycle_prop
);
25
}
26
27
GenerationalFileAppender::~GenerationalFileAppender
()
28
{
29
}
30
31
bool
GenerationalFileAppender::configureHook
()
32
{
33
// verify valid limits
34
int
m =
maxEventsPerCycle_prop
.
rvalue
();
35
if
((0 > m))
36
{
37
log(
Error
) <<
"Invalid maxEventsPerCycle value of "
38
<< m <<
". Value must be >= 0."
39
<< endlog();
40
return
false
;
41
}
42
maxEventsPerCycle
= m;
43
44
// \todo error checking
45
46
appender
=
new
log4cpp::GenerationalFileAppender
(
getName
(),
47
filename_prop
.
get
());
48
49
return
configureLayout
();
50
}
51
52
void
GenerationalFileAppender::updateHook
()
53
{
54
processEvents
(
maxEventsPerCycle
);
55
}
56
57
void
GenerationalFileAppender::cleanupHook
()
58
{
59
/* normally in log4cpp the category owns the appenders and deletes them
60
itself, however we don't associate appenders and categories in the
61
same manner. Hence, you have to manually manage appenders.
62
*/
63
delete
appender
;
64
appender
= 0;
65
}
66
67
void
GenerationalFileAppender::advanceGeneration
()
68
{
69
if
(0 !=
appender
)
70
{
71
static_cast<
log4cpp::GenerationalFileAppender
*
>
(
appender
)->
advanceGeneration
();
72
}
73
else
74
{
75
log(
Error
) <<
"No appender to roll over!"
<< endlog();
76
}
77
}
78
79
// namespaces
80
}
81
}
82
83
ORO_LIST_COMPONENT_TYPE
(
OCL::logging::GenerationalFileAppender
);
OCL::logging::GenerationalFileAppender::configureHook
virtual bool configureHook()
Create log4cpp appender.
Definition:
GenerationalFileAppender.cpp:31
RTT::Property::get
DataSourceType get() const
OCL::logging::Appender::appender
log4cpp::Appender * appender
Appender created by derived class.
Definition:
Appender.hpp:52
RTT::TaskContext::provides
Service::shared_ptr provides()
OCL::logging::GenerationalFileAppender::advanceGeneration_op
RTT::Operation< void(void)> advanceGeneration_op
Definition:
GenerationalFileAppender.hpp:28
OCL::logging::GenerationalFileAppender::~GenerationalFileAppender
virtual ~GenerationalFileAppender()
Definition:
GenerationalFileAppender.cpp:27
OCL::logging::GenerationalFileAppender::maxEventsPerCycle
int maxEventsPerCycle
Definition:
GenerationalFileAppender.hpp:48
OCL::logging::GenerationalFileAppender::cleanupHook
virtual void cleanupHook()
Destroy appender.
Definition:
GenerationalFileAppender.cpp:57
GenerationalFileAppender.hh
RTT::Property::rvalue
const_reference_t rvalue() const
RTT::OwnThread
OwnThread
OCL::logging::Appender
Definition:
Appender.hpp:16
Logger.hpp
GenerationalFileAppender.hpp
Component.hpp
OCL::logging::Appender::configureLayout
virtual bool configureLayout()
Definition:
Appender.cpp:29
RTT::PropertyBag::addProperty
Property< T > & addProperty(const std::string &name, T &attr)
OCL
Definition:
deployer-funcs.cpp:68
OCL::logging::Appender::processEvents
virtual void processEvents(int n)
Definition:
Appender.cpp:104
OCL::logging::GenerationalFileAppender::advanceGeneration
void advanceGeneration()
Advance to the next logfile generation.
Definition:
GenerationalFileAppender.cpp:67
Error
Error
OCL::logging::GenerationalFileAppender::maxEventsPerCycle_prop
RTT::Property< int > maxEventsPerCycle_prop
Definition:
GenerationalFileAppender.hpp:37
log4cpp::GenerationalFileAppender
RTT::TaskContext::properties
PropertyBag * properties()
ORO_LIST_COMPONENT_TYPE
ORO_LIST_COMPONENT_TYPE(OCL::logging::GenerationalFileAppender)
OCL::logging::GenerationalFileAppender::updateHook
virtual void updateHook()
Process at most maxEventsPerCycle event.
Definition:
GenerationalFileAppender.cpp:52
RTT
OCL::logging::GenerationalFileAppender
Definition:
GenerationalFileAppender.hpp:14
OCL::logging::GenerationalFileAppender::filename_prop
RTT::Property< std::string > filename_prop
Name of file to append to.
Definition:
GenerationalFileAppender.hpp:33
RTT::TaskContext::getName
virtual const std::string & getName() const
ocl
Author(s): OCL Development Team
autogenerated on Wed Jun 26 2019 19:26:27