MoveIt Pro API
Core Behaviors for MoveIt Pro
Loading...
Searching...
No Matches
moveit_pro::behavior::LoggerBase Class Reference

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

#include <logger.hpp>

Inheritance diagram for moveit_pro::behavior::LoggerBase:

Public Types

enum class  LogFilterAction { Forward , Drop }
 Action a LogFilter returns to tell the logger how to handle a message. More...
 
using LogFilter = std::function< LogFilterAction(int32_t, const std::string &)>
 A filter invoked for every message published through this logger.
 

Public Member Functions

virtual ~LoggerBase ()=default
 
void publishFailureMessage (const std::string &error_source_name, const std::string &details="")
 Helper function that wraps publishMessage with a preset ERROR log level.
 
void publishWarnMessage (const std::string &source_name, const std::string &details="")
 Helper function that wraps publishMessage with a preset WARN log level.
 
void publishInfoMessage (const std::string &source_name, const std::string &details="")
 Helper function that wraps publishMessage with a preset INFO log level.
 
void publishMessage (const int32_t log_level, const std::string &source_name, const std::string &details)
 Function to publish a message.
 
virtual std::string consumeErrorLogBuffer ()
 Helper function to get the error log buffer.
 
std::shared_ptr< void > pushFilter (LogFilter filter)
 Push a filter onto the active filter stack.
 

Protected Member Functions

virtual void publishMessage (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.
 

Detailed Description

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

Member Typedef Documentation

◆ 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_levelThe severity of the message (moveit_studio_agent_msgs::msg::Log::ERROR/WARN/INFO).
detailsThe fully-formatted message text (including the source name and level string).
Returns
Forward to publish the message normally, or Drop to suppress it entirely.

Member Enumeration Documentation

◆ LogFilterAction

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

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.

Enumerator
Forward 
Drop 

Constructor & Destructor Documentation

◆ ~LoggerBase()

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

Member Function Documentation

◆ 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
Note
This function clears out the logs once retrieved

◆ 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_nameName used to identify the source of the failure.
detailsA detailed message describing the failure. For example, the contents of an exception's message.

◆ 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_nameName used to identify the source of the info.
detailsA detailed message describing the information.

◆ publishMessage() [1/2]

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

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_levelmoveit_studio_agent_msgs::msg::ERROR/WARN/INFO
detailsContains the information message

Reimplemented in moveit_pro::behavior::LoggerROS, and moveit_pro::behavior::LoggerROS.

◆ publishMessage() [2/2]

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_levelmoveit_studio_agent_msgs::msg::ERROR/WARN/INFO
source_nameName used to identify the source of the log.
detailsContains the information message

◆ 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_nameName used to identify the source of the warning.
detailsA detailed message describing the warning.

◆ 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
filterThe filter to install. Must not be empty.
Returns
An opaque ownership token. Reset or destroy it to remove the filter.

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