1
1
#include " SymbolLoader.h"
2
2
#include < Foundation/Foundation.h>
3
3
#include < dlfcn.h>
4
- #include " Helpers.h "
4
+ #include < os/log.h >
5
5
6
6
namespace tns {
7
7
8
+ // Unified logging: create a dedicated log for the SymbolLoader
9
+ static os_log_t ns_symbolloader_log () {
10
+ // Function-local static initialization is thread-safe in C++11+.
11
+ static os_log_t log = os_log_create (" @nativescript/ios" , " SymbolLoader" );
12
+ return log;
13
+ }
14
+
8
15
class SymbolResolver {
9
16
public:
10
17
virtual void * loadFunctionSymbol (const char * symbolName) = 0;
@@ -37,7 +44,7 @@ virtual bool load() override {
37
44
CFErrorRef error = nullptr ;
38
45
bool loaded = CFBundleLoadExecutableAndReturnError (this ->_bundle , &error);
39
46
if (error) {
40
- Log ( " % s" , [[(NSError *)error localizedDescription ] UTF8String ]);
47
+ os_log_error ( ns_symbolloader_log (), " %{public} s" , [[(NSError *)error localizedDescription ] UTF8String ]);
41
48
}
42
49
43
50
return loaded;
@@ -101,8 +108,6 @@ virtual bool load() override {
101
108
NSURL * bundleUrl = [NSURL URLWithString: frameworkPathStr relativeToURL: baseUrl];
102
109
if (CFBundleRef bundle = CFBundleCreate (kCFAllocatorDefault , (CFURLRef)bundleUrl)) {
103
110
resolver = std::make_unique<CFBundleSymbolResolver>(bundle);
104
- } else {
105
- Log (" NativeScript could not load bundle %s" , bundleUrl.absoluteString .UTF8String );
106
111
}
107
112
} else if (module ->libraries ->count == 1 ) {
108
113
if (module ->isSystem ()) {
@@ -113,11 +118,9 @@ virtual bool load() override {
113
118
module ->libraries->first ()->value ().getName ()];
114
119
115
120
if (void * library = dlopen (libraryPath.UTF8String , RTLD_LAZY | RTLD_LOCAL)) {
116
- Log (" NativeScript loaded library %s" , libraryPath.UTF8String );
117
121
resolver = std::make_unique<DlSymbolResolver>(library);
118
122
} else if (const char * libraryError = dlerror ()) {
119
- Log (" NativeScript could not load library %s, error: %s" , libraryPath.UTF8String ,
120
- libraryError);
123
+ os_log_debug (ns_symbolloader_log (), " NativeScript could not load library %{public}s, error: %{public}s" , libraryPath.UTF8String , libraryError);
121
124
}
122
125
}
123
126
}
0 commit comments