RTI Connext Modern C++ API  Version 7.0.0
rti::config::Logger Class Reference

The singleton type used to configure RTI Connext logging. More...

#include <rti/config/Logger.hpp>

Public Member Functions

Verbosity verbosity ()
 Get the verbosity at which RTI Connext is currently logging diagnostic information. More...
 
Verbosity verbosity_by_category (LogCategory category)
 Get the verbosity at which RTI Connext is currently logging diagnostic information in the given category. More...
 
void verbosity (Verbosity verbosity)
 Set the verbosity at which RTI Connext will log diagnostic information. More...
 
void verbosity_by_category (LogCategory category, Verbosity verbosity)
 Set the verbosity at which RTI Connext will log diagnostic information in the given category. More...
 
FILE * output_file ()
 Get the file to which the logged output is redirected. More...
 
void output_file (FILE *out)
 Set the file to which the logged output is redirected. More...
 
void output_file (const char *file_name)
 Set the name of the file to which the logged output is redirected. More...
 
void output_file_set (const char *file_preffix, const char *file_suffix, int max_bytes, int max_files=dds::core::LENGTH_UNLIMITED)
 Set the name of the file to which the logged output is redirected. More...
 
void output_handler (std::function< void(const LogMessage &)> handler)
 Redirects RTI Connext logging to a function. More...
 
void reset_output_handler ()
 Resets a previously set output handler. More...
 
PrintFormat print_format ()
 Get the current message format for the log level LogLevel::EXCEPTION. More...
 
void print_format (PrintFormat print_format)
 Set the message format that RTI Connext will use to log diagnostic information for all the log levels, except for LogLevel::FATAL_ERROR. When the Activity Context is printed, the user can select the information that will be part of the Activity Context by using the API rti::config::activity_context::set_attribute_mask. More...
 
PrintFormat print_format_by_log_level (LogLevel log_level)
 Get the current message format, by log level, that RTI Connext is using to log diagnostic information. More...
 
void print_format_by_log_level (PrintFormat print_format, LogLevel log_level)
 Set the message format, by log level, that RTI Connext will use to log diagnostic information. When the Activity Context is printed, the user can select the information that will be part of the Activity Context by using the API rti::config::activity_context::set_attribute_mask. More...
 

Static Public Member Functions

static Loggerinstance ()
 Get the singleton instance of this type. More...
 

Detailed Description

The singleton type used to configure RTI Connext logging.

Member Function Documentation

◆ instance()

static Logger& rti::config::Logger::instance ( )
inlinestatic

◆ verbosity() [1/2]

Verbosity rti::config::Logger::verbosity ( )

Get the verbosity at which RTI Connext is currently logging diagnostic information.

The default verbosity if rti::config::Logger::verbosity is never called is rti::core::LogVerbosity::EXCEPTION.

If rti::config::Logger::verbosity_by_category has been used to set different verbosities for different categories of messages, this method will return the maximum verbosity of all categories.

Examples:
Foo_publisher.cxx, and Foo_subscriber.cxx.

Referenced by rti::config::ScopedLoggerVerbosity::ScopedLoggerVerbosity(), and rti::config::ScopedLoggerVerbosity::~ScopedLoggerVerbosity().

◆ verbosity_by_category() [1/2]

Verbosity rti::config::Logger::verbosity_by_category ( LogCategory  category)

Get the verbosity at which RTI Connext is currently logging diagnostic information in the given category.

The default verbosity if rti::config::Logger::verbosity and rti::config::Logger::verbosity_by_category are never called is rti::core::LogVerbosity::EXCEPTION.

◆ verbosity() [2/2]

void rti::config::Logger::verbosity ( Verbosity  verbosity)

Set the verbosity at which RTI Connext will log diagnostic information.

Note: Logging at high verbosities will be detrimental to your application's performance. Your default setting should typically remain at rti::core::LogVerbosity::WARNING or below. (The default verbosity if you never set it is rti::core::LogVerbosity::EXCEPTION.)

◆ verbosity_by_category() [2/2]

void rti::config::Logger::verbosity_by_category ( LogCategory  category,
Verbosity  verbosity 
)

