Great and Powerfull Logger is part of Sweetie Bot project. It is meant as drop in replacment for RTT::Logger.
Native OROCOS logging system suffers a few drawbacks:
-
RTT::Logger
does not support categories and individual log levels for components. Also it is not real-time. -
OCL::logging::Category
provides real-time logging service, but suffers from not very convinent syntax for<<
operator:log->getRTStream(log4cpp::ERROR) <<
Moreover it creates temporary
ostringstream
anygetRTStream
call. -
log4cpp::Category
is not realtime, deployer does not supportlog4cpp
out of box (recompiling is needed). -
All logging systems lack ROS integration.
Great and Powerfull Loger is hear to fix thoese deficiencies! It has many tricks under its mantle.
-
log4cpp::RosAppender
islog4cpp
appender which forward messages to\rosout
ROS topic. -
RosAppenderService
(rosout
service) is able to forward givenlog4cpp
category to\rosut
(useaddCategory
operation). -
Log4cppService
(log4cpp
service) allows to initializelog4cpp
using configuration file. -
OCL::logging::RosAppender
component forwards log fromOCL::logging
category to\rosut
(useOCL::logging::LoggerService
to setup connection). -
Logger interface includes:
-
LoggerLog4Cpp
logs directly to specifiedlog4cpp
category. -
LoggerOCL
logs toOCL
category. -
LoggerRos
directry logs to\rosout
, for log priority assigment may useOCL
orlog4cpp
categories. -
LoggerRTT
uses RTT::Logger to display messages. Loggers do not rely on dynamic memory allocation and useRTT::Loger
style syntax:using sweetie_bot::Logger; sweetie_bot::LoggerLog4Cpp log("robot.component");
log(Logger::INFO) << "I'm GREAT and POWERFULL LOGEER!" << Logger::endl;
Great and Powerfull Logger creates unexisting categories (despite generosity is clearly not its element). But you should set log levels via
log4cpp
configuration file or usingocl::logging::LoggerService
component. By default log levels areUNSET
so no messages are shown.Log is flushed by
Logger::endl
manipulator,RTT::Logger
maipulators are also supported. SeeLoggerTest
for example. -
Your should select the logger facility and declare log4cpp
categories.
Your should configure loglevels using log4cpp configuration file or OCL LoggerService cpf file.
See scripts/logger.log4cpp
and scripts/logger.cpf
for example.
This files contains log levels for hierarchical tree of categories see log4cpp documentation for more details.
Then there are three ways to provide deployer with this information:
- Use
--rtt-log4cpp-config-file
option ofdeployer
on startup. (Deployer must be compiled with log4cpp support). - Use
log4cpp
service to load.log4cpp
file (seescripts/test_logger.ops
andscripts/test_logger_log4cpp.lua
). - Use
marshalling
service to load.cpf
file inOCL::LoggerService
component.
Basic deployment code looks like:
loadService("Deployer", "log4cpp");
log4cpp.configure("logger.log4cpp");
or in lua (see scripts/logger.lua
helper module and scripts/test_logger_log4cpp.lua
for details):
dofile(rttros.find_rospack("sweetie_bot_logger") .. "logger.lua")
logger.init_loglevels_log4cpp("logging.log4cpp")
Use log4cpp
configuration file to declare loglevels and appenders. See log4cpp documentation for details.
Example configuration may be found in scripts/logger_log4cpp.log4cpp
.
Also you may add RosAppender
to any category to redirect messages to /rosout
.
log4cpp.addRosAppender("<category_name>", 20);
Use OCL logging infrastructure deployment procedure as described in OROCOS documentation.
See scripts/test_logger_ocl.ops
as example.
If deployer is compiled with log4cpp support you can redirect RTT::Logger
category org.orocos.rtt
to \rosout
:
log4cpp.addRosAppender("org.orocos.rtt", 20);
But during shutdown deadlock occurs due to logging attempt using appender being destructed.
Currently this bug is fixed by assert
. Also you can call log4cpp.shutdown
explicitly to prevent deadlock.
LOGGER_SCRIPTS=`rospack find sweetie_bot_logger`/scripts
deployer -s $LOGGER_SCRIPTS/test_logger.ops
deployer -s $LOGGER_SCRIPTS/test_logger_log4cpp.ops
rttlua -i $LOGGER_SCRIPTS/test_logger_log4cpp.lua
deployer -s $LOGGER_SCRIPTS/test_logger_ocl.ops
LoggerRosut
usesMutex
to prevent concurrent write.- If output port of
log4cpp:::RosAppender
is connected during object destruction Ursa Major is being summomed (deadlock happens). It is caused by attempt to log via appender being destructed. Currently bug is amended withassert
but alsolog4cpp.shutdown
just before exit. - It seems
\rosout
is unable to process connection requests fast enoughs. First bunch of messages from LoggerTest is missing on\rosout
. Just call sleep.