Skip to content

OCL:Logging: Add logging priority filter to appenders. #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: toolchain-2.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions logging/Appender.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "logging/Appender.hpp"
#include "ocl/Component.hpp"

#include <boost/algorithm/string.hpp>

#include <log4cpp/Appender.hh>
#include <log4cpp/BasicLayout.hh>
#include <log4cpp/SimpleLayout.hh>
Expand All @@ -14,18 +16,38 @@ Appender::Appender(std::string name) :
appender(0),
layoutName_prop("LayoutName", "Layout name (e.g. 'simple', 'pattern')"),
layoutPattern_prop("LayoutPattern", "Layout conversion pattern (for those layouts that use a pattern)"),
priorityThreshold_prop("PriorityThreshold", "Messages with lower priorities are filtered.", "NOTSET"),
countMaxPopped(0)
{
ports()->addEventPort("LogPort", log_port );

properties()->addProperty(layoutName_prop);
properties()->addProperty(layoutPattern_prop);
properties()->addProperty(priorityThreshold_prop);
}

Appender::~Appender()
{
}

bool Appender::configureThreshold()
{
log4cpp::Priority::Value priority = log4cpp::Priority::NOTSET;
try
{
priority = log4cpp::Priority::getPriorityValue( boost::to_upper_copy( priorityThreshold_prop.rvalue() ) );
}
catch (std::invalid_argument)
{
// \todo more descriptive
RTT::Logger::In in(getName());
RTT::log(RTT::Error) << "Bad log4cpp priority: " << priorityThreshold_prop.rvalue() << RTT::endlog();
return false;
}
if (appender) appender->setThreshold(priority);
return true;
}

bool Appender::configureLayout()
{
bool rc;
Expand Down Expand Up @@ -70,6 +92,8 @@ bool Appender::startHook()
{
/// \todo input ports must be connected?
// return log_port.ready();
//
configureThreshold();

return true;
}
Expand Down
7 changes: 7 additions & 0 deletions logging/Appender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Appender : public RTT::TaskContext
successfully, otherwise false
*/
virtual bool configureLayout();

/** Set appender priority threshold.
*/
bool configureThreshold();

/// ensure port is connected before we start
virtual bool startHook();
/// Drain the buffer
Expand Down Expand Up @@ -56,6 +61,8 @@ class Appender : public RTT::TaskContext
RTT::Property<std::string> layoutName_prop;
/// Layout conversion pattern (for those layouts that use a pattern)
RTT::Property<std::string> layoutPattern_prop;
/// Priority threshold
RTT::Property<std::string> priorityThreshold_prop;

/* Used by \a processEvents() when popping items from the buffer.
* This is a class member, rather than a stack instance, to reduce the
Expand Down