Set the verbosity at which RTI Connext will log diagnostic information in the given category.

◆ output_file() [1/3]

FILE* rti::config::Logger::output_file ( )

Get the file to which the logged output is redirected.

If no output file has been registered through rti::config::Logger::set_output_file, this method will return NULL. In this case, logged output will on most platforms go to standard out as if through printf.

◆ output_file() [2/3]

void rti::config::Logger::output_file ( FILE *  out)

Set the file to which the logged output is redirected.

The file passed may be NULL, in which case further logged output will be redirected to the platform-specific default output location (standard out on most platforms).

For better performance when log messages are generated frequently, the log messages are not flushed into a file immediately after they are generated. In other words, while writing a log message, RTI Connext only calls the function fwrite() (see https://pubs.opengroup.org/onlinepubs/009695399/functions/fwrite.html); it does not call the function fflush() (see https://pubs.opengroup.org/onlinepubs/009695399/functions/fflush.html). If your application requires a different flushing behavior, you may use rti::config::Logger::set_output_device to configure a custom logging device.

◆ output_file() [3/3]

void rti::config::Logger::output_file ( const char *  file_name)

Set the name of the file to which the logged output is redirected.

The name may be NULL, in which case further logged output will be redirected to the platform-specific default output location (standard out on most platforms).

See rti::config::Logger::set_output_file for the flushing behavior.

◆ output_file_set()

void rti::config::Logger::output_file_set ( const char *  file_preffix,
const char *  file_suffix,
int  max_bytes,
int  max_files = dds::core::LENGTH_UNLIMITED 
)

Set the name of the file to which the logged output is redirected.

The name may be NULL, in which case further logged output will be redirected to the platform-specific default output location (standard out on most platforms).

See rti::config::Logger::set_output_file for the flushing behavior.

◆ output_handler()

void rti::config::Logger::output_handler ( std::function< void(const LogMessage &)>  handler)
inline

Redirects RTI Connext logging to a function.

When a handler is set, log messages stop being directed to the standard output and are passed to the handler.

To direct logging back to the standard output, use reset_output_handler().

Parameters
handlerA function or function object capable of receiving a const LogMessage& argument, the log message.

The following example sets a handler that saves all log messages in a vector:

std::vector<std::string> saved_logs;
Logger::instance().output_handler([&saved_logs](const LogMessage& message) {
saved_logs.push_back(message.text); // message is copied as a std::string
});

The char * in the LogMessage is only valid within the callback.

◆ reset_output_handler()

void rti::config::Logger::reset_output_handler ( )
inline

Resets a previously set output handler.

Directs RTI Connext logging back to the standard output.

References rti::config::LogMessage::is_security_message, rti::config::LogMessage::level, rti::config::LogMessage::message_id, and rti::config::LogMessage::text.

◆ print_format() [1/2]

PrintFormat rti::config::Logger::print_format ( )

Get the current message format for the log level LogLevel::EXCEPTION.

Use rti::config::Logger::get_print_format_by_log_level to retrieve the format for other log levels.

If rti::config::Logger::set_print_format is never called, the default format is PrintFormat::DEFAULT.

◆ print_format() [2/2]

void rti::config::Logger::print_format ( PrintFormat  print_format)

Set the message format that RTI Connext will use to log diagnostic information for all the log levels, except for LogLevel::FATAL_ERROR. When the Activity Context is printed, the user can select the information that will be part of the Activity Context by using the API rti::config::activity_context::set_attribute_mask.

◆ print_format_by_log_level() [1/2]

PrintFormat rti::config::Logger::print_format_by_log_level ( LogLevel  log_level)

Get the current message format, by log level, that RTI Connext is using to log diagnostic information.

If rti::config::Logger::set_print_format is never called, the default format is PrintFormat::DEFAULT.

◆ print_format_by_log_level() [2/2]

void rti::config::Logger::print_format_by_log_level ( PrintFormat  print_format,
LogLevel  log_level 
)

Set the message format, by log level, that RTI Connext will use to log diagnostic information. When the Activity Context is printed, the user can select the information that will be part of the Activity Context by using the API rti::config::activity_context::set_attribute_mask.