Libs/Common/Logging.h
Namespaces
| Name |
|---|
| shapeworks User usage reporting (telemetry) |
Classes
| Name | |
|---|---|
| struct | fmt::formatter< QString > |
| class | shapeworks::Logging ShapeWorks Logging Library. |
Functions
| Name | |
|---|---|
| template <typename... Args> std::string |
safe_format(const std::string & fmt_str, const Args &... args) |
Defines
| Name | |
|---|---|
| SW_LOG_STACK(message) Log stack macro. |
|
| SW_LOG(message, ...) Log message macro. |
|
| SW_LOG_ONLY(message, ...) Log only macro. |
|
| SW_WARN(message, ...) Log warning macro. |
|
| SW_ERROR(message, ...) Log error macro. |
|
| SW_DEBUG(message, ...) Log debug macro. |
|
| SW_TRACE(x) Variable trace macro (e.g. output variable name = |
|
| SW_MESSAGE(message, ...) Log show message macro. |
|
| SW_STATUS(message, ...) Don't write to log, but set status (e.g. in the Studio statusbar) |
|
| SW_PROGRESS(value, message, ...) | |
| SW_CLOSE_LOG() Close session macro. |
|
| SW_LOG_ONCE(message, ...) Log once macro, will only log the message once. |
Functions Documentation
function safe_format
cpp
template <typename... Args>
std::string safe_format(
const std::string & fmt_str,
const Args &... args
)
Macros Documentation
define SW_LOG_STACK
```cpp
define SW_LOG_STACK(
message
) shapeworks::Logging::Instance().log_stack(message) ```
Log stack macro.
define SW_LOG
```cpp
define SW_LOG(
message,
...
) shapeworks::Logging::Instance().log_message(safe_format(message, ##VA_ARGS), LINE, FILE); ```
Log message macro.
define SW_LOG_ONLY
```cpp
define SW_LOG_ONLY(
message,
...
) shapeworks::Logging::Instance().log_only(safe_format(message, ##VA_ARGS), LINE, FILE, FUNCTION); ```
Log only macro.
define SW_WARN
```cpp
define SW_WARN(
message,
...
) shapeworks::Logging::Instance().log_warning(safe_format(message, ##VA_ARGS), LINE, FILE) ```
Log warning macro.
define SW_ERROR
```cpp
define SW_ERROR(
message,
...
) shapeworks::Logging::Instance().log_error(safe_format(message, ##VA_ARGS), LINE, FILE) ```
Log error macro.
define SW_DEBUG
```cpp
define SW_DEBUG(
message,
...
) shapeworks::Logging::Instance().log_debug(safe_format(message, ##VA_ARGS), LINE, FILE, FUNCTION) ```
Log debug macro.
define SW_TRACE
```cpp
define SW_TRACE(
x
) SW_DEBUG(#x " = {}", x); ```
Variable trace macro (e.g. output variable name =
define SW_MESSAGE
```cpp
define SW_MESSAGE(
message,
...
) shapeworks::Logging::Instance().show_message(safe_format(message, ##VA_ARGS), LINE, FILE) ```
Log show message macro.
define SW_STATUS
```cpp
define SW_STATUS(
message,
...
) shapeworks::Logging::Instance().show_status(safe_format(message, ##VA_ARGS), LINE, FILE) ```
Don't write to log, but set status (e.g. in the Studio statusbar)
define SW_PROGRESS
```cpp
define SW_PROGRESS(
value,
message,
...
) shapeworks::Logging::Instance().show_progress(value, safe_format(message, ##VA_ARGS)); ```
define SW_CLOSE_LOG
```cpp
define SW_CLOSE_LOG(
) shapeworks::Logging::Instance().close_log(); ```
Close session macro.
define SW_LOG_ONCE
```cpp
define SW_LOG_ONCE(
message,
...
) { \ static bool logged = false; \ if (!logged) { \ SW_LOG(message, ##VA_ARGS); \ logged = true; \ } \ } ```
Log once macro, will only log the message once.
Source code
```cpp
pragma once
include
include
include
include
template <>
struct fmt::formatter
template
template
namespace shapeworks {
class Logging { public: static Logging& Instance();
void open_file_log(const std::string& filename);
bool check_log_open() const;
std::string get_log_filename() const;
void log_message(const std::string& message, const int line, const char* file) const;
void log_only(const std::string& message, const int line, const char file, const char function) const;
void log_stack(const std::string& message) const;
void log_error(const std::string& message, const int line, const char* file) const;
void show_message(const std::string& message, const int line, const char* file) const;
void show_status(const std::string& message, const int line, const char* file) const;
void show_progress(double value, const std::string& message);
void log_debug(const std::string& message, const int line, const char file, const char function) const;
void log_warning(const std::string& message, const int line, const char* file) const;
void close_log();
void set_error_callback(const std::function
void set_message_callback(const std::function
void set_warning_callback(const std::function
void set_debug_callback(const std::function
void set_status_callback(const std::function
void set_progress_callback(const std::function
private: Logging();
std::string log_filename_; bool log_open_ = false;
std::function
std::function
std::function
std::function
std::function
std::function
define SW_LOG_STACK(message) shapeworks::Logging::Instance().log_stack(message)
#define SW_LOG(message, ...) \ shapeworks::Logging::Instance().log_message(safe_format(message, ##VA_ARGS), LINE, FILE);
#define SW_LOG_ONLY(message, ...) \ shapeworks::Logging::Instance().log_only(safe_format(message, ##VA_ARGS), LINE, FILE, FUNCTION);
#define SW_WARN(message, ...) \ shapeworks::Logging::Instance().log_warning(safe_format(message, ##VA_ARGS), LINE, FILE)
#define SW_ERROR(message, ...) \ shapeworks::Logging::Instance().log_error(safe_format(message, ##VA_ARGS), LINE, FILE)
#define SW_DEBUG(message, ...) \ shapeworks::Logging::Instance().log_debug(safe_format(message, ##VA_ARGS), LINE, FILE, FUNCTION)
define SW_TRACE(x) SW_DEBUG(#x " = {}", x);
#define SW_MESSAGE(message, ...) \ shapeworks::Logging::Instance().show_message(safe_format(message, ##VA_ARGS), LINE, FILE)
#define SW_STATUS(message, ...) \ shapeworks::Logging::Instance().show_status(safe_format(message, ##VA_ARGS), LINE, FILE)
#define SW_PROGRESS(value, message, ...) \ shapeworks::Logging::Instance().show_progress(value, safe_format(message, ##VA_ARGS));
define SW_CLOSE_LOG() shapeworks::Logging::Instance().close_log();
#define SW_LOG_ONCE(message, ...) \ { \ static bool logged = false; \ if (!logged) { \ SW_LOG(message, ##VA_ARGS); \ logged = true; \ } \ } } // namespace shapeworks ```
Updated on 2026-03-31 at 16:02:11 +0000