Skip to content

Instantly share code, notes, and snippets.

@adamjs
Created October 16, 2019 06:36
Show Gist options
  • Save adamjs/c111817b85b1aa05dc28944550497c59 to your computer and use it in GitHub Desktop.
Save adamjs/c111817b85b1aa05dc28944550497c59 to your computer and use it in GitHub Desktop.
// Inside Tab.cpp, replace your void Tab::OnAddConsoleMessage definition with all of the following:
inline std::string ToUTF8(const String& str) {
String8 utf8 = str.utf8();
return std::string(utf8.data(), utf8.length());
}
inline const char* Stringify(MessageSource source) {
switch(source) {
case kMessageSource_XML: return "XML";
case kMessageSource_JS: return "JS";
case kMessageSource_Network: return "Network";
case kMessageSource_ConsoleAPI: return "ConsoleAPI";
case kMessageSource_Storage: return "Storage";
case kMessageSource_AppCache: return "AppCache";
case kMessageSource_Rendering: return "Rendering";
case kMessageSource_CSS: return "CSS";
case kMessageSource_Security: return "Security";
case kMessageSource_ContentBlocker: return "ContentBlocker";
case kMessageSource_Other: return "Other";
default: return "";
}
}
inline const char* Stringify(MessageLevel level) {
switch(level) {
case kMessageLevel_Log: return "Log";
case kMessageLevel_Warning: return "Warning";
case kMessageLevel_Error: return "Error";
case kMessageLevel_Debug: return "Debug";
case kMessageLevel_Info: return "Info";
default: return "";
}
}
void Tab::OnAddConsoleMessage(View* caller,
MessageSource source,
MessageLevel level,
const String& message,
uint32_t line_number,
uint32_t column_number,
const String& source_id) {
std::cout << "[Tab #" << id_ << "] [" << Stringify(source) << "] [" << Stringify(level) <<
"] " << ToUTF8(message);
if (source == kMessageSource_JS)
std::cout << " (" << ToUTF8(source_id) << " @ line " << line_number << ", col " << column_number << ")";
std::cout << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment