From 7282834171bb07efa9f15a13725bf3ed44ace64f Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Mon, 19 Sep 2022 19:59:48 +0200 Subject: [PATCH] [darwin] Make CHIPCommandStorageDelegate less chatty by default to not pollute logs (#22729) --- .../commands/common/CHIPCommandStorageDelegate.mm | 8 ++++++++ .../Framework/CHIP/MTRPersistentStorageDelegateBridge.mm | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/examples/darwin-framework-tool/commands/common/CHIPCommandStorageDelegate.mm b/examples/darwin-framework-tool/commands/common/CHIPCommandStorageDelegate.mm index 45af924a7fee8b..7cbdce85006375 100644 --- a/examples/darwin-framework-tool/commands/common/CHIPCommandStorageDelegate.mm +++ b/examples/darwin-framework-tool/commands/common/CHIPCommandStorageDelegate.mm @@ -2,6 +2,8 @@ #import +#define LOG_DEBUG_PERSISTENT_STORAGE_DELEGATE 0 + NSString * const kCHIPToolDefaultsDomain = @"com.apple.chiptool"; id MTRGetDomainValueForKey(NSString * domain, NSString * key) @@ -39,9 +41,13 @@ BOOL CHIPClearAllDomain(NSString * domain) { NSArray * allKeys = CHIPGetDomainKeyList(domain); +#if LOG_DEBUG_PERSISTENT_STORAGE_DELEGATE NSLog(@"Removing keys: %@ %@", allKeys, domain); +#endif for (id key in allKeys) { +#if LOG_DEBUG_PERSISTENT_STORAGE_DELEGATE NSLog(@"Removing key: %@", key); +#endif if (!MTRRemoveDomainValueForKey(domain, (NSString *) key)) { return NO; } @@ -61,7 +67,9 @@ - (BOOL)deleteAllStorage - (nullable NSData *)storageDataForKey:(NSString *)key { NSData * value = MTRGetDomainValueForKey(kCHIPToolDefaultsDomain, key); +#if LOG_DEBUG_PERSISTENT_STORAGE_DELEGATE NSLog(@"CHIPPersistentStorageDelegate Get Value for Key: %@, value %@", key, value); +#endif return value; } diff --git a/src/darwin/Framework/CHIP/MTRPersistentStorageDelegateBridge.mm b/src/darwin/Framework/CHIP/MTRPersistentStorageDelegateBridge.mm index bc14ad1020cafe..fdcde68d6799cc 100644 --- a/src/darwin/Framework/CHIP/MTRPersistentStorageDelegateBridge.mm +++ b/src/darwin/Framework/CHIP/MTRPersistentStorageDelegateBridge.mm @@ -17,6 +17,8 @@ #import "MTRPersistentStorageDelegateBridge.h" +#define LOG_DEBUG_PERSISTENT_STORAGE_DELEGATE 0 + MTRPersistentStorageDelegateBridge::MTRPersistentStorageDelegateBridge(id delegate) : mDelegate(delegate) , mWorkQueue(dispatch_queue_create("com.csa.matter.framework.storage.workqueue", DISPATCH_QUEUE_SERIAL)) @@ -35,7 +37,9 @@ NSString * keyString = [NSString stringWithUTF8String:key]; dispatch_sync(mWorkQueue, ^{ +#if LOG_DEBUG_PERSISTENT_STORAGE_DELEGATE NSLog(@"PersistentStorageDelegate Sync Get Value for Key: %@", keyString); +#endif NSData * value = [mDelegate storageDataForKey:keyString]; @@ -76,7 +80,9 @@ __block CHIP_ERROR error = CHIP_NO_ERROR; dispatch_sync(mWorkQueue, ^{ +#if LOG_DEBUG_PERSISTENT_STORAGE_DELEGATE NSLog(@"PersistentStorageDelegate Set Key %@", keyString); +#endif if ([mDelegate setStorageData:valueData forKey:keyString] == NO) { error = CHIP_ERROR_PERSISTED_STORAGE_FAILED; @@ -92,7 +98,9 @@ __block CHIP_ERROR error = CHIP_NO_ERROR; dispatch_sync(mWorkQueue, ^{ +#if LOG_DEBUG_PERSISTENT_STORAGE_DELEGATE NSLog(@"PersistentStorageDelegate Delete Key: %@", keyString); +#endif if ([mDelegate removeStorageDataForKey:keyString] == NO) { error = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;