From dad9dd7e9e1ce83a5b095b6ce3e222a5d6e0a58a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Wed, 18 Mar 2020 15:57:29 +0800 Subject: [PATCH] iOS: devkit log --- doric-iOS/Devkit/Classes/DoricDebugJSEngine.m | 48 +++++++++++++++++++ doric-iOS/Pod/Classes/DoricRegistry.m | 14 ------ doric-iOS/Pod/Classes/Engine/DoricJSEngine.m | 17 ++++++- 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/doric-iOS/Devkit/Classes/DoricDebugJSEngine.m b/doric-iOS/Devkit/Classes/DoricDebugJSEngine.m index 3fa2fcac..37bc5e40 100644 --- a/doric-iOS/Devkit/Classes/DoricDebugJSEngine.m +++ b/doric-iOS/Devkit/Classes/DoricDebugJSEngine.m @@ -20,8 +20,55 @@ // Created by jingpeng.wang on 2020/2/25. // +#import "DoricContext.h" #import "DoricDebugJSEngine.h" #import "DoricJSRemoteExecutor.h" +#import "DoricUtil.h" +#import "NSString+JsonString.h" +#import "DoricDev.h" + +@interface DoricDebugMonitor : NSObject +@end + +@implementation DoricDebugMonitor +- (void)onException:(NSException *)exception inContext:(DoricContext *)context { + DoricLog(@"DefaultMonitor - source: %@- onException - %@", context.source, exception.reason); + NSDictionary *jsonDic = @{ + @"cmd": @"EXCEPTION", + @"data": @{ + @"source": [context.source stringByReplacingOccurrencesOfString:@".js" withString:@".ts"], + @"exception": exception.reason + } + }; + + NSString *jsonStr = [NSString dc_convertToJsonWithDic:jsonDic]; + [[DoricDev instance] sendDevCommand:jsonStr]; +} + +- (void)onLog:(DoricLogType)type message:(NSString *)message { + DoricLog(message); + + NSString *typeString = @"DEFAULT"; + if (type == DoricLogTypeDebug) { + typeString = @"DEFAULT"; + } else if (type == DoricLogTypeWarning) { + typeString = @"WARN"; + } else if (type == DoricLogTypeError) { + typeString = @"ERROR"; + } + + NSDictionary *jsonDic = @{ + @"cmd": @"LOG", + @"data": @{ + @"type": typeString, + @"message": message + } + }; + + NSString *jsonStr = [NSString dc_convertToJsonWithDic:jsonDic]; + [[DoricDev instance] sendDevCommand:jsonStr]; +} +@end @interface DoricDebugJSEngine () @end @@ -35,6 +82,7 @@ - (instancetype)init { } - (void)initJSEngine { + [self.registry registerMonitor:[DoricDebugMonitor new]]; self.jsExecutor = [[DoricJSRemoteExecutor alloc] init]; } diff --git a/doric-iOS/Pod/Classes/DoricRegistry.m b/doric-iOS/Pod/Classes/DoricRegistry.m index 2a8b2a56..9b9528d6 100644 --- a/doric-iOS/Pod/Classes/DoricRegistry.m +++ b/doric-iOS/Pod/Classes/DoricRegistry.m @@ -77,19 +77,6 @@ + (instancetype)instance { @end -@interface DoricDefaultMonitor : NSObject -@end - -@implementation DoricDefaultMonitor -- (void)onException:(NSException *)exception inContext:(DoricContext *)context { - DoricLog(@"DefaultMonitor - source: %@- onException - %@", context.source, exception.reason); -} - -- (void)onLog:(DoricLogType)type message:(NSString *)message { - DoricLog(message); -} -@end - @interface DoricRegistry () @property(nonatomic, strong) NSMutableDictionary *bundles; @@ -113,7 +100,6 @@ - (instancetype)init { _envVariables = [NSMutableDictionary new]; [self innerRegister]; _monitors = [NSMutableSet new]; - [self registerMonitor:[DoricDefaultMonitor new]]; [DoricLibraries.instance.libraries enumerateObjectsUsingBlock:^(DoricLibrary *obj, BOOL *stop) { [obj load:self]; }]; diff --git a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m index e0c59b72..c1c25bc1 100644 --- a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m +++ b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m @@ -26,6 +26,20 @@ #import "DoricUtil.h" #import "DoricBridgeExtension.h" #import +#import "DoricContext.h" + +@interface DoricDefaultMonitor : NSObject +@end + +@implementation DoricDefaultMonitor +- (void)onException:(NSException *)exception inContext:(DoricContext *)context { + DoricLog(@"DefaultMonitor - source: %@- onException - %@", context.source, exception.reason); +} + +- (void)onLog:(DoricLogType)type message:(NSString *)message { + DoricLog(message); +} +@end @interface DoricJSEngine () @property(nonatomic, strong) NSMutableDictionary *timers; @@ -59,8 +73,8 @@ - (instancetype)init { }; dispatch_async(_jsQueue, ^() { self.timers = [[NSMutableDictionary alloc] init]; - [self initJSEngine]; self.registry = [[DoricRegistry alloc] init]; + [self initJSEngine]; [self initJSExecutor]; [self initDoricEnvironment]; }); @@ -69,6 +83,7 @@ - (instancetype)init { } - (void)initJSEngine { + [self.registry registerMonitor:[DoricDefaultMonitor new]]; self.jsExecutor = [DoricJSCoreExecutor new]; }