Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit eb1368e

Browse files
committed
feat: split long logs into multiple instead of truncating
1 parent 3f4abd1 commit eb1368e

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

‎NativeScript/runtime/Console.cpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
3753
void 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

6798
void 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

167201
void 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

231266
void Console::AttachLogFunction(Local<Context> context, Local<Object> console, const std::string name, v8::FunctionCallback callback) {

‎NativeScript/runtime/Console.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Console {
1111
static void Init(v8::Local<v8::Context> context);
1212
private:
1313
static void AttachLogFunction(v8::Local<v8::Context> context, v8::Local<v8::Object> console, const std::string name, v8::FunctionCallback callback = Console::LogCallback);
14+
static void SplitAndLogInChunks(std::string message);
1415
static void LogCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
1516
static void AssertCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
1617
static void DirCallback(const v8::FunctionCallbackInfo<v8::Value>& args);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /