feat:Doric cli show doric logs

This commit is contained in:
pengfeizhou
2021-02-05 19:36:25 +08:00
committed by osborn
parent d4c8d08660
commit ddc74a9027
7 changed files with 196 additions and 20 deletions

View File

@@ -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;
}

View 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

View 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