Skip to content

Commit

Permalink
Add SW_LOG_ONCE macro and use with telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
akenmorris committed Feb 14, 2023
1 parent b307215 commit cc4c123
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Libs/Common/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,13 @@ class Logging {
//! Close session macro
#define SW_CLOSE_LOG() shapeworks::Logging::Instance().close_log();

//! Log once macro, will only log the message once
#define SW_LOG_ONCE(message, ...) \
{ \
static bool logged = false; \
if (!logged) { \
SW_LOG(message, ##__VA_ARGS__); \
logged = true; \
} \
}
} // namespace shapeworks
4 changes: 2 additions & 2 deletions Studio/Data/Telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ void Telemetry::record_event(const QString& name, const QVariantMap& params) {
QString api_secret{GA_API_SECRET};

if (measurement_id.isEmpty() || api_secret.isEmpty()) {
SW_LOG("Telemetry disabled, no measurement id or api secret");
SW_LOG_ONCE("Telemetry disabled, no measurement id or api secret");
return;
}

if (!prefs_.get_telemetry_enabled()) {
SW_LOG("Telemetry disabled by preferences");
SW_LOG_ONCE("Telemetry disabled by preferences");
return;
}

Expand Down

0 comments on commit cc4c123

Please sign in to comment.