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