Skip to content

Commit

Permalink
perf: improve log, change some MMLogWarn to MMLogError
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed Apr 29, 2024
1 parent 709ee8a commit 8f9c876
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Easydict/objc/MMKit/Kit/MMOrderedDictionary.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ - (id)mutableCopyWithZone:(NSZone *)zone {

- (id)copy {
NSString *reason = [NSString stringWithFormat:@"-[%@ %@] not supported, please use mutableCopy!", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
MMLogWarn(@"%@", reason);
MMLogError(@"%@", reason);
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:reason
userInfo:nil];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ - (void)detectText:(NSString *)text completion:(nonnull void (^)(EZLanguage, NSE
}

- (void)ocr:(EZQueryModel *)queryModel completion:(void (^)(EZOCRResult *_Nullable, NSError *_Nullable))completion {
MMLogWarn(@"Apple Dictionary does not support ocr");
MMLogError(@"Apple Dictionary does not support ocr");
}

- (BOOL)queryDictionaryForText:(NSString *)text language:(EZLanguage)language {
Expand Down
8 changes: 4 additions & 4 deletions Easydict/objc/Service/AudioPlayer/EZAudioPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ - (BOOL)canPlayLocalAudioFileAtPath:(NSString *)filePath {

if (!asset.readable || !asset.isPlayable) {
// change go.mp3 to go.m4a will cause asset not readable
MMLogWarn(@"asset not readable or playable: %@", filePath);
MMLogError(@"asset not readable or playable: %@", filePath);
return NO;
}

Expand Down Expand Up @@ -697,7 +697,7 @@ - (nullable NSString *)tryCorrectAudioFileTypeWithPath:(NSString *)filePath {
MMLogInfo(@"rename successful: %@", newFilePath);
return newFilePath;
} else {
MMLogWarn(@"rename failed: %@", [error localizedDescription]);
MMLogError(@"rename failed: %@", [error localizedDescription]);
return nil;
}
}
Expand Down Expand Up @@ -738,7 +738,7 @@ - (BOOL)isAudioFilePlayable:(NSURL *)filePathURL {
return NO;
}
} else {
MMLogWarn(@"Error opening audio file type: %d", (int)status);
MMLogError(@"Error opening audio file type: %d", (int)status);
return NO;
}
return YES;
Expand Down Expand Up @@ -776,7 +776,7 @@ - (BOOL)isAudioFilePlayable:(NSURL *)filePathURL {
id plistData = [NSPropertyListSerialization propertyListWithData:itemWhereFroms options:NSPropertyListImmutable format:&format error:&plistError];

if (plistError) {
MMLogWarn(@"Error decoding property list: %@", plistError);
MMLogError(@"Error decoding property list: %@", plistError);
return nil;
}

Expand Down
2 changes: 1 addition & 1 deletion Easydict/objc/Service/DeepL/EZDeepLTranslate.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ - (void)translate:(NSString *)text from:(EZLanguage)from to:(EZLanguage)to compl
}

- (void)ocr:(EZQueryModel *)queryModel completion:(void (^)(EZOCRResult *_Nullable, NSError *_Nullable))completion {
MMLogWarn(@"deepL not support ocr");
MMLogError(@"deepL not support ocr");
}

- (BOOL)autoConvertTraditionalChinese {
Expand Down
6 changes: 3 additions & 3 deletions Easydict/objc/Service/WebViewTranslator/EZWebViewTranslator.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ - (void)queryTranslateURL:(NSString *)URL
// MMLog(@"queryTranslateURL: %@", URL);

[self loadURL:URL];
CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
// CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();

if (URL.length && completionHandler) {
mm_weakify(self);
Expand All @@ -152,7 +152,7 @@ - (void)queryTranslateURL:(NSString *)URL
completionHandler(nil, error);
} else {
completionHandler(texts, nil);
CFAbsoluteTime endTime = CFAbsoluteTimeGetCurrent();
// CFAbsoluteTime endTime = CFAbsoluteTimeGetCurrent();
// MMLog(@"webView cost: %.1f ms, URL: %@", (endTime - startTime) * 1000, URL); // cost ~2s
}
[self resetWebView];
Expand Down Expand Up @@ -229,7 +229,7 @@ - (void)getTextContentOfElement:(NSString *)selector
[self getTextContentOfElement:selector completion:completion];
});
} else {
MMLogWarn(@"fail, max retry count: %ld", self.retryCount);
MMLogError(@"fail, max retry count: %ld", self.retryCount);
if (completion) {
completion(nil, [EZError timeoutError]);
}
Expand Down
2 changes: 1 addition & 1 deletion Easydict/objc/Snip/Snip.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ - (MMEventMonitor *)rightMouseDownMonitor {
- (void)startWithCompletion:(void (^)(NSImage *_Nullable))completion {
BOOL enableRecord = [self checkRecordPermission];
if (!enableRecord) {
MMLogWarn(@"disabled record permission");
MMLogError(@"disabled record permission");
completion(nil);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions Easydict/objc/Utility/EZAudioUtils/EZAudioUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ + (void)getPlayingSongInfo {
// Get a C function pointer for MRMediaRemoteGetNowPlayingInfo
void *mrMediaRemoteGetNowPlayingInfoPointer = CFBundleGetFunctionPointerForName(mediaRemoteBundle, CFSTR("MRMediaRemoteGetNowPlayingInfo"));
if (!mrMediaRemoteGetNowPlayingInfoPointer) {
MMLogWarn(@"Failed to get MRMediaRemoteGetNowPlayingInfo function pointer");
MMLogError(@"Failed to get MRMediaRemoteGetNowPlayingInfo function pointer");
CFRelease(mediaRemoteBundle);
}
typedef void (*MRMediaRemoteGetNowPlayingInfoFunction)(dispatch_queue_t queue, void (^completionHandler)(NSDictionary *information));
Expand All @@ -96,7 +96,7 @@ + (void)getPlayingSongInfo {
// Get a C function pointer for MRNowPlayingClientGetBundleIdentifier
void *mrNowPlayingClientGetBundleIdentifierPointer = CFBundleGetFunctionPointerForName(mediaRemoteBundle, CFSTR("MRNowPlayingClientGetBundleIdentifier"));
if (!mrNowPlayingClientGetBundleIdentifierPointer) {
MMLogWarn(@"Failed to get MRNowPlayingClientGetBundleIdentifier function pointer");
MMLogError(@"Failed to get MRNowPlayingClientGetBundleIdentifier function pointer");
CFRelease(mediaRemoteBundle);
}

Expand Down

0 comments on commit 8f9c876

Please sign in to comment.