From 87378c58fecc30c55a1066b391289ea11305c490 Mon Sep 17 00:00:00 2001 From: limingming Date: Fri, 28 Oct 2022 16:18:53 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dlog=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NSLog/Function/DoraemonNSLogManager.h | 7 ++-- .../NSLog/Function/DoraemonNSLogManager.m | 34 ++++++++++++++----- .../List/DoraemonNSLogListViewController.m | 12 +++---- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/iOS/DoraemonKit/Src/Core/Plugin/Common/NSLog/Function/DoraemonNSLogManager.h b/iOS/DoraemonKit/Src/Core/Plugin/Common/NSLog/Function/DoraemonNSLogManager.h index dfd2ff56a..207dcdd87 100644 --- a/iOS/DoraemonKit/Src/Core/Plugin/Common/NSLog/Function/DoraemonNSLogManager.h +++ b/iOS/DoraemonKit/Src/Core/Plugin/Common/NSLog/Function/DoraemonNSLogManager.h @@ -13,11 +13,14 @@ + (instancetype)sharedInstance; -@property (nonatomic, strong) NSMutableArray *dataArray; - - (void)startNSLogMonitor; - (void)stopNSLogMonitor; - (void)addNSLog:(NSString *)log; + +- (NSArray *)readLogs; +- (void)clearLogs; + @end + diff --git a/iOS/DoraemonKit/Src/Core/Plugin/Common/NSLog/Function/DoraemonNSLogManager.m b/iOS/DoraemonKit/Src/Core/Plugin/Common/NSLog/Function/DoraemonNSLogManager.m index 37f3b6eff..b1b6adf67 100644 --- a/iOS/DoraemonKit/Src/Core/Plugin/Common/NSLog/Function/DoraemonNSLogManager.m +++ b/iOS/DoraemonKit/Src/Core/Plugin/Common/NSLog/Function/DoraemonNSLogManager.m @@ -25,6 +25,10 @@ void myNSLog(NSString *format, ...){ old_nslog(@"%@",str); } +@interface DoraemonNSLogManager() +@property (nonatomic, strong) NSMutableArray *dataArray; +@property (nonatomic, strong) dispatch_queue_t logQueue; +@end @implementation DoraemonNSLogManager @@ -39,6 +43,7 @@ + (instancetype)sharedInstance { } - (void)startNSLogMonitor{ + self.logQueue = dispatch_queue_create("dokit.log.queue", DISPATCH_QUEUE_SERIAL); doraemon_rebind_symbols((struct doraemon_rebinding[1]){"NSLog", (void *)myNSLog, (void **)&old_nslog},1); } @@ -47,14 +52,16 @@ - (void)stopNSLogMonitor{ } - (void)addNSLog:(NSString *)log{ - DoraemonNSLogModel *model = [[DoraemonNSLogModel alloc] init]; - model.content = log; - model.timeInterval = [[NSDate date] timeIntervalSince1970]; - - if (!_dataArray) { - _dataArray = [[NSMutableArray alloc] init]; - } - [_dataArray addObject:model]; + dispatch_sync(self.logQueue, ^{ + DoraemonNSLogModel *model = [[DoraemonNSLogModel alloc] init]; + model.content = log; + model.timeInterval = [[NSDate date] timeIntervalSince1970]; + + if (!_dataArray) { + _dataArray = [[NSMutableArray alloc] init]; + } + [_dataArray addObject:model]; + }); // return; // if (@available(iOS 13.0, *)) { @@ -66,4 +73,15 @@ - (void)addNSLog:(NSString *)log{ } +- (NSArray *)readLogs { + NSArray *array = [_dataArray copy]; + return array; +} + +- (void)clearLogs { + dispatch_sync(self.logQueue, ^{ + [self.dataArray removeAllObjects]; + }); +} + @end diff --git a/iOS/DoraemonKit/Src/Core/Plugin/Common/NSLog/List/DoraemonNSLogListViewController.m b/iOS/DoraemonKit/Src/Core/Plugin/Common/NSLog/List/DoraemonNSLogListViewController.m index d27f68955..212a236aa 100644 --- a/iOS/DoraemonKit/Src/Core/Plugin/Common/NSLog/List/DoraemonNSLogListViewController.m +++ b/iOS/DoraemonKit/Src/Core/Plugin/Common/NSLog/List/DoraemonNSLogListViewController.m @@ -33,8 +33,8 @@ - (void)viewDidLoad { [self setRightNavBarItems:@[model1,model2]]; //按照时间倒序排列 - self.dataArray = [[[DoraemonNSLogManager sharedInstance].dataArray reverseObjectEnumerator] allObjects]; - + NSArray *logs = [[DoraemonNSLogManager sharedInstance] readLogs]; + self.dataArray = [[logs reverseObjectEnumerator] allObjects]; _searchView = [[DoraemonNSLogSearchView alloc] initWithFrame:CGRectMake(kDoraemonSizeFrom750_Landscape(32), IPHONE_NAVIGATIONBAR_HEIGHT+kDoraemonSizeFrom750_Landscape(32), self.view.doraemon_width-2*kDoraemonSizeFrom750_Landscape(32), kDoraemonSizeFrom750_Landscape(100))]; _searchView.delegate = self; @@ -49,13 +49,13 @@ - (void)viewDidLoad { } - (void)clear { - [[DoraemonNSLogManager sharedInstance].dataArray removeAllObjects]; + [[DoraemonNSLogManager sharedInstance] clearLogs]; self.dataArray = [[NSArray alloc] init]; [self.tableView reloadData]; } - (void)export { - NSArray *dataArray = [[DoraemonNSLogManager sharedInstance].dataArray copy]; + NSArray *dataArray = [[DoraemonNSLogManager sharedInstance] readLogs]; NSMutableString *log = [[NSMutableString alloc] init]; for (DoraemonNSLogModel *model in dataArray) { NSString *time = [NSString stringWithFormat:@"[%@]",[DoraemonUtil dateFormatTimeInterval:model.timeInterval]]; @@ -128,7 +128,7 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd #pragma mark - DoraemonNSLogSearchViewDelegate - (void)searchViewInputChange:(NSString *)text{ if (text.length > 0) { - NSArray *dataArray = [[[DoraemonNSLogManager sharedInstance].dataArray reverseObjectEnumerator] allObjects]; + NSArray *dataArray = [[[[DoraemonNSLogManager sharedInstance] readLogs] reverseObjectEnumerator] allObjects]; NSMutableArray *resultArray = [[NSMutableArray alloc] init]; for(DoraemonNSLogModel *model in dataArray){ NSString *content = model.content; @@ -138,7 +138,7 @@ - (void)searchViewInputChange:(NSString *)text{ } self.dataArray = [[NSArray alloc] initWithArray:resultArray]; }else{ - self.dataArray = [[[DoraemonNSLogManager sharedInstance].dataArray reverseObjectEnumerator] allObjects]; + self.dataArray = [[[[DoraemonNSLogManager sharedInstance] readLogs] reverseObjectEnumerator] allObjects]; } [self.tableView reloadData]; From 59d7d38ec2f33493589f61bdd1ff86afd59a9139 Mon Sep 17 00:00:00 2001 From: limingming Date: Fri, 28 Oct 2022 16:50:20 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E5=85=BC=E5=AE=B9=E7=9B=AE=E5=89=8Dhover=20p?= =?UTF-8?q?odfile.lock=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DoraemonKit.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DoraemonKit.podspec b/DoraemonKit.podspec index 6d4e3e285..ddc4d43ac 100644 --- a/DoraemonKit.podspec +++ b/DoraemonKit.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| s.name = 'DoraemonKit' - s.version = '3.1.3' + s.version = '3.1.2' s.summary = 'iOS 各式各样的工具集合' # This description is used to generate tags and improve search results. From 8dc30b972bff4d6e26bc34025501899dd5b22598 Mon Sep 17 00:00:00 2001 From: limingming Date: Thu, 3 Nov 2022 10:33:20 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=9B=9E=E6=BB=9A=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E7=BB=99=E6=BA=90=E9=A1=B9=E7=9B=AE=E6=8F=90?= =?UTF-8?q?PR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DoraemonKit.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DoraemonKit.podspec b/DoraemonKit.podspec index ddc4d43ac..6d4e3e285 100644 --- a/DoraemonKit.podspec +++ b/DoraemonKit.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| s.name = 'DoraemonKit' - s.version = '3.1.2' + s.version = '3.1.3' s.summary = 'iOS 各式各样的工具集合' # This description is used to generate tags and improve search results.