API
4.2
For MATLAB, Python, Java, and C++ users
|
This is a singleton class (single instance) for logging messages and controlling how those messages are presented to the user. More...
Public Member Functions | |
Logger ()=delete | |
This is a static singleton class: there is no way of constructing it. More... | |
Static Public Member Functions | |
static void | setLevel (Level level) |
Log messages of importance level and greater. More... | |
static Level | getLevel () |
static void | setLevelString (std::string level) |
Set the logging level using one of the following strings (case-insensitive): More... | |
static std::string | getLevelString () |
static bool | shouldLog (Level level) |
Returns true if messages at the provided level should be logged, based on the set logging level. More... | |
static void | addFileSink (const std::string &filepath="opensim.log") |
Log messages to a file at the level getLevel(). More... | |
static void | removeFileSink () |
Remove the filesink if it exists. More... | |
static void | addSink (const std::shared_ptr< LogSink > sink) |
Start reporting messages to the provided sink. More... | |
static void | removeSink (const std::shared_ptr< LogSink > sink) |
Remove a sink. More... | |
Commands to log messages | |
Use these functions instead of using spdlog directly. | |
template<typename... Args> | |
static void | critical (spdlog::string_view_t fmt, const Args &... args) |
template<typename... Args> | |
static void | error (spdlog::string_view_t fmt, const Args &... args) |
template<typename... Args> | |
static void | warn (spdlog::string_view_t fmt, const Args &... args) |
template<typename... Args> | |
static void | info (spdlog::string_view_t fmt, const Args &... args) |
template<typename... Args> | |
static void | debug (spdlog::string_view_t fmt, const Args &... args) |
template<typename... Args> | |
static void | trace (spdlog::string_view_t fmt, const Args &... args) |
template<typename... Args> | |
static void | cout (spdlog::string_view_t fmt, const Args &... args) |
Use this function to log messages that would normally be sent to std::cout. More... | |
This is a singleton class (single instance) for logging messages and controlling how those messages are presented to the user.
|
delete |
This is a static singleton class: there is no way of constructing it.
|
static |
Log messages to a file at the level getLevel().
OpenSim logs messages to the file opensim.log by default. If we are already logging messages to a file, then this function issues a warning and returns; invoke removeFileSink() first.
|
static |
Start reporting messages to the provided sink.
|
inlinestatic |
Use this function to log messages that would normally be sent to std::cout.
These messages always appear, and are also logged to the filesink (addFileSink()) and any sinks added via addSink(). The main use case for this function is inside of functions whose intent is to print information (e.g., Component::printSubcomponentInfo()). Besides such use cases, this function should be used sparingly to give users control over what gets logged.
Referenced by log_cout().
|
inlinestatic |
Referenced by log_critical().
|
inlinestatic |
Referenced by log_debug().
|
inlinestatic |
Referenced by log_error().
|
static |
|
static |
|
inlinestatic |
Referenced by log_info().
|
static |
Remove the filesink if it exists.
If the filesink was already removed, then this does nothing.
|
static |
Remove a sink.
If it doesn't exist, do nothing.
|
static |
Log messages of importance level
and greater.
For example, if the level is set to Info, then Critical, Error, Warn, and Info messages are logged, while Debug and Trace messages are not logged.
|
static |
Set the logging level using one of the following strings (case-insensitive):
|
static |
Returns true if messages at the provided level should be logged, based on the set logging level.
The following code will produce output:
|
inlinestatic |
Referenced by log_trace().
|
inlinestatic |
Referenced by log_warn().
|
strong |
This enum lists the types of messages that should be logged.
These levels match those of the spdlog logging library that OpenSim uses for logging.
Enumerator | |
---|---|
Off | Do not log any messages. Useful when running an optimization or automated pipeline. |
Critical | Only log critical errors. |
Error | Log all messages that require user intervention. |
Warn | Log warnings. Warnings are generated when the software will proceed but the user should check their input. |
Info | Default. |
Debug | Log information that may be useful when debugging the operation of the software to investigate unexpected results. |
Trace | Log as much as possible, including messages that describe the software's behavior step by step. Note: OpenSim has very few Trace-level messages. |