Skip to content

Commit 1d86313

Browse files
committed
feat(config): logRuntimeDetail boolean can toggle verbose runtime logs
1 parent fea46b2 commit 1d86313

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

NativeScript/runtime/Interop.mm

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,9 +1487,6 @@
14871487
// MARK: - Debug Messages for the runtime
14881488

14891489
void ExecuteWriteValueValidationsAndStopExecutionAndLogStackTrace(Local<Context> context, const TypeEncoding* typeEncoding, void* dest, Local<Value> arg) {
1490-
if (!RuntimeConfig.IsDebug) {
1491-
return;
1492-
}
14931490
Isolate* isolate = context->GetIsolate();
14941491
std::string destName = typeEncoding->details.interfaceDeclarationReference.name.valuePtr();
14951492
Local<Value> originArg = arg;
@@ -1524,32 +1521,35 @@ bool IsTypeEncondingHandldedByDebugMessages(const TypeEncoding* typeEncoding) {
15241521
}
15251522

15261523
void LogWriteValueTraceMessage(Local<Context> context, const TypeEncoding* typeEncoding, void* dest, Local<Value> arg) {
1527-
if (!RuntimeConfig.IsDebug) {
1528-
return;
1529-
}
15301524
Isolate* isolate = context->GetIsolate();
15311525
std::string destName = typeEncoding->details.interfaceDeclarationReference.name.valuePtr();
15321526
std::string originName = tns::ToString(isolate, arg);
15331527
if (originName == "") {
15341528
// empty string
15351529
originName = "\"\"";
15361530
}
1531+
// NOTE: stringWithFormat is slow, perhaps use different c string concatenation?
15371532
NSString* message = [NSString stringWithFormat:@"Interop::WriteValue: from {%s} to {%s}", originName.c_str(), destName.c_str()];
15381533
Log(@"%@", message);
15391534
}
15401535

15411536
void Interop::ExecuteWriteValueDebugValidationsIfInDebug(Local<Context> context, const TypeEncoding* typeEncoding, void* dest, Local<Value> arg) {
1537+
15421538
if (!RuntimeConfig.IsDebug) {
15431539
return;
15441540
}
1545-
if (arg.IsEmpty() || arg->IsNullOrUndefined()) {
1546-
return;
1547-
}
1548-
if (IsTypeEncondingHandldedByDebugMessages(typeEncoding)) {
1549-
return;
1541+
id value = Runtime::GetAppConfigValue("logRuntimeDetail");
1542+
bool logRuntimeDetail = value ? [value boolValue] : false;
1543+
if (logRuntimeDetail) {
1544+
if (arg.IsEmpty() || arg->IsNullOrUndefined()) {
1545+
return;
1546+
}
1547+
if (IsTypeEncondingHandldedByDebugMessages(typeEncoding)) {
1548+
return;
1549+
}
1550+
LogWriteValueTraceMessage(context, typeEncoding, dest, arg);
1551+
ExecuteWriteValueValidationsAndStopExecutionAndLogStackTrace(context, typeEncoding, dest, arg);
15501552
}
1551-
LogWriteValueTraceMessage(context, typeEncoding, dest, arg);
1552-
ExecuteWriteValueValidationsAndStopExecutionAndLogStackTrace(context, typeEncoding, dest, arg);
15531553
}
15541554

15551555
}

NativeScript/runtime/MetadataBuilder.mm

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Worker.h"
1212
#include "Caches.h"
1313
#include "Tasks.h"
14+
#include "Runtime.h"
1415
#include "RuntimeConfig.h"
1516

1617
using namespace v8;
@@ -812,13 +813,18 @@
812813
// TODO: Find out if the isMethodCallback property can be determined based on a UITableViewController.prototype.viewDidLoad.call(this) or super.viewDidLoad() call
813814

814815
if (RuntimeConfig.IsDebug) {
815-
NSString* message = [NSString stringWithFormat:@"MetadataBuilder::InvokeMethod class {%s}, selector {%s}, isInitializer {%s}, type {%s}, lib {%s}",
816-
containingClass.c_str(),
817-
meta->selectorAsString(),
818-
meta->isInitializer() ? "true":"false",
819-
meta->typeName(),
820-
meta->topLevelModule()->getName()];
821-
Log(@"%@", message);
816+
id value = Runtime::GetAppConfigValue("logRuntimeDetail");
817+
bool logRuntimeDetail = value ? [value boolValue] : false;
818+
if (logRuntimeDetail) {
819+
// NOTE: stringWithFormat is slow, perhaps use different c string concatenation?
820+
NSString* message = [NSString stringWithFormat:@"MetadataBuilder::InvokeMethod: class {%s}, selector {%s}, isInitializer {%s}, type {%s}, lib {%s}",
821+
containingClass.c_str(),
822+
meta->selectorAsString(),
823+
meta->isInitializer() ? "true":"false",
824+
meta->typeName(),
825+
meta->topLevelModule()->getName()];
826+
Log(@"%@", message);
827+
}
822828
}
823829

824830
try {

0 commit comments

Comments
 (0)