elsa logging

Table of Contents


class elsa::Logger

Logging class for elsa purposes (wrapper around spdlog).

This class provides logging for the elsa library. It is a thin wrapper around the spdlog third party library, using the single-threaded versions of the sinks.


Maximilian Hornung - initial version


Tobias Lasser - rewrite

Logger::get(“name”) requests a logger (from spdlog) corresponding to “name”, which is used just as you would use spdlog directly, i.e. you can use the info(), debug(), warn() etc. routines. For more details on spdlog, please visit https://github.com/gabime/spdlog.

By default, Logger enables console logging. If requested, file logging can enabled in addition via addFileSink. Log levels are set via setLevel (again, they correspond to the spdlog log levels).

Public Types

enum LogLevel

available log levels (default: INFO), corresponding to those of spdlog


enumerator TRACE
enumerator DEBUG
enumerator INFO
enumerator WARN
enumerator ERR
enumerator CRITICAL
enumerator OFF

Public Static Functions

std::shared_ptr<spdlog::logger> get(std::string name)

return a logger corresponding to “name” (if not existing, it is created)

void setLevel(LogLevel level)

set the log level for all loggers

void enableFileLogging(std::string filename)

enable file logging

void flush()

flush all loggers

Private Members

LogLevel _level = {LogLevel::INFO}

the log level

std::unique_ptr<std::string> _fileName = {}

the file name for file logging (if enabled)

std::map<std::string, std::shared_ptr<spdlog::logger>> _loggers

map storing the loggers identified by a string

Private Static Functions

Logger &getInstance()

returns the singleton instance of Logger

spdlog::level::level_enum convertLevelToSpdlog(LogLevel level)

convert elsa LogLevel to spdlog::level::level_enum


friend class LogGuard


class elsa::LogGuard

simple log guard class, logs a message each on creation and destruction.

This class serves as a guard for logging, simple instantiation will log a starting message, while going out of scope logs an ending message.


Matthias Wieczorek - initial code


Maximilian Hornung - modularization


Tobias Lasser - minor modifications

Public Functions

LogGuard(std::string loggerName, std::string message, Logger::LogLevel level = Logger::LogLevel::INFO)

constructor taking the name of the logger to log to, the message and the log level of the message


destructor outputting the final log message

Private Members

std::string _message

the name of the logger to log to

Logger::LogLevel _level

the message to log


template<class Duration = std::chrono::milliseconds, class Clock = std::chrono::steady_clock>
class elsa::Timer

Timer class to provide easy logging of timing.

This class provides logging of timing using the guard pattern. It stores the current time upon creation, and outputs a log message with time elapsed on destruction.


Matthias Wieczorek - initial code


Maximilian Hornung - modularization


Tobias Lasser - minor changes

Public Functions

Timer(std::string name, std::string message)

start the timer, using loggerName as logger, outputting message at end


stop the timer and actually output the log message

Private Members

std::string _name

the start time on creation

std::string _message

the name of what is running