maliput
text_logging.h File Reference

Detailed Description

This is the entry point for all text logging within Drake. Once you've included this file, the suggested ways you should write log messages include:

  maliput::drake::log()->trace("Some trace message: {} {}", something, some_other);

Similarly, it provides:

  maliput::drake::log()->debug(...);
  maliput::drake::log()->info(...);
  maliput::drake::log()->warn(...);
  maliput::drake::log()->error(...);
  maliput::drake::log()->critical(...);

If you want to log objects that are expensive to serialize, these macros will not be compiled if debugging is turned off (-DNDEBUG is set):

  DRAKE_LOGGER_TRACE("message: {}", something_conditionally_compiled);
  DRAKE_LOGGER_DEBUG("message: {}", something_conditionally_compiled);

The format string syntax is fmtlib; see https://fmt.dev/latest/syntax.html. In particular, any class that overloads operator<< for ostream can be printed without any special handling. (Note that the documentation link provides syntax for the latest version of fmtlib; the version of fmtlib used by Drake might be older.)

#include <string>
#include <spdlog/spdlog.h>
#include <spdlog/fmt/ostr.h>
#include "maliput/drake/common/drake_copyable.h"
Include dependency graph for text_logging.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  Warn
 When constructed, logs a message (at "warn" severity); the destructor is guaranteed to be trivial. More...
 

Namespaces

 maliput
 Code in this file is inspired by: https://github.com/RobotLocomotion/drake/blob/master/common/text_logging.h.
 
 maliput::drake
 
 maliput::drake::logging
 

Macros

#define SPDLOG_ACTIVE_LEVEL   SPDLOG_LEVEL_TRACE
 
#define DRAKE_LOGGER_TRACE(...)
 
#define DRAKE_LOGGER_DEBUG(...)
 

Typedefs

using logger = spdlog::logger
 The maliput::drake::logging::logger class provides text logging methods. More...
 

Functions

logging::logger * log ()
 Retrieve an instance of a logger to use for logging; for example: More...
 
sink * get_dist_sink ()
 (Advanced) Retrieves the default sink for all Drake logs. More...
 
std::string set_log_level (const std::string &level)
 Invokes drake::log()->set_level(level). More...
 
void set_log_pattern (const std::string &pattern)
 Invokes drake::log()->set_pattern(pattern). More...
 

Variables

constexpr bool kHaveSpdlog = true
 True only if spdlog is enabled in this build. More...
 
const char *const kSetLogLevelUnchanged = "unchanged"
 The "unchanged" string to pass to set_log_level() so as to achieve a no-op. More...
 
const char *const kSetLogLevelHelpMessage
 An end-user help string suitable to describe the effects of set_log_level(). More...
 
const char *const kSetLogPatternHelpMessage
 An end-user help string suitable to describe the effects of set_log_pattern(). More...
 

Macro Definition Documentation

◆ DRAKE_LOGGER_DEBUG

#define DRAKE_LOGGER_DEBUG (   ...)
Value:
do { \
/* Capture the maliput::drake::log() in a temporary, using a relatively unique */ \
/* variable name to avoid potential variable name shadowing warnings. */ \
::maliput::drake::logging::logger* const drake_spdlog_macro_logger_alias = ::maliput::drake::log(); \
if (drake_spdlog_macro_logger_alias->level() <= spdlog::level::debug) { \
SPDLOG_LOGGER_DEBUG(drake_spdlog_macro_logger_alias, __VA_ARGS__); \
} \
} while (0)

◆ DRAKE_LOGGER_TRACE

#define DRAKE_LOGGER_TRACE (   ...)
Value:
do { \
/* Capture the maliput::drake::log() in a temporary, using a relatively unique */ \
/* variable name to avoid potential variable name shadowing warnings. */ \
::maliput::drake::logging::logger* const drake_spdlog_macro_logger_alias = ::maliput::drake::log(); \
if (drake_spdlog_macro_logger_alias->level() <= spdlog::level::trace) { \
SPDLOG_LOGGER_TRACE(drake_spdlog_macro_logger_alias, __VA_ARGS__); \
} \
} while (0)

◆ SPDLOG_ACTIVE_LEVEL

#define SPDLOG_ACTIVE_LEVEL   SPDLOG_LEVEL_TRACE
maliput::common::logger::trace
@ trace
Definition: logger.h:79
maliput::log
common::Logger * log()
Definition: logger.cc:111
maliput::drake::logging::logger
spdlog::logger logger
The maliput::drake::logging::logger class provides text logging methods.
Definition: text_logging.h:94
maliput::common::logger::debug
@ debug
Definition: logger.h:80