Skip to content

Commit

Permalink
[darwin] Make CHIPCommandStorageDelegate less chatty by default to no…
Browse files Browse the repository at this point in the history
…t pollute logs (#22729)
  • Loading branch information
vivien-apple authored Sep 19, 2022
1 parent 0cf7694 commit 7282834
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#import <Matter/Matter.h>

#define LOG_DEBUG_PERSISTENT_STORAGE_DELEGATE 0

NSString * const kCHIPToolDefaultsDomain = @"com.apple.chiptool";

id MTRGetDomainValueForKey(NSString * domain, NSString * key)
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#import "MTRPersistentStorageDelegateBridge.h"

#define LOG_DEBUG_PERSISTENT_STORAGE_DELEGATE 0

MTRPersistentStorageDelegateBridge::MTRPersistentStorageDelegateBridge(id<MTRStorage> delegate)
: mDelegate(delegate)
, mWorkQueue(dispatch_queue_create("com.csa.matter.framework.storage.workqueue", DISPATCH_QUEUE_SERIAL))
Expand All @@ -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];

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 7282834

Please sign in to comment.