Skip to content

Commit 11e047b

Browse files
committed
Add ability to log without going to Studio log
1 parent 3b78b50 commit 11e047b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Libs/Common/Logging.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace shapeworks {
1313
static std::string create_header(const int line, const char* filename, const char* function = "") {
1414
const char* name = (strrchr(filename, '/') ? strrchr(filename, '/') + 1 : filename);
1515
const char* name2 = (strrchr(name, '\\') ? strrchr(name, '\\') + 1 : name);
16-
const char* function_name = (strrchr(function, ':') ? strrchr(function, ':') + 1 : function);
1716
if (!function) {
1817
std::string header = "[" + std::string(name2) + "|" + std::to_string(line) + "]";
1918
return header;
2019
} else {
20+
const char* function_name = (strrchr(function, ':') ? strrchr(function, ':') + 1 : function);
2121
std::string header = "[" + std::string(name2) + "|" + std::string(function_name) + "|" + std::to_string(line) + "]";
2222
return header;
2323
}
@@ -69,6 +69,14 @@ void Logging::log_message(const std::string& message, const int line, const char
6969
}
7070
}
7171

72+
//-----------------------------------------------------------------------------
73+
void Logging::log_only(const std::string& message, const int line, const char* file) const {
74+
spd::info(message);
75+
if (log_open_) {
76+
spd::get("file")->info(message);
77+
}
78+
}
79+
7280
//-----------------------------------------------------------------------------
7381
void Logging::log_stack(const std::string& message) const {
7482
spd::error(message);

Libs/Common/Logging.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class Logging {
102102
//! Log a message, use SW_LOG macro
103103
void log_message(const std::string& message, const int line, const char* file) const;
104104

105+
//! Log a message, use SW_LOG_ONLY macro
106+
void log_only(const std::string& message, const int line, const char* file) const;
107+
105108
//! Log a stack trace message, use SW_LOG_STACK macro
106109
void log_stack(const std::string& message) const;
107110

@@ -171,6 +174,10 @@ class Logging {
171174
#define SW_LOG(message, ...) \
172175
shapeworks::Logging::Instance().log_message(safe_format(message, ##__VA_ARGS__), __LINE__, __FILE__);
173176

177+
//! Log only macro
178+
#define SW_LOG_ONLY(message, ...) \
179+
shapeworks::Logging::Instance().log_only(safe_format(message, ##__VA_ARGS__), __LINE__, __FILE__);
180+
174181
//! Log warning macro
175182
#define SW_WARN(message, ...) \
176183
shapeworks::Logging::Instance().log_warning(safe_format(message, ##__VA_ARGS__), __LINE__, __FILE__)

0 commit comments

Comments
 (0)