Skip to content

Commit

Permalink
fix(ios): add missing error log and suppress some warning
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Oct 30, 2023
1 parent 61c41d8 commit 34c6693
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
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

0 comments on commit 34c6693

Please sign in to comment.