15#ifndef FASTDDS_DDS_LOG__LOG_HPP
16#define FASTDDS_DDS_LOG__LOG_HPP
21#include <fastdds/rtps/attributes/ThreadSettings.hpp>
22#include <fastdds/fastdds_dll.hpp>
41#define EPROSIMA_LOG_INFO(cat, msg) EPROSIMA_LOG_INFO_IMPL_(cat, msg)
43#define EPROSIMA_LOG_WARNING(cat, msg) EPROSIMA_LOG_WARNING_IMPL_(cat, msg)
45#define EPROSIMA_LOG_ERROR(cat, msg) EPROSIMA_LOG_ERROR_IMPL_(cat, msg)
47#if ENABLE_OLD_LOG_MACROS_
52#define logInfo(cat, msg) logInfo_(cat, msg)
54#define logWarning(cat, msg) logWarning_(cat, msg)
56#define logError(cat, msg) logError_(cat, msg)
59#define logInfo_(cat, msg) EPROSIMA_LOG_INFO_IMPL_(cat, msg);
60#define logWarning_(cat, msg) EPROSIMA_LOG_WARNING_IMPL_(cat, msg);
61#define logError_(cat, msg) EPROSIMA_LOG_ERROR_IMPL_(cat, msg);
102 std::unique_ptr<LogConsumer>&& consumer);
154 FASTDDS_EXPORTED_API
static void Reset();
157 FASTDDS_EXPORTED_API
static void Flush();
190 const std::string& message,
197 std::ostream& output,
214 output <<
"Invalid Verbosity Kind.";
236 std::ostream& stream,
241 std::ostream& stream,
246 std::ostream& stream,
251 std::ostream& stream,
256 std::ostream& stream,
261#define __func__ __FUNCTION__
288#if !HAVE_LOG_NO_ERROR
290#define EPROSIMA_LOG_ERROR_IMPL_(cat, msg) \
292 std::stringstream fastdds_log_ss_tmp__; \
293 fastdds_log_ss_tmp__ << msg; \
294 eprosima::fastdds::dds::Log::QueueLog( \
295 fastdds_log_ss_tmp__.str(), eprosima::fastdds::dds::Log::Context{__FILE__, __LINE__, __func__, #cat}, \
296 eprosima::fastdds::dds::Log::Kind::Error); \
299#elif (__INTERNALDEBUG || _INTERNALDEBUG)
301#define EPROSIMA_LOG_ERROR_IMPL_(cat, msg) \
303 auto fastdds_log_lambda_tmp__ = [&]() \
305 std::stringstream fastdds_log_ss_tmp__; \
306 fastdds_log_ss_tmp__ << msg; \
308 (void)fastdds_log_lambda_tmp__; \
312#define EPROSIMA_LOG_ERROR_IMPL_(cat, msg)
319#if !HAVE_LOG_NO_WARNING
321#define EPROSIMA_LOG_WARNING_IMPL_(cat, msg) \
323 if (eprosima::fastdds::dds::Log::GetVerbosity() >= eprosima::fastdds::dds::Log::Kind::Warning) \
325 std::stringstream fastdds_log_ss_tmp__; \
326 fastdds_log_ss_tmp__ << msg; \
327 eprosima::fastdds::dds::Log::QueueLog( \
328 fastdds_log_ss_tmp__.str(), eprosima::fastdds::dds::Log::Context{__FILE__, __LINE__, __func__, #cat}, \
329 eprosima::fastdds::dds::Log::Kind::Warning); \
333#elif (__INTERNALDEBUG || _INTERNALDEBUG)
335#define EPROSIMA_LOG_WARNING_IMPL_(cat, msg) \
337 auto fastdds_log_lambda_tmp__ = [&]() \
339 std::stringstream fastdds_log_ss_tmp__; \
340 fastdds_log_ss_tmp__ << msg; \
342 (void)fastdds_log_lambda_tmp__; \
347#define EPROSIMA_LOG_WARNING_IMPL_(cat, msg)
355#if !HAVE_LOG_NO_INFO && \
356 (defined(FASTDDS_ENFORCE_LOG_INFO) || \
357 ((defined(__INTERNALDEBUG) || defined(_INTERNALDEBUG)) && (defined(_DEBUG) || defined(__DEBUG) || \
360#define EPROSIMA_LOG_INFO_IMPL_(cat, msg) \
362 if (eprosima::fastdds::dds::Log::GetVerbosity() >= eprosima::fastdds::dds::Log::Kind::Info) \
364 std::stringstream fastdds_log_ss_tmp__; \
365 fastdds_log_ss_tmp__ << msg; \
366 eprosima::fastdds::dds::Log::QueueLog( \
367 fastdds_log_ss_tmp__.str(), eprosima::fastdds::dds::Log::Context{__FILE__, __LINE__, __func__, #cat}, \
368 eprosima::fastdds::dds::Log::Kind::Info); \
372#elif (__INTERNALDEBUG || _INTERNALDEBUG)
374#define EPROSIMA_LOG_INFO_IMPL_(cat, msg) \
376 auto fastdds_log_lambda_tmp__ = [&]() \
378 std::stringstream fastdds_log_ss_tmp__; \
379 fastdds_log_ss_tmp__ << msg; \
381 (void)fastdds_log_lambda_tmp__; \
386#define EPROSIMA_LOG_INFO_IMPL_(cat, msg)
Consumes a log entry to output it somewhere.
Definition Log.hpp:225
FASTDDS_EXPORTED_API void print_context(std::ostream &stream, const Log::Entry &, bool color) const
FASTDDS_EXPORTED_API void print_timestamp(std::ostream &stream, const Log::Entry &, bool color) const
FASTDDS_EXPORTED_API void print_message(std::ostream &stream, const Log::Entry &, bool color) const
virtual ~LogConsumer()=default
FASTDDS_EXPORTED_API void print_header(std::ostream &stream, const Log::Entry &, bool color) const
virtual void Consume(const Log::Entry &)=0
FASTDDS_EXPORTED_API void print_new_line(std::ostream &stream, bool color) const
Logging utilities.
Definition Log.hpp:80
static FASTDDS_EXPORTED_API void SetCategoryFilter(const std::regex &)
Sets a filter that will pattern-match against log categories, dropping any unmatched categories.
static FASTDDS_EXPORTED_API void Reset()
Returns the logging engine to configuration defaults.
static FASTDDS_EXPORTED_API std::regex GetCategoryFilter()
Returns a copy of the current category filter or an empty object otherwise.
static FASTDDS_EXPORTED_API void RegisterConsumer(std::unique_ptr< LogConsumer > &&consumer)
Registers an user defined consumer to route log output.
static FASTDDS_EXPORTED_API void ClearConsumers()
Removes all registered consumers, including the default stdout.
static FASTDDS_EXPORTED_API void SetErrorStringFilter(const std::regex &)
Sets a filter that will pattern-match against the provided error string, dropping any unmatched categ...
static FASTDDS_EXPORTED_API void SetVerbosity(Log::Kind)
Sets the verbosity level, allowing for messages equal or under that priority to be logged.
static FASTDDS_EXPORTED_API Log::Kind GetVerbosity()
Returns the current verbosity level.
static FASTDDS_EXPORTED_API void SetThreadConfig(const rtps::ThreadSettings &)
Sets thread configuration for the logging thread.
static FASTDDS_EXPORTED_API void SetFilenameFilter(const std::regex &)
Sets a filter that will pattern-match against filenames, dropping any unmatched categories.
static FASTDDS_EXPORTED_API void QueueLog(const std::string &message, const Log::Context &, Log::Kind)
Not recommended to call this method directly! Use the following macros:
static FASTDDS_EXPORTED_API void ReportFunctions(bool)
Enables the reporting of function names in log entries. Enabled by default when supported.
static FASTDDS_EXPORTED_API void KillThread()
Stops the logging thread. It will re-launch on the next call to a successful log macro.
static FASTDDS_EXPORTED_API void ReportFilenames(bool)
Enables the reporting of filenames in log entries. Disabled by default.
Kind
Types of log entry.
Definition Log.hpp:90
@ Info
Definition Log.hpp:93
@ Warning
Definition Log.hpp:92
@ Error
Definition Log.hpp:91
static FASTDDS_EXPORTED_API void Flush()
Waits until all info logged up to the call time is consumed.
static FASTDDS_EXPORTED_API std::regex GetFilenameFilter()
Returns a copy of the current filename filter or an empty object otherwise.
static FASTDDS_EXPORTED_API bool HasCategoryFilter()
Returns whether a category filter was set or not.
static FASTDDS_EXPORTED_API std::regex GetErrorStringFilter()
Returns a copy of the current error string filter or an empty object otherwise.
static FASTDDS_EXPORTED_API void UnsetCategoryFilter()
Unset the category filter.
Definition DomainParticipant.hpp:45
std::ostream & operator<<(std::ostream &output, const Time_t &t)
Definition Time_t.hpp:261
const char * category
Definition Log.hpp:170
int line
Definition Log.hpp:168
const char * filename
Definition Log.hpp:167
const char * function
Definition Log.hpp:169
std::string message
Definition Log.hpp:175
std::string timestamp
Definition Log.hpp:178
Log::Kind kind
Definition Log.hpp:177
Log::Context context
Definition Log.hpp:176
Struct ThreadSettings to specify various thread settings.
Definition ThreadSettings.hpp:37