From 2add5099b9a7306eb1f35826a7586b358a86b5b8 Mon Sep 17 00:00:00 2001 From: John T McIntosh Date: Wed, 20 Dec 2017 06:49:09 -0600 Subject: [PATCH] Add support for toggling logs off and back on at runtime #trivial (#714) --- Source/Base/ASLog.h | 10 ++++++++++ Source/Base/ASLog.m | 9 +++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Source/Base/ASLog.h b/Source/Base/ASLog.h index be4bff368..c6aba76ba 100644 --- a/Source/Base/ASLog.h +++ b/Source/Base/ASLog.h @@ -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); diff --git a/Source/Base/ASLog.m b/Source/Base/ASLog.m index 8e65c4b55..e1c42ea79 100644 --- a/Source/Base/ASLog.m +++ b/Source/Base/ASLog.m @@ -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() {