Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions NativeScript/runtime/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value>& args) {
// TODO: implement 'forceLog' override option like android has, to force logs in prod if desired
if (!RuntimeConfig.LogToSystemConsole) {
Expand Down Expand Up @@ -66,7 +82,22 @@ void Console::LogCallback(const FunctionCallbackInfo<Value>& 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<Value>& args) {
Expand All @@ -92,7 +123,9 @@ void Console::AssertCallback(const FunctionCallbackInfo<Value>& args) {
std::string log = ss.str();

SendToDevToolsFrontEnd(ConsoleAPIType::kAssert, args);
Log("%s", log.c_str());

SplitAndLogInChunks(log);
// Log("%s", log.c_str());
}
}

Expand Down Expand Up @@ -163,7 +196,8 @@ void Console::DirCallback(const FunctionCallbackInfo<Value>& 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<Value>& args) {
Expand Down Expand Up @@ -224,7 +258,8 @@ void Console::TimeEndCallback(const FunctionCallbackInfo<Value>& 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> context, Local<Object> console, const std::string name, v8::FunctionCallback callback) {
Expand Down
1 change: 1 addition & 0 deletions NativeScript/runtime/Console.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Console {
using ConsoleAPIType = v8_inspector::ConsoleAPIType;

static void AttachLogFunction(v8::Local<v8::Context> context, v8::Local<v8::Object> console, const std::string name, v8::FunctionCallback callback = Console::LogCallback);
static void SplitAndLogInChunks(std::string message);
static void LogCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
static void AssertCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
static void DirCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down