通过使用[obj redactedDescription]
从日志中红字敏感字符串,类似于Rails的filter_parameters。
默认情况下,红字字典和基本键值样式日志中的密码属性。
红字字典
[@{@"password": "secret",@"username": @"user01"} redactedDescription]
-> {
password: [REDACTED];
username: "user01";
}
红字字符串
[@"password = secret; username = user01" redactedDescription]
-> password = [REDACTED]; username = user01
#import "Redact.h"
然后使用[obj redactedDescription];
或者使用RedactedLog()替代NSLog(),将以下宏之一添加到您的.pch文件中:
#define NSLog RedactedLogF // if you would like filename and function name
// or
#define NSLog RedactedLog // cleaner log and without any extra meta info
默认情况下password
是一个红字键,但很容易添加更多。
[NCRedact addRedactedKey:@"secret_key"];
或使用redact来缩减日志
NSString *path = [[NSBundle mainBundle] bundlePath];
[NCRedact addRedactedString:path with:@"[BUNDLE]"];
要运行测试用例;克隆存储库,并从Example目录运行pod install
。然后打开工作空间并运行测试。
Daniel Brooker, [email protected], @DraconisNZ
Redact可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。