shapeworks::Logging
Module: Common Classes
ShapeWorks Logging Library. More...
#include <Logging.h>
Public Functions
Name | |
---|---|
Logging & | Instance() Return the singleton instance. |
void | open_file_log(const std::string & filename) Create a file log. |
bool | check_log_open() const Return if the log is open. |
std::string | get_log_filename() const Return the log filename. |
void | log_message(const std::string & message, const int line, const char * file) const Log a message, use SW_LOG macro. |
void | log_stack(const std::string & message) const Log a stack trace message, use SW_LOG_STACK macro. |
void | log_error(const std::string & message, const int line, const char * file) const Log an error, use SW_ERROR macro. |
void | show_message(const std::string & message, const int line, const char * file) const Log a message, use SW_MESSAGE macro. |
void | show_status(const std::string & message, const int line, const char * file) const Log a message, use SW_STATUS macro. |
void | show_progress(double value, const std::string & message) Display progress (0-100) |
void | log_debug(const std::string & message, const int line, const char * file, const char * function) const Log a debug message, use SW_DEBUG macro. |
void | log_warning(const std::string & message, const int line, const char * file) const Log a warning message, use SW_WARN macro. |
void | close_log() Close the log, use SW_CLOSE_LOG macro. |
void | set_error_callback(const std::function< void(std::string)> & callback) Set an error callback function to be called whenever an error is raised. |
void | set_message_callback(const std::function< void(std::string)> & callback) Set a message callback function to be called whenever an message is posted. |
void | set_warning_callback(const std::function< void(std::string)> & callback) Set a warning callback function to be called whenever a warning is posted. |
void | set_debug_callback(const std::function< void(std::string)> & callback) Set a debug message callback function to be called whenever a debug message is posted. |
void | set_status_callback(const std::function< void(std::string)> & callback) Set a status callback function to be called whenever a status message is posted. |
void | set_progress_callback(const std::function< void(double, std::string)> & callback) Set a progress callback function to be called whenever a progress update is posted. |
Detailed Description
class shapeworks::Logging;
ShapeWorks Logging Library.
The Logging class supports univeral console and file logging.
To use the ShapeWorks logging library, use the pre-defined macros:
Normal log message:
SW_LOG("message")
Warning:
SW_WARN("warning")
Error:
SW_ERROR("error")
Debug:
SW_DEBUG("debug")
Output (assuming it was line 25 of Analyze.cpp and SW_LOG_LEVEL=debug):
[2022-08-18 11:40:01.021] [debug] [Analyze.cpp|25] debug
The logging macros using the fmt library. Read more here:
Example:
int mode = 10;
double eigen_value = 42.3;
SW_LOG("eigen value [{}]: {:.2f}", mode, eigen_value);
Output:
[2022-08-18 11:37:42.613] [info] eigen value [10]: 42.32
Public Functions Documentation
function Instance
static Logging & Instance()
Return the singleton instance.
function open_file_log
void open_file_log(
const std::string & filename
)
Create a file log.
function check_log_open
bool check_log_open() const
Return if the log is open.
function get_log_filename
std::string get_log_filename() const
Return the log filename.
function log_message
void log_message(
const std::string & message,
const int line,
const char * file
) const
Log a message, use SW_LOG macro.
function log_stack
void log_stack(
const std::string & message
) const
Log a stack trace message, use SW_LOG_STACK macro.
function log_error
void log_error(
const std::string & message,
const int line,
const char * file
) const
Log an error, use SW_ERROR macro.
function show_message
void show_message(
const std::string & message,
const int line,
const char * file
) const
Log a message, use SW_MESSAGE macro.
function show_status
void show_status(
const std::string & message,
const int line,
const char * file
) const
Log a message, use SW_STATUS macro.
function show_progress
void show_progress(
double value,
const std::string & message
)
Display progress (0-100)
function log_debug
void log_debug(
const std::string & message,
const int line,
const char * file,
const char * function
) const
Log a debug message, use SW_DEBUG macro.
function log_warning
void log_warning(
const std::string & message,
const int line,
const char * file
) const
Log a warning message, use SW_WARN macro.
function close_log
void close_log()
Close the log, use SW_CLOSE_LOG macro.
function set_error_callback
void set_error_callback(
const std::function< void(std::string)> & callback
)
Set an error callback function to be called whenever an error is raised.
function set_message_callback
void set_message_callback(
const std::function< void(std::string)> & callback
)
Set a message callback function to be called whenever an message is posted.
function set_warning_callback
void set_warning_callback(
const std::function< void(std::string)> & callback
)
Set a warning callback function to be called whenever a warning is posted.
function set_debug_callback
void set_debug_callback(
const std::function< void(std::string)> & callback
)
Set a debug message callback function to be called whenever a debug message is posted.
function set_status_callback
void set_status_callback(
const std::function< void(std::string)> & callback
)
Set a status callback function to be called whenever a status message is posted.
function set_progress_callback
void set_progress_callback(
const std::function< void(double, std::string)> & callback
)
Set a progress callback function to be called whenever a progress update is posted.
Updated on 2024-03-17 at 12:58:44 -0600