diff --git a/NativeScript/runtime/Console.cpp b/NativeScript/runtime/Console.cpp index e3bed68e..b47b1c2c 100644 --- a/NativeScript/runtime/Console.cpp +++ b/NativeScript/runtime/Console.cpp @@ -39,6 +39,22 @@ void Console::AttachInspectorClient(v8_inspector::JsV8InspectorClient* aInspecto inspector = aInspector; } +void Console::SplitAndLogInChunks(std::string message) { + auto messageLength = message.length(); + int maxStringLength = 1000; // technically 1024, but let's have some room :) + + if (messageLength < maxStringLength) { + // print normally + Log("%s", message.c_str()); + } else { + // split into chunks + for (int i = 0; i < messageLength; i += maxStringLength) { + std::string messagePart = message.substr(i, maxStringLength); + Log("%s", messagePart.c_str()); + } + } +} + void Console::LogCallback(const FunctionCallbackInfo& args) { // TODO: implement 'forceLog' override option like android has, to force logs in prod if desired if (!RuntimeConfig.LogToSystemConsole) { @@ -66,7 +82,22 @@ void Console::LogCallback(const FunctionCallbackInfo& args) { ConsoleAPIType method = VerbosityToInspectorMethod(verbosityLevel); SendToDevToolsFrontEnd(method, args); std::string msgWithVerbosity = "CONSOLE " + verbosityLevelUpper + ": " + msgToLog; - Log("%s", msgWithVerbosity.c_str()); + + SplitAndLogInChunks(msgWithVerbosity); + // //Log("%s", msgWithVerbosity.c_str()); + // auto messageLength = msgWithVerbosity.length(); + // int maxStringLength = 1000; // technically 1024, but let's have some room :) + + // if (messageLength < maxStringLength) { + // // print normally + // Log("%s", msgWithVerbosity.c_str()); + // } else { + // // split into chunks + // for (int i = 0; i < messageLength; i += maxStringLength) { + // std::string messagePart = msgWithVerbosity.substr(i, maxStringLength); + // Log("%s", messagePart.c_str()); + // } + // } } void Console::AssertCallback(const FunctionCallbackInfo& args) { @@ -92,7 +123,9 @@ void Console::AssertCallback(const FunctionCallbackInfo& args) { std::string log = ss.str(); SendToDevToolsFrontEnd(ConsoleAPIType::kAssert, args); - Log("%s", log.c_str()); + + SplitAndLogInChunks(log); + // Log("%s", log.c_str()); } } @@ -163,7 +196,8 @@ void Console::DirCallback(const FunctionCallbackInfo& args) { std::string msgToLog = ss.str(); SendToDevToolsFrontEnd(ConsoleAPIType::kDir, args); - Log("%s", msgToLog.c_str()); + SplitAndLogInChunks(msgToLog); + // Log("%s", msgToLog.c_str()); } void Console::TimeCallback(const FunctionCallbackInfo& args) { @@ -224,7 +258,8 @@ void Console::TimeEndCallback(const FunctionCallbackInfo& args) { std::string msgToLog = ss.str(); SendToDevToolsFrontEnd(isolate, ConsoleAPIType::kTimeEnd, msgToLog); - Log("%s", msgToLog.c_str()); + SplitAndLogInChunks(msgToLog); + // Log("%s", msgToLog.c_str()); } void Console::AttachLogFunction(Local context, Local console, const std::string name, v8::FunctionCallback callback) { diff --git a/NativeScript/runtime/Console.h b/NativeScript/runtime/Console.h index 9ce0539c..bc2e60af 100644 --- a/NativeScript/runtime/Console.h +++ b/NativeScript/runtime/Console.h @@ -15,6 +15,7 @@ class Console { using ConsoleAPIType = v8_inspector::ConsoleAPIType; static void AttachLogFunction(v8::Local context, v8::Local console, const std::string name, v8::FunctionCallback callback = Console::LogCallback); + static void SplitAndLogInChunks(std::string message); static void LogCallback(const v8::FunctionCallbackInfo& args); static void AssertCallback(const v8::FunctionCallbackInfo& args); static void DirCallback(const v8::FunctionCallbackInfo& args);