Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for toggling logs off and back on at runtime #714

Merged
merged 1 commit into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Source/Base/ASLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ ASDISPLAYNODE_EXTERN_C_BEGIN
*/
void ASDisableLogging(void);

/**
* Restore logging that has been runtime-disabled via ASDisableLogging().
*
* Logging can be disabled at runtime using the ASDisableLogging() function.
* This command restores logging to the level provided in the build
* configuration. This can be used in conjunction with ASDisableLogging()
* to allow logging to be toggled off and back on at runtime.
*/
void ASEnableLogging(void);

/// Log for general node events e.g. interfaceState, didLoad.
#define ASNodeLogEnabled 1
os_log_t ASNodeLog(void);
Expand Down
9 changes: 5 additions & 4 deletions Source/Base/ASLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
static atomic_bool __ASLogEnabled = ATOMIC_VAR_INIT(YES);

void ASDisableLogging() {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
atomic_store(&__ASLogEnabled, NO);
});
atomic_store(&__ASLogEnabled, NO);
}

void ASEnableLogging() {
atomic_store(&__ASLogEnabled, YES);
}

ASDISPLAYNODE_INLINE BOOL ASLoggingIsEnabled() {
Expand Down