Skip to content

Commit 0055c99

Browse files
committed
fix: logging on macOS not working cause of os_log, use it only on ios
1 parent a0ed205 commit 0055c99

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

NativeScript/runtime/modules/console/Console.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ std::string transformJSObject(napi_env env, napi_value object) {
8989
return JsonStringifyObject(env, object, false);
9090
}
9191

92-
std::string buildStringFromArg(napi_env env, napi_value val, napi_value inspectSymbol) {
92+
std::string buildStringFromArg(napi_env env, napi_value val,
93+
napi_value inspectSymbol) {
9394
napi_valuetype type;
9495
napi_typeof(env, val, &type);
9596

@@ -118,7 +119,8 @@ std::string buildStringFromArg(napi_env env, napi_value val, napi_value inspectS
118119
if (isStrictEqual) {
119120
arrayStr << "[Circular]";
120121
} else {
121-
std::string elementString = buildStringFromArg(env, propertyValue, inspectSymbol);
122+
std::string elementString =
123+
buildStringFromArg(env, propertyValue, inspectSymbol);
122124
arrayStr << elementString;
123125
}
124126

@@ -131,8 +133,10 @@ std::string buildStringFromArg(napi_env env, napi_value val, napi_value inspectS
131133
return arrayStr.str();
132134
} else if (type == napi_object) {
133135
napi_value inspectFunc = nullptr;
134-
napi_status getInspectStatus = napi_get_property(env, val, inspectSymbol, &inspectFunc);
135-
if (getInspectStatus == napi_ok && napi_util::is_of_type(env, inspectFunc, napi_function)) {
136+
napi_status getInspectStatus =
137+
napi_get_property(env, val, inspectSymbol, &inspectFunc);
138+
if (getInspectStatus == napi_ok &&
139+
napi_util::is_of_type(env, inspectFunc, napi_function)) {
136140
napi_value inspectedValue;
137141
napi_call_function(env, val, inspectFunc, 0, nullptr, &inspectedValue);
138142
return buildStringFromArg(env, inspectedValue, inspectSymbol);
@@ -158,8 +162,9 @@ std::string buildLogString(napi_env env, napi_callback_info info,
158162
napi_get_named_property(env, global, "Symbol", &Symbol);
159163
napi_get_named_property(env, Symbol, "for", &SymbolFor);
160164
napi_create_string_utf8(env, "nodejs.util.inspect.custom", NAPI_AUTO_LENGTH,
161-
&symbolDescription);
162-
napi_call_function(env, global, SymbolFor, 1, &symbolDescription, &inspectSymbol);
165+
&symbolDescription);
166+
napi_call_function(env, global, SymbolFor, 1, &symbolDescription,
167+
&inspectSymbol);
163168

164169
std::stringstream ss;
165170

@@ -247,7 +252,9 @@ JS_METHOD(Console::Log) {
247252
std::string logString = log.str();
248253

249254
#ifdef __APPLE__
250-
#if TNS_HAVE_OS_LOG
255+
#if TARGET_OS_OSX
256+
NSLog(CFSTR("%s"), logString.c_str());
257+
#elif TNS_HAVE_OS_LOG
251258
os_log(OS_LOG_DEFAULT, "%{public}s", logString.c_str());
252259
#else
253260
NSLog(CFSTR("%s"), logString.c_str());

0 commit comments

Comments
 (0)