Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Unified Diff: src/base/logging.cc

Issue 891693002: [base] Further improve the logging facility. Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/base/logging.h ('K') | « src/base/logging.h ('k') | src/checks.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/base/logging.cc
diff --git a/src/base/logging.cc b/src/base/logging.cc
index 25d77bb1ec1dc9b9e9e84e3ac2460eb689ac088f..04d6ea0ae316c14223befb7ea4d6276609d88a09 100644
--- a/src/base/logging.cc
+++ b/src/base/logging.cc
@@ -18,6 +18,7 @@
namespace v8 {
namespace base {
+namespace logging {
// Explicit instantiations for commonly used comparisons.
#define DEFINE_MAKE_CHECK_OP_STRING(type) \
@@ -35,11 +36,11 @@ DEFINE_MAKE_CHECK_OP_STRING(void const*)
// Explicit instantiations for floating point checks.
-#define DEFINE_CHECK_OP_IMPL(NAME) \
- template std::string* Check##NAME##Impl<float, float>( \
- float const& lhs, float const& rhs, char const* msg); \
- template std::string* Check##NAME##Impl<double, double>( \
- double const& lhs, double const& rhs, char const* msg);
+#define DEFINE_CHECK_OP_IMPL(NAME) \
+ template std::string* Check##NAME##Impl<float, float>( \
+ float const& lhs, float const& rhs, char const* result); \
+ template std::string* Check##NAME##Impl<double, double>( \
+ double const& lhs, double const& rhs, char const* result);
DEFINE_CHECK_OP_IMPL(EQ)
DEFINE_CHECK_OP_IMPL(NE)
DEFINE_CHECK_OP_IMPL(LE)
@@ -49,7 +50,34 @@ DEFINE_CHECK_OP_IMPL(GT)
#undef DEFINE_CHECK_OP_IMPL
+LogMessage::LogMessage(char const* file, int line, LogSeverity severity)
+ : file_(file), line_(line), severity_(severity) {}
+
+
+LogMessage::LogMessage(char const* file, int line, std::string* result)
+ : LogMessage(file, line, LOG_FATAL, result) {}
+
+
+LogMessage::LogMessage(char const* file, int line, LogSeverity severity,
+ std::string* result)
+ : LogMessage(file, line, severity) {
+ stream() << "Check failed: " << *result;
+ delete result;
+}
+
+
+LogMessage::~LogMessage() {
+ if (severity_ == LOG_FATAL) {
+ V8_Fatal(file_, line_, "%s", stream_.str().c_str());
+ }
+ OS::Print("%s\n", stream_.str().c_str());
+}
+
+
+namespace {
+
// Attempts to dump a backtrace (if supported).
+// TODO(bmeurer): Inline this thing into the caller!
void DumpBacktrace() {
#if V8_LIBC_GLIBC || V8_OS_BSD
void* trace[100];
@@ -99,6 +127,9 @@ void DumpBacktrace() {
#endif // V8_LIBC_GLIBC || V8_OS_BSD
}
+} // namespace
+
+} // namespace logging
} // namespace base
} // namespace v8
@@ -114,7 +145,7 @@ extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) {
v8::base::OS::VPrintError(format, arguments);
va_end(arguments);
v8::base::OS::PrintError("\n#\n");
- v8::base::DumpBacktrace();
+ v8::base::logging::DumpBacktrace();
fflush(stderr);
v8::base::OS::Abort();
}
« src/base/logging.h ('K') | « src/base/logging.h ('k') | src/checks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698