Utopia  2
Framework for studying models of complex & adaptive systems.
Functions | Variables
Output Logging

Utility functions for all logging output based on the spdlog backend. More...

Collaboration diagram for Output Logging:

Functions

std::shared_ptr< spdlog::logger > Utopia::init_logger (const std::string name, const spdlog::level::level_enum level, const bool throw_on_exist=true)
 Initialize a logger with a certain name and log level. More...
 
void Utopia::setup_loggers (const spdlog::level::level_enum level_core=spdlog::level::warn, const spdlog::level::level_enum level_data_io=spdlog::level::warn, const spdlog::level::level_enum level_data_mngr=spdlog::level::warn, const std::string &log_pattern="")
 Set up and register the global loggers and set the global log pattern. More...
 

Variables

const std::string Utopia::log_core = "core"
 
const std::string Utopia::log_data_io = "data_io"
 
const std::string Utopia::log_data_mngr = "data_mngr"
 

Detailed Description

Utility functions for all logging output based on the spdlog backend.

All output of the simulation backend is intended to be controlled via loggers. Loggers are implemented using spdlog (see https://github.com/gabime/spdlog). Regular output via the standard pipes std::cout and std::cerr is strongly discouraged.

Utopia generates three types of loggers: One logger for Data I/O functions, one for Core (backend) functions, and one for each model instance. The Utopia::Model base class holds a logger instance which should be used for information on the current model. To write log messages from within Data I/O or Core backend functions, the respective logger first has to be retrieved. This is achieved by using spdlog::get (https://github.com/gabime/spdlog/wiki/2.-Creating-loggers). The names for the two loggers are exported within the Utopia namespace. All log levels are handled through the input configuration files.

The Utopia::PseudoParent automatically creates the utility loggers. For executables without Models (like tests), the loggers have to be created explicitly by manually calling Utopia::setup_loggers.

Function Documentation

◆ init_logger()

std::shared_ptr<spdlog::logger> Utopia::init_logger ( const std::string  name,
const spdlog::level::level_enum  level,
const bool  throw_on_exist = true 
)
inline

Initialize a logger with a certain name and log level.

If the logger already exists, issue a warning and only set the log level. Optionally, this function can throw an exception.

Parameters
nameName of the logger. This is also the registered logger name.
levelLevel of the logger. See spdlog::level::level_enum
throw_on_existThrow an exception if the logger exists

◆ setup_loggers()

void Utopia::setup_loggers ( const spdlog::level::level_enum  level_core = spdlog::level::warn,
const spdlog::level::level_enum  level_data_io = spdlog::level::warn,
const spdlog::level::level_enum  level_data_mngr = spdlog::level::warn,
const std::string &  log_pattern = "" 
)
inline

Set up and register the global loggers and set the global log pattern.

Utopia employs the following global loggers:

  • core: for the Core module
  • data_io: for the Data I/O module in general
  • data_mngr: for the DataIO::DataManager

They can be retrieved with the spdlog::get(name) function, where 'name' can be one of the 'log_' strings stored in the Utopia namespace.

This function only (re)sets the log levels if the loggers already exist.

Parameters
level_coreLog level of the core logger
level_data_ioLog level of the data_io logger
level_data_mngrLog level of the data_mngr logger
log_patternThe global log pattern. If empty, a pre-defined log pattern will be set instead of the spdlog default.

Variable Documentation

◆ log_core

const std::string Utopia::log_core = "core"
inline

◆ log_data_io

const std::string Utopia::log_data_io = "data_io"
inline

◆ log_data_mngr

const std::string Utopia::log_data_mngr = "data_mngr"
inline