diff --git a/impeller/base/validation.cc b/impeller/base/validation.cc index d95a84c811c89..ebba11852489c 100644 --- a/impeller/base/validation.cc +++ b/impeller/base/validation.cc @@ -33,11 +33,12 @@ ScopedValidationFatal::~ScopedValidationFatal() { sValidationLogsAreFatal--; } -ValidationLog::ValidationLog() = default; +ValidationLog::ValidationLog(const char* file, int line) + : file_(file), line_(line) {} ValidationLog::~ValidationLog() { if (sValidationLogsDisabledCount <= 0) { - ImpellerValidationBreak(stream_.str().c_str()); + ImpellerValidationBreak(stream_.str().c_str(), file_, line_); } } @@ -45,19 +46,17 @@ std::ostream& ValidationLog::GetStream() { return stream_; } -void ImpellerValidationBreak(const char* message) { - std::stringstream stream; +void ImpellerValidationBreak(const char* message, const char* file, int line) { + const auto severity = + ImpellerValidationErrorsAreFatal() ? fml::LOG_FATAL : fml::LOG_ERROR; + auto fml_log = fml::LogMessage{severity, file, line, nullptr}; + fml_log.stream() << #if FLUTTER_RELEASE - stream << "Impeller validation: " << message; -#else - stream << "Break on '" << __FUNCTION__ - << "' to inspect point of failure: " << message; -#endif - if (sValidationLogsAreFatal > 0) { - FML_LOG(FATAL) << stream.str(); - } else { - FML_LOG(ERROR) << stream.str(); - } + "Impeller validation: " << message; +#else // FLUTTER_RELEASE + "Break on '" << __FUNCTION__ + << "' to inspect point of failure: " << message; +#endif // FLUTTER_RELEASE } bool ImpellerValidationErrorsAreFatal() { diff --git a/impeller/base/validation.h b/impeller/base/validation.h index 6d3ca3a52d19f..47ef7c20fc559 100644 --- a/impeller/base/validation.h +++ b/impeller/base/validation.h @@ -11,13 +11,15 @@ namespace impeller { class ValidationLog { public: - ValidationLog(); + ValidationLog(const char* file, int line); ~ValidationLog(); std::ostream& GetStream(); private: + const char* file_ = nullptr; + int line_ = 0; std::ostringstream stream_; ValidationLog(const ValidationLog&) = delete; @@ -29,7 +31,7 @@ class ValidationLog { ValidationLog& operator=(ValidationLog&&) = delete; }; -void ImpellerValidationBreak(const char* message); +void ImpellerValidationBreak(const char* message, const char* file, int line); void ImpellerValidationErrorsSetFatal(bool fatal); @@ -70,6 +72,6 @@ struct ScopedValidationFatal { /// are fatal. The runtime-mode restriction still applies. This usually /// happens in test environments. /// -#define VALIDATION_LOG ::impeller::ValidationLog{}.GetStream() +#define VALIDATION_LOG ::impeller::ValidationLog{__FILE__, __LINE__}.GetStream() #endif // FLUTTER_IMPELLER_BASE_VALIDATION_H_