2
0

Cross-platform translation of mpw logs into Pearl.

This commit is contained in:
Maarten Billemont 2020-04-06 19:27:17 -04:00
parent c62ff63718
commit 8e15be21ab
3 changed files with 42 additions and 49 deletions

View File

@ -31,6 +31,35 @@
@end
MPLogSink mpw_log_sink_pearl;
void mpw_log_sink_pearl(const MPLogEvent *record) {
PearlLogLevel level = PearlLogLevelInfo;
switch (record->level) {
case LogLevelTrace:
level = PearlLogLevelTrace;
break;
case LogLevelDebug:
level = PearlLogLevelDebug;
break;
case LogLevelInfo:
level = PearlLogLevelInfo;
break;
case LogLevelWarning:
level = PearlLogLevelWarn;
break;
case LogLevelError:
level = PearlLogLevelError;
break;
case LogLevelFatal:
level = PearlLogLevelFatal;
break;
}
[[PearlLogger get] inFile:[@(record->file) lastPathComponent] atLine:record->line fromFunction:@(record->function)
withLevel:level text:@(record->message)];
}
@implementation MPAppDelegate_Shared
static MPAppDelegate_Shared *instance;
@ -45,6 +74,16 @@ static MPAppDelegate_Shared *instance;
if (!(self = instance = [super init]))
return nil;
[PearlLogger get].historyLevel = PearlLogLevelInfo;
#ifdef DEBUG
[PearlLogger get].printLevel = PearlLogLevelDebug;
#else
[PearlLogger get].printLevel = PearlLogLevelInfo;
#endif
mpw_verbosity = LogLevelTrace;
mpw_log_sink_register( &mpw_log_sink_pearl );
NSManagedObjectModel *model = [NSManagedObjectModel mergedModelFromBundles:nil];
[model kc_generateOrderedSetAccessors];
self.storeCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];

View File

@ -39,14 +39,7 @@ static EventHotKeyID MPLockHotKey = { .signature = 'lock', .id = 1 };
+ (void)initialize {
static dispatch_once_t once = 0;
dispatch_once( &once, ^{
[MPMacConfig get];
#ifdef DEBUG
[PearlLogger get].printLevel = PearlLogLevelDebug; //Trace;
#endif
} );
[MPMacConfig get];
}
static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData) {
@ -98,7 +91,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
SentryLevel sentryLevel = kSentryLevelInfo;
switch (message.level) {
case PearlLogLevelTrace:
sentryLevel = kSentryLevelDebug;
sentryLevel = kSentryLevelNone;
break;
case PearlLogLevelDebug:
sentryLevel = kSentryLevelDebug;

View File

@ -33,50 +33,11 @@
@end
MPLogSink mpw_log_sink_pearl;
void mpw_log_sink_pearl(const MPLogEvent *record) {
PearlLogLevel level = PearlLogLevelInfo;
switch (record->level) {
case LogLevelTrace:
level = PearlLogLevelDebug;
break;
case LogLevelDebug:
level = PearlLogLevelDebug;
break;
case LogLevelInfo:
level = PearlLogLevelInfo;
break;
case LogLevelWarning:
level = PearlLogLevelWarn;
break;
case LogLevelError:
level = PearlLogLevelError;
break;
case LogLevelFatal:
level = PearlLogLevelFatal;
break;
}
[[PearlLogger get] inFile:[@(record->file) lastPathComponent] atLine:record->line fromFunction:@(record->function)
withLevel:level text:@(record->message)];
}
@implementation MPiOSAppDelegate
+ (void)initialize {
static dispatch_once_t once = 0;
dispatch_once( &once, ^{
[PearlLogger get].printLevel = [[MPiOSConfig get].traceMode boolValue]? PearlLogLevelDebug: PearlLogLevelInfo;
[PearlLogger get].historyLevel = [[MPiOSConfig get].traceMode boolValue]? PearlLogLevelTrace: PearlLogLevelInfo;
#ifdef DEBUG
[PearlLogger get].printLevel = PearlLogLevelDebug;
#endif
mpw_verbosity = LogLevelTrace;
mpw_log_sink_register( &mpw_log_sink_pearl );
} );
[MPiOSConfig get];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {