Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): add missing error log and suppress some warning #3573

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions framework/ios/base/modules/HippyModulesSetup.mm
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ - (void)setupModulesCompletion:(dispatch_block_t)completion {
// Check for name collisions between preregistered modules
HippyModuleData *moduleData = moduleDataByName[moduleName];
if (moduleData) {
HippyLogError(@"Attempted to register HippyBridgeModule class %@ for the "
HippyLogWarn(@"Attempted to register HippyBridgeModule class %@ for the "
"name '%@', but name was already registered by class %@",
moduleClass, moduleName, moduleData.moduleClass);
continue;
Expand All @@ -202,7 +202,7 @@ - (void)setupModulesCompletion:(dispatch_block_t)completion {
continue;
} else if ([moduleData.moduleClass new] != nil) {
// Both modules were non-nil, so it's unclear which should take precedence
HippyLogError(@"Attempted to register HippyBridgeModule class %@ for the "
HippyLogWarn(@"Attempted to register HippyBridgeModule class %@ for the "
"name '%@', but name was already registered by class %@",
moduleClass, moduleName, moduleData.moduleClass);
}
Expand Down
4 changes: 2 additions & 2 deletions framework/ios/utils/NSObject+CtxValue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#import "NSObject+CtxValue.h"
#import "HippyAsserts.h"

#import "HippyLog.h"
#include "driver/napi/js_ctx.h"
#include "driver/napi/js_ctx_value.h"
#include "footstone/string_view.h"
Expand All @@ -32,7 +32,7 @@ @implementation NSObject (CtxValue)

- (CtxValuePtr)convertToCtxValue:(const CtxPtr &)context; {
@autoreleasepool {
HippyAssert(NO, @"%@ must implemente convertToCtxValue method", NSStringFromClass([self class]));
HippyLogWarn(@"%@ must implemente convertToCtxValue method", NSStringFromClass([self class]));
std::unordered_map<CtxValuePtr, CtxValuePtr> valueMap;
return context->CreateObject(valueMap);
}
Expand Down
18 changes: 16 additions & 2 deletions modules/ios/base/HippyLog.mm
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ void HippyAddLogFunction(HippyLogFunction logFunction) {
}
}

/**
* returns the topmost stacked log function for the current thread, which
* may not be the same as the current value of HippyCurrentLogFunction.
*/
static HippyLogFunction HippyGetLocalLogFunction() {
NSMutableDictionary *threadDictionary = [NSThread currentThread].threadDictionary;
NSArray<HippyLogFunction> *functionStack = threadDictionary[HippyLogFunctionStack];
HippyLogFunction logFunction = functionStack.lastObject;
if (logFunction) {
return logFunction;
}
return HippyGetLogFunction();
}

void HippyPerformBlockWithLogFunction(void (^block)(void), HippyLogFunction logFunction) {
NSMutableDictionary *threadDictionary = [NSThread currentThread].threadDictionary;
NSMutableArray<HippyLogFunction> *functionStack = threadDictionary[HippyLogFunctionStack];
Expand All @@ -96,7 +110,7 @@ void HippyPerformBlockWithLogFunction(void (^block)(void), HippyLogFunction logF
}

void HippyPerformBlockWithLogPrefix(void (^block)(void), NSString *prefix) {
HippyLogFunction logFunction = HippyGetLogFunction();
HippyLogFunction logFunction = HippyGetLocalLogFunction();
if (logFunction) {
HippyPerformBlockWithLogFunction(block,
^(HippyLogLevel level, HippyLogSource source,
Expand Down Expand Up @@ -153,7 +167,7 @@ void HippyPerformBlockWithLogPrefix(void (^block)(void), NSString *prefix) {
}

void HippyLogNativeInternal(HippyLogLevel level, const char *fileName, int lineNumber, NSString *format, ...) {
HippyLogFunction logFunction = HippyGetLogFunction();
HippyLogFunction logFunction = HippyGetLocalLogFunction();
BOOL log = HIPPY_DEBUG || (logFunction != nil);
if (log && level >= HippyGetLogThreshold()) {
// Get message
Expand Down
Loading