Skip to content

Commit 7101127

Browse files
authored
fix: symbol loader log true errors only to not confuse terminal output (#293)
1 parent 42a5328 commit 7101127

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

NativeScript/runtime/SymbolLoader.mm

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22
#include "SymbolLoader.h"
33
#include "Helpers.h"
44
#include <dlfcn.h>
5+
#include <os/log.h>
56

67
namespace tns {
78

9+
// Unified logging: create a dedicated log for the SymbolLoader
10+
static os_log_t ns_symbolloader_log() {
11+
// Function-local static initialization is thread-safe in C++11+.
12+
static os_log_t log = os_log_create("@nativescript/ios", "SymbolLoader");
13+
return log;
14+
}
15+
816
class SymbolResolver {
917
public:
1018
virtual void* loadFunctionSymbol(const char* symbolName) = 0;
@@ -35,7 +43,7 @@ virtual bool load() override {
3543
CFErrorRef error = nullptr;
3644
bool loaded = CFBundleLoadExecutableAndReturnError(this->_bundle, &error);
3745
if (error) {
38-
NSLog(@"%s", [[(NSError*)error localizedDescription] UTF8String]);
46+
os_log_error(ns_symbolloader_log(), "%{public}s", [[(NSError*)error localizedDescription] UTF8String]);
3947
}
4048

4149
return loaded;
@@ -100,8 +108,6 @@ virtual bool load() override {
100108
NSURL* bundleUrl = [NSURL URLWithString:frameworkPathStr relativeToURL:baseUrl];
101109
if (CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, (CFURLRef)bundleUrl)) {
102110
resolver = std::make_unique<CFBundleSymbolResolver>(bundle);
103-
} else {
104-
NSLog(@"NativeScript could not load bundle %s\n", bundleUrl.absoluteString.UTF8String);
105111
}
106112
} else if (module->libraries->count == 1) {
107113
if (module->isSystem()) {
@@ -110,10 +116,9 @@ virtual bool load() override {
110116
NSString* libraryPath = [NSString stringWithFormat:@"%@/lib%s.dylib", libsPath, module->libraries->first()->value().getName()];
111117

112118
if (void* library = dlopen(libraryPath.UTF8String, RTLD_LAZY | RTLD_LOCAL)) {
113-
NSLog(@"NativeScript loaded library %s\n", libraryPath.UTF8String);
114119
resolver = std::make_unique<DlSymbolResolver>(library);
115120
} else if (const char* libraryError = dlerror()) {
116-
NSLog(@"NativeScript could not load library %s, error: %s\n", libraryPath.UTF8String, libraryError);
121+
os_log_debug(ns_symbolloader_log(), "NativeScript could not load library %{public}s, error: %{public}s", libraryPath.UTF8String, libraryError);
117122
}
118123
}
119124
}

0 commit comments

Comments
 (0)