Skip to main content

LoggerBase Class

Base class to allow Behaviors to report messages with detailed explanations to MoveIt Studio UI. More...

Declaration

class moveit_pro::behavior::LoggerBase { ... }

Included Headers

#include <logger.hpp>

Derived Classes

classLoggerROS

A ROS-specialized implementation of LoggerBase that publishes the error message on a topic and logs it through an rclcpp Logger. More...

Public Member Typedefs Index

usingLogFilter = std::function< LogFilterAction(int32_t, const std::string &)>

A filter invoked for every message published through this logger. More...

Enumerations Index

enum classLogFilterAction { ... }

Action a LogFilter returns to tell the logger how to handle a message. More...

Public Destructor Index

~LoggerBase ()=default

Public Member Functions Index

voidpublishFailureMessage (const std::string &error_source_name, const std::string &details="")

Helper function that wraps publishMessage with a preset ERROR log level. More...

voidpublishWarnMessage (const std::string &source_name, const std::string &details="")

Helper function that wraps publishMessage with a preset WARN log level. More...

voidpublishInfoMessage (const std::string &source_name, const std::string &details="")

Helper function that wraps publishMessage with a preset INFO log level. More...

voidpublishDebugMessage (const std::string &source_name, const std::string &details="")

Helper function that wraps publishMessage with a preset DEBUG log level. More...

voidpublishMessage (const int32_t log_level, const std::string &source_name, const std::string &details)

Function to publish a message. More...

std::stringconsumeErrorLogBuffer ()

Helper function to get the error log buffer. More...

std::shared_ptr< void >pushFilter (LogFilter filter)

Push a filter onto the active filter stack. More...

voidpublishMessage (const int32_t log_level, const std::string &details)

Function to publish a message. The default implementation logs to spdlog. LoggerROS is a good example of a subclass that overrides this, in which it publishes the message to a ROS topic and also calls this superclass function to also log to console. More...

Private Member Functions Index

LogFilterActionapplyFilters (const int32_t log_level, const std::string &details) const

Apply the top-of-stack filter (if any) to a message. More...

Private Member Attributes Index

std::vector< std::string >error_log_buffer_

Buffer for collecting logs. Guarded by error_log_buffer_mutex_ because messages may be appended from Behavior background threads (e.g. AsyncBehaviorBase) while the Objective end-handler drains it. More...

std::mutexerror_log_buffer_mutex_

Mutex guarding error_log_buffer_. More...

std::shared_ptr< FilterStack >filter_stack_ = std::make_shared<FilterStack>()

Shared filter-stack state; see FilterStack. Never null — created once and outlives any token only through that token's weak_ptr. More...

Description

Base class to allow Behaviors to report messages with detailed explanations to MoveIt Studio UI.

Definition at line 27 of file logger.hpp.

Public Member Typedefs

LogFilter

using moveit_pro::behavior::LoggerBase::LogFilter = std::function<LogFilterAction(int32_t , const std::string& )>

A filter invoked for every message published through this logger.

Parameters
log_level

The severity of the message (moveit_studio_agent_msgs::msg::Log::ERROR/WARN/INFO/DEBUG).

details

The fully-formatted message text (including the source name and level string).

Returns

Forward to publish the message normally, or Drop to suppress it entirely.

Definition at line 94 of file logger.hpp.

Enumerations

LogFilterAction

enum class moveit_pro::behavior::LoggerBase::LogFilterAction
strong

Action a LogFilter returns to tell the logger how to handle a message.

Enumeration values
Forward
Drop

The filter is consulted on the public publishMessage funnel, before the message is dispatched to the virtual publish path. Drop suppresses the message entirely (no console, no error buffer, no ROS topic, and so no UI toast); Forward leaves the message untouched and publishes it as if no filter were installed.

Definition at line 82 of file logger.hpp.

Public Destructor

~LoggerBase()

virtual moveit_pro::behavior::LoggerBase::~LoggerBase ()
virtual default

Definition at line 30 of file logger.hpp.

Public Member Functions

consumeErrorLogBuffer()

std::string moveit_pro::behavior::LoggerBase::consumeErrorLogBuffer ()
virtual

Helper function to get the error log buffer.

Returns

A string containing all the error logs in the buffer, separated by new lines

info

This function clears out the logs once retrieved

Declaration at line 74 of file logger.hpp, definition at line 172 of file logger.cpp.

publishDebugMessage()

void moveit_pro::behavior::LoggerBase::publishDebugMessage (const std::string & source_name, const std::string & details="")

Helper function that wraps publishMessage with a preset DEBUG log level.

Parameters
source_name

