feat:Doric cli show doric logs
This commit is contained in:
@@ -28,6 +28,16 @@
|
||||
#import "DoricWSClient.h"
|
||||
#import "DoricDebugDriver.h"
|
||||
#import "DoricDevViewController.h"
|
||||
#import "DoricDevMonitor.h"
|
||||
|
||||
@interface DoricDevLibrary : DoricLibrary
|
||||
@end
|
||||
|
||||
@implementation DoricDevLibrary
|
||||
- (void)load:(DoricRegistry *)registry {
|
||||
|
||||
}
|
||||
@end
|
||||
|
||||
@interface DoricDev ()
|
||||
@property(nonatomic, strong) DoricWSClient *wsclient;
|
||||
@@ -46,6 +56,12 @@ - (instancetype)init {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onEnterDebugEvent) name:@"EnterDebugEvent" object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onStopDebugEvent) name:@"StopDebugEvent" object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDebuggerReadyEvent) name:@"DebuggerReadyEvent" object:nil];
|
||||
[Doric registerLibrary:[DoricDevLibrary new]];
|
||||
NSValue *value = DoricContextManager.instance.aliveContexts.firstObject;
|
||||
if (value) {
|
||||
DoricContext *context = value.nonretainedObjectValue;
|
||||
[context.driver.registry registerMonitor:[DoricDevMonitor new]];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
16
doric-iOS/Devkit/Classes/DoricDevMonitor.h
Normal file
16
doric-iOS/Devkit/Classes/DoricDevMonitor.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// DoricDevMonitor.h
|
||||
// DoricDevkit
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/2/5.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricMonitorProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricDevMonitor : NSObject <DoricMonitorProtocol>
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
55
doric-iOS/Devkit/Classes/DoricDevMonitor.m
Normal file
55
doric-iOS/Devkit/Classes/DoricDevMonitor.m
Normal file
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// DoricDevMonitor.m
|
||||
// DoricDevkit
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/2/5.
|
||||
//
|
||||
|
||||
#import "DoricDevMonitor.h"
|
||||
|
||||
#import "DoricDev.h"
|
||||
#import "NSString+JsonString.h"
|
||||
#import "Doric.h"
|
||||
|
||||
@implementation DoricDevMonitor
|
||||
- (void)onException:(NSException *)exception inContext:(DoricContext *)context {
|
||||
if (!DoricDev.instance.isInDevMode) {
|
||||
return;
|
||||
}
|
||||
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 {
|
||||
if (!DoricDev.instance.isInDevMode) {
|
||||
return;
|
||||
}
|
||||
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
|
Reference in New Issue
Block a user