text_logging.h File Reference

This is the entry point for all text logging within Drake. More...

#include <memory>
#include <fmt/format.h>
#include <fmt/ostream.h>
#include "drake/common/drake_copyable.h"
Include dependency graph for text_logging.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


class  logger
 A stubbed-out version of spdlog::logger. More...




#define SPDLOG_TRACE(logger, ...)
#define SPDLOG_DEBUG(logger, ...)
#define DRAKE_SPDLOG_TRACE(logger, ...)
#define DRAKE_SPDLOG_DEBUG(logger, ...)


logging::logger * log ()
 Retrieve an instance of a logger to use for logging; for example: drake::log()->info("potato!") More...

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:

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

Similarly, it provides:


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):

  SPDLOG_TRACE(drake::log(), "message: {}", something_conditionally_compiled);
  SPDLOG_DEBUG(drake::log(), "message: {}", something_conditionally_compiled);

Note that if you are running with NDEBUG undefined, so that these two macros are expanded, the arguments will be evaluated even if logging is disabled. If you want to avoid that cost, Drake provides macros that provide the same functionality but won't evaluate the arguments unless they are actually going to be logged:

                     "message: {}", something_conditionally_compiled);
                     "message: {}", something_conditionally_compiled);

We suggest using the Drake versions of these macros everywhere so that you don't have to decide when the argument-evaluation cost is going to be excessive.

The format string syntax is fmtlib; see http://fmtlib.net/3.0.0/syntax.html. In particular, any class that overloads operator<< for ostream can be printed without any special handling.

Macro Definition Documentation

#define DRAKE_SPDLOG_DEBUG (   logger,
#define DRAKE_SPDLOG_TRACE (   logger,
#define SPDLOG_DEBUG (   logger,
#define SPDLOG_TRACE (   logger,