Name used to identify the source of the debug message.

details

A detailed debug message.

Declaration at line 59 of file logger.hpp, definition at line 67 of file logger.cpp.

publishFailureMessage()

void moveit_pro::behavior::LoggerBase::publishFailureMessage (const std::string & error_source_name, const std::string & details="")

Helper function that wraps publishMessage with a preset ERROR log level.

Parameters
error_source_name

Name used to identify the source of the failure.

details

A detailed message describing the failure. For example, the contents of an exception's message.

Declaration at line 38 of file logger.hpp, definition at line 52 of file logger.cpp.

publishInfoMessage()

void moveit_pro::behavior::LoggerBase::publishInfoMessage (const std::string & source_name, const std::string & details="")

Helper function that wraps publishMessage with a preset INFO log level.

Parameters
source_name

Name used to identify the source of the info.

details

A detailed message describing the information.

Declaration at line 52 of file logger.hpp, definition at line 62 of file logger.cpp.

publishMessage()

void moveit_pro::behavior::LoggerBase::publishMessage (const int32_t log_level, const std::string & source_name, const std::string & details)

Function to publish a message.

Parameters
log_level

moveit_studio_agent_msgs::msg::Log::ERROR/WARN/INFO/DEBUG

source_name

Name used to identify the source of the log.

details

Contains the information message

Declaration at line 67 of file logger.hpp, definition at line 72 of file logger.cpp.

publishMessage()

void moveit_pro::behavior::LoggerBase::publishMessage (const int32_t log_level, const std::string & details)
virtual

Function to publish a message. The default implementation logs to spdlog. LoggerROS is a good example of a subclass that overrides this, in which it publishes the message to a ROS topic and also calls this superclass function to also log to console.

Parameters
log_level

moveit_studio_agent_msgs::msg::Log::ERROR/WARN/INFO/DEBUG

details

Contains the information message

Declaration at line 115 of file logger.hpp, definition at line 136 of file logger.cpp.

publishWarnMessage()

void moveit_pro::behavior::LoggerBase::publishWarnMessage (const std::string & source_name, const std::string & details="")

Helper function that wraps publishMessage with a preset WARN log level.

Parameters
source_name

Name used to identify the source of the warning.

details

A detailed message describing the warning.

Declaration at line 45 of file logger.hpp, definition at line 57 of file logger.cpp.

pushFilter()

std::shared_ptr< void > moveit_pro::behavior::LoggerBase::pushFilter (LogFilter filter)

Push a filter onto the active filter stack.

The returned RAII token pops this filter (under the filter mutex) when it is destroyed. Only the top (most recently pushed) filter is consulted per message — there is no fallthrough from a Forward to the filters beneath it; while an inner filter is installed, the outer ones are dormant. In the normal single-filter case this is moot. If filters are nested (e.g. nested SuppressChildErrors decorators), only the innermost filter's decision applies to messages logged while it is on top. Thread-safe.

Parameters
filter

The filter to install. Must not be empty.

Returns

An opaque ownership token. Reset or destroy it to remove the filter.

Declaration at line 106 of file logger.hpp, definition at line 105 of file logger.cpp.

Private Member Functions

applyFilters()

LoggerBase::LogFilterAction moveit_pro::behavior::LoggerBase::applyFilters (const int32_t log_level, const std::string & details)

Apply the top-of-stack filter (if any) to a message.

Copies the top filter out from under the filter-stack mutex and invokes it with the lock released, so a callback that itself logs cannot self-deadlock and there is no lock-order inversion with any mutex the callback takes.

Returns

The filter's action, or Forward when the stack is empty.

Declaration at line 125 of file logger.hpp, definition at line 89 of file logger.cpp.

Private Member Attributes

error_log_buffer_

std::vector<std::string> moveit_pro::behavior::LoggerBase::error_log_buffer_

Buffer for collecting logs. Guarded by error_log_buffer_mutex_ because messages may be appended from Behavior background threads (e.g. AsyncBehaviorBase) while the Objective end-handler drains it.

Definition at line 189 of file logger.hpp.

error_log_buffer_mutex_

std::mutex moveit_pro::behavior::LoggerBase::error_log_buffer_mutex_

Mutex guarding error_log_buffer_.

Definition at line 194 of file logger.hpp.

filter_stack_

std::shared_ptr<FilterStack> moveit_pro::behavior::LoggerBase::filter_stack_ = std::make_shared<FilterStack>()

Shared filter-stack state; see FilterStack. Never null — created once and outlives any token only through that token's weak_ptr.

Definition at line 200 of file logger.hpp.


The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.9.8.