Skip to content

Commit

Permalink
Add support for toggling logs off and back on at runtime #trivial (Te…
Browse files Browse the repository at this point in the history
  • Loading branch information
johntmcintosh authored and bernieperez committed Apr 25, 2018
1 parent 4304d99 commit 2add509
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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

0 comments on commit 2add509

Please sign in to comment.