@@ -34,6 +34,22 @@ void Console::Init(Local<Context> context) {
3434 }
3535}
3636
37+ void Console::SplitAndLogInChunks (std::string message) {
38+ auto messageLength = message.length ();
39+ int maxStringLength = 1000 ; // technically 1024, but let's have some room :)
40+
41+ if (messageLength < maxStringLength) {
42+ // print normally
43+ Log (" %s" , message.c_str ());
44+ } else {
45+ // split into chunks
46+ for (int i = 0 ; i < messageLength; i += maxStringLength) {
47+ std::string messagePart = message.substr (i, maxStringLength);
48+ Log (" %s" , messagePart.c_str ());
49+ }
50+ }
51+ }
52+
3753void Console::LogCallback (const FunctionCallbackInfo<Value>& args) {
3854 // TODO: implement 'forceLog' override option like android has, to force logs in prod if desired
3955 if (!RuntimeConfig.LogToSystemConsole ) {
@@ -61,7 +77,22 @@ void Console::LogCallback(const FunctionCallbackInfo<Value>& args) {
6177 std::string level = VerbosityToInspectorVerbosity (verbosityLevel);
6278 v8_inspector::V8LogAgentImpl::EntryAdded (msgToLog, level, " " , 0 );
6379 std::string msgWithVerbosity = " CONSOLE " + verbosityLevelUpper + " : " + msgToLog;
64- Log (" %s" , msgWithVerbosity.c_str ());
80+
81+ SplitAndLogInChunks (msgWithVerbosity);
82+ // //Log("%s", msgWithVerbosity.c_str());
83+ // auto messageLength = msgWithVerbosity.length();
84+ // int maxStringLength = 1000; // technically 1024, but let's have some room :)
85+
86+ // if (messageLength < maxStringLength) {
87+ // // print normally
88+ // Log("%s", msgWithVerbosity.c_str());
89+ // } else {
90+ // // split into chunks
91+ // for (int i = 0; i < messageLength; i += maxStringLength) {
92+ // std::string messagePart = msgWithVerbosity.substr(i, maxStringLength);
93+ // Log("%s", messagePart.c_str());
94+ // }
95+ // }
6596}
6697
6798void Console::AssertCallback (const FunctionCallbackInfo<Value>& args) {
@@ -86,7 +117,9 @@ void Console::AssertCallback(const FunctionCallbackInfo<Value>& args) {
86117
87118 std::string log = ss.str ();
88119 v8_inspector::V8LogAgentImpl::EntryAdded (log, " error" , " " , 0 );
89- Log (" %s" , log.c_str ());
120+
121+ SplitAndLogInChunks (log);
122+ // Log("%s", log.c_str());
90123 }
91124}
92125
@@ -161,7 +194,8 @@ void Console::DirCallback(const FunctionCallbackInfo<Value>& args) {
161194 std::string verbosityLevel = tns::ToString (isolate, data);
162195 std::string level = VerbosityToInspectorVerbosity (verbosityLevel);
163196 v8_inspector::V8LogAgentImpl::EntryAdded (msgToLog, level, " " , 0 );
164- Log (" %s" , msgToLog.c_str ());
197+ SplitAndLogInChunks (msgToLog);
198+ // Log("%s", msgToLog.c_str());
165199}
166200
167201void Console::TimeCallback (const FunctionCallbackInfo<Value>& args) {
@@ -225,7 +259,8 @@ void Console::TimeEndCallback(const FunctionCallbackInfo<Value>& args) {
225259 std::string level = VerbosityToInspectorVerbosity (verbosityLevel);
226260 std::string msgToLog = ss.str ();
227261 v8_inspector::V8LogAgentImpl::EntryAdded (msgToLog, level, " " , 0 );
228- Log (" %s" , msgToLog.c_str ());
262+ SplitAndLogInChunks (msgToLog);
263+ // Log("%s", msgToLog.c_str());
229264}
230265
231266void Console::AttachLogFunction (Local<Context> context, Local<Object> console, const std::string name, v8::FunctionCallback callback) {
0 commit comments