5 #include <boost/algorithm/string.hpp> 19 LoggingService::LoggingService(std::string name) :
21 levels_prop(
"Levels",
"A PropertyBag defining the level of each category of interest."),
22 additivity_prop(
"Additivity",
"A PropertyBag defining the additivity of each category of interest."),
23 appenders_prop(
"Appenders",
"A PropertyBag defining the appenders for each category of interest."),
24 level_EMERG_attr (
"EMERG",
log4cpp::Priority::EMERG ),
25 level_FATAL_attr (
"FATAL",
log4cpp::Priority::FATAL ),
26 level_ALERT_attr (
"ALERT",
log4cpp::Priority::ALERT ),
27 level_CRIT_attr (
"CRIT",
log4cpp::Priority::CRIT ),
29 level_WARN_attr (
"WARN",
log4cpp::Priority::WARN ),
30 level_NOTICE_attr(
"NOTICE",
log4cpp::Priority::NOTICE),
31 level_INFO_attr (
"INFO",
log4cpp::Priority::INFO ),
33 level_NOTSET_attr(
"NOTSET",
log4cpp::Priority::NOTSET),
34 setCategoryPriority_mtd(
"setCategoryPriority", &
LoggingService::setCategoryPriority, this),
35 getCategoryPriorityName_mtd(
"getCategoryPriorityName", &
LoggingService::getCategoryPriorityName, this),
36 logCategories_mtd(
"logCategories", &
LoggingService::logCategories, this)
51 this->
provides()->addOperation(
setCategoryPriority_mtd ).doc(
"Set the priority of category to p").arg(
"name",
"Name of the category").arg(
"p",
"Priority to set");
62 log(
Debug) <<
"Configuring LoggingService" << endlog();
75 log(
Error) <<
"Expected Property '" 76 << (*it)->
getName() <<
"' to be of type string." << endlog();
81 std::string levelName = category->
value();
88 boost::algorithm::to_upper(levelName);
96 catch (std::invalid_argument)
99 log(
Error) <<
"Bad level name: " << levelName << endlog();
103 log(
Debug) <<
"Getting category '" << categoryName <<
"'" << endlog();
109 log(
Info) <<
"Category '" << categoryName
110 <<
"' has priority '" << levelName <<
"'" 119 if (appender && (port = appender->
ports()->
getPort(
"LogPort")) )
123 log(
Warning) <<
"Reconfiguring LoggingService '"<<
getName() <<
"': I've removed all existing Appender connections and will now rebuild them."<<endlog();
135 log(
Error) <<
"Expected Property '" 136 << (*it)->
getName() <<
"' to be of type boolean." << endlog();
141 bool additivity = category->
value();
145 log(
Debug) <<
"Getting category '" << categoryName <<
"'" << endlog();
151 log(
Info) <<
"Category '" << categoryName
152 <<
"' has additivity '" << std::string(additivity ?
"on":
"off") <<
"'" 167 log(
Error) <<
"Expected Property '" 168 << (*it)->
getName() <<
"' to be of type string." << endlog();
174 std::string appenderName = association->
value();
182 log(
Error) <<
"Category '" << categoryName <<
"' is not an OCL category: type is '" <<
typeid(p).name() <<
"'" << endlog();
201 std::stringstream str;
202 str <<
"Category '" << categoryName
203 <<
"' has appender '" << appenderName <<
"'" 206 log(
Info) << str.str() << endlog();
212 log(
Error) <<
"Failed to connect port to appender '" << appenderName <<
"'" << endlog();
219 log(
Error) <<
"Failed to find log port in appender" << endlog();
226 log(
Error) <<
"Could not find appender '" << appenderName <<
"'" << endlog();
247 log(
Info) <<
"Category '" << name <<
"' set to priority '" << level <<
"'" << endlog();
249 log(
Error) <<
"Priority value '" << priority <<
"' is not known!" << endlog();
254 log(
Error) <<
"Could not find category '" << name <<
"'" << endlog();
267 log(
Info) <<
"Category '" << name <<
"' has priority '" << rc <<
"'" << endlog();
269 rc =
"UNKNOWN PRIORITY";
270 log(
Error) <<
"Category '" << name <<
"' has unknown priority!" << endlog();
275 rc =
"UNKNOWN CATEGORY";
276 log(
Error) <<
"Could not find category '" << name <<
"'" << endlog();
284 std::vector<log4cpp::Category*>* categories =
287 std::vector<log4cpp::Category*>::iterator iter;
288 log(
Info) <<
"Number categories = " << (int)categories->size() << endlog();
289 for (iter = categories->begin(); iter != categories->end(); ++iter)
291 std::stringstream str;
295 <<
"Category '" << (*iter)->
getName() <<
"', level=" 298 <<
typeid(*iter).name()
299 <<
"', type really is '" 300 << std::string(0 != c ?
"OCL::Category" :
"log4cpp::Category")
301 <<
"', additivity=" << (
const char*)((*iter)->getAdditivity()?
"yes":
"no");
304 str <<
", port=" << (c->
log_port.connected() ?
"connected" :
"not connected");
309 str <<
", parent name='" << p->
getName() <<
"'";
313 str <<
", No parent";
316 log(
Info) << str.str() << endlog();
RTT::OutputPort< OCL::logging::LoggingEvent > log_port
std::vector< std::string > active_appenders
bool setCategoryPriority(const std::string &name, const int priority)
RTT::Property< RTT::PropertyBag > additivity_prop
Service::shared_ptr provides()
RTT::Attribute< int > level_NOTICE_attr
RTT::Attribute< int > level_WARN_attr
RTT::Attribute< int > level_ERROR_attr
virtual Category * getParent()
RTT::Attribute< int > level_NOTSET_attr
virtual void setAdditivity(bool additivity)
static Category & getInstance(const std::string &name)
ORO_LIST_COMPONENT_TYPE(OCL::logging::LoggingService)
virtual TaskContext * getPeer(const std::string &peer_name) const
RTT::Attribute< int > level_FATAL_attr
RTT::Attribute< int > level_ALERT_attr
virtual bool configureHook()
RTT::Attribute< int > level_EMERG_attr
RTT::Operation< std::string(std::string)> getCategoryPriorityName_mtd
virtual void disconnect()=0
virtual ~LoggingService()
DataFlowInterface * ports()
static const char * categoryName
Property< T > & addProperty(const std::string &name, T &attr)
base::PortInterface * getPort(const std::string &name) const
virtual const std::string & getName() const
RTT::Attribute< int > level_DEBUG_attr
static ConnPolicy buffer(int size, int lock_policy=LOCK_FREE, bool init_connection=false, bool pull=false)
virtual Priority::Value getPriority() const
virtual void setPriority(Priority::Value priority)
Properties & getProperties()
Properties::const_iterator const_iterator
static const int LOCK_FREE
static std::vector< Category * > * getCurrentCategories()
RTT::Attribute< int > level_CRIT_attr
PropertyBag * properties()
static Category * exists(const std::string &name)
virtual bool connectTo(PortInterface *other, ConnPolicy const &policy)=0
RTT::Operation< bool(std::string, int)> setCategoryPriority_mtd
const std::string & getName() const
std::string getCategoryPriorityName(const std::string &name)
RTT::Attribute< int > level_INFO_attr
RTT::Property< RTT::PropertyBag > appenders_prop
RTT::Property< RTT::PropertyBag > levels_prop
static const std::string & getPriorityName(int priority)
ORO_CREATE_COMPONENT_TYPE()
RTT::Operation< void(void)> logCategories_mtd
static Value getPriorityValue(const std::string &priorityName)
virtual const std::string & getName() const