[Impeller] Validation logs indicate where in code the validation error happened. (flutter/engine#53784)
Earlier, all validation logs originated from validation.cc which was not useful at all since you had to find the string in the source.
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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_
|
||||
|
||||
Reference in New Issue
Block a user