mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-15 16:16:08 +00:00
Namespace Log.h/cpp in dawn::
The LogMessage::LogMessage constructor was redefining a symbol that exists in re2 inside of Chromium. So we namespace Log inside dawn:: to avoid the conflict. BUG=dawn:302 Change-Id: Ida349208e2c6fe9ac032e1bd8cd442dff0b3f6bc Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14320 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
dd4584340d
commit
dc3317da6c
@@ -19,7 +19,7 @@ void HandleAssertionFailure(const char* file,
|
||||
const char* function,
|
||||
int line,
|
||||
const char* condition) {
|
||||
ErrorLog() << "Assertion failure at " << file << ":" << line << " (" << function
|
||||
<< "): " << condition;
|
||||
dawn::ErrorLog() << "Assertion failure at " << file << ":" << line << " (" << function
|
||||
<< "): " << condition;
|
||||
DAWN_BREAKPOINT();
|
||||
}
|
||||
|
||||
@@ -23,90 +23,94 @@
|
||||
# include <android/log.h>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
namespace dawn {
|
||||
|
||||
const char* SeverityName(LogSeverity severity) {
|
||||
switch (severity) {
|
||||
case LogSeverity::Debug:
|
||||
return "Debug";
|
||||
case LogSeverity::Info:
|
||||
return "Info";
|
||||
case LogSeverity::Warning:
|
||||
return "Warning";
|
||||
case LogSeverity::Error:
|
||||
return "Error";
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return "";
|
||||
namespace {
|
||||
|
||||
const char* SeverityName(LogSeverity severity) {
|
||||
switch (severity) {
|
||||
case LogSeverity::Debug:
|
||||
return "Debug";
|
||||
case LogSeverity::Info:
|
||||
return "Info";
|
||||
case LogSeverity::Warning:
|
||||
return "Warning";
|
||||
case LogSeverity::Error:
|
||||
return "Error";
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(DAWN_PLATFORM_ANDROID)
|
||||
android_LogPriority AndroidLogPriority(LogSeverity severity) {
|
||||
switch (severity) {
|
||||
case LogSeverity::Debug:
|
||||
return ANDROID_LOG_INFO;
|
||||
case LogSeverity::Info:
|
||||
return ANDROID_LOG_INFO;
|
||||
case LogSeverity::Warning:
|
||||
return ANDROID_LOG_WARN;
|
||||
case LogSeverity::Error:
|
||||
return ANDROID_LOG_ERROR;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return ANDROID_LOG_ERROR;
|
||||
android_LogPriority AndroidLogPriority(LogSeverity severity) {
|
||||
switch (severity) {
|
||||
case LogSeverity::Debug:
|
||||
return ANDROID_LOG_INFO;
|
||||
case LogSeverity::Info:
|
||||
return ANDROID_LOG_INFO;
|
||||
case LogSeverity::Warning:
|
||||
return ANDROID_LOG_WARN;
|
||||
case LogSeverity::Error:
|
||||
return ANDROID_LOG_ERROR;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return ANDROID_LOG_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // defined(DAWN_PLATFORM_ANDROID)
|
||||
|
||||
} // anonymous namespace
|
||||
} // anonymous namespace
|
||||
|
||||
LogMessage::LogMessage(LogSeverity severity) : mSeverity(severity) {
|
||||
}
|
||||
|
||||
LogMessage::~LogMessage() {
|
||||
std::string fullMessage = mStream.str();
|
||||
|
||||
// If this message has been moved, its stream is empty.
|
||||
if (fullMessage.empty()) {
|
||||
return;
|
||||
LogMessage::LogMessage(LogSeverity severity) : mSeverity(severity) {
|
||||
}
|
||||
|
||||
const char* severityName = SeverityName(mSeverity);
|
||||
LogMessage::~LogMessage() {
|
||||
std::string fullMessage = mStream.str();
|
||||
|
||||
FILE* outputStream = stdout;
|
||||
if (mSeverity == LogSeverity::Warning || mSeverity == LogSeverity::Error) {
|
||||
outputStream = stderr;
|
||||
}
|
||||
// If this message has been moved, its stream is empty.
|
||||
if (fullMessage.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char* severityName = SeverityName(mSeverity);
|
||||
|
||||
FILE* outputStream = stdout;
|
||||
if (mSeverity == LogSeverity::Warning || mSeverity == LogSeverity::Error) {
|
||||
outputStream = stderr;
|
||||
}
|
||||
|
||||
#if defined(DAWN_PLATFORM_ANDROID)
|
||||
android_LogPriority androidPriority = AndroidLogPriority(mSeverity);
|
||||
__android_log_print(androidPriority, "Dawn", "%s: %s\n", severityName, fullMessage.c_str());
|
||||
android_LogPriority androidPriority = AndroidLogPriority(mSeverity);
|
||||
__android_log_print(androidPriority, "Dawn", "%s: %s\n", severityName, fullMessage.c_str());
|
||||
#else // defined(DAWN_PLATFORM_ANDROID)
|
||||
// Note: we use fprintf because <iostream> includes static initializers.
|
||||
fprintf(outputStream, "%s: %s\n", severityName, fullMessage.c_str());
|
||||
fflush(outputStream);
|
||||
// Note: we use fprintf because <iostream> includes static initializers.
|
||||
fprintf(outputStream, "%s: %s\n", severityName, fullMessage.c_str());
|
||||
fflush(outputStream);
|
||||
#endif // defined(DAWN_PLATFORM_ANDROID)
|
||||
}
|
||||
}
|
||||
|
||||
LogMessage DebugLog() {
|
||||
return {LogSeverity::Debug};
|
||||
}
|
||||
LogMessage DebugLog() {
|
||||
return {LogSeverity::Debug};
|
||||
}
|
||||
|
||||
LogMessage InfoLog() {
|
||||
return {LogSeverity::Info};
|
||||
}
|
||||
LogMessage InfoLog() {
|
||||
return {LogSeverity::Info};
|
||||
}
|
||||
|
||||
LogMessage WarningLog() {
|
||||
return {LogSeverity::Warning};
|
||||
}
|
||||
LogMessage WarningLog() {
|
||||
return {LogSeverity::Warning};
|
||||
}
|
||||
|
||||
LogMessage ErrorLog() {
|
||||
return {LogSeverity::Error};
|
||||
}
|
||||
LogMessage ErrorLog() {
|
||||
return {LogSeverity::Error};
|
||||
}
|
||||
|
||||
LogMessage DebugLog(const char* file, const char* function, int line) {
|
||||
LogMessage message = DebugLog();
|
||||
message << file << ":" << line << "(" << function << ")";
|
||||
return message;
|
||||
}
|
||||
LogMessage DebugLog(const char* file, const char* function, int line) {
|
||||
LogMessage message = DebugLog();
|
||||
message << file << ":" << line << "(" << function << ")";
|
||||
return message;
|
||||
}
|
||||
|
||||
} // namespace dawn
|
||||
|
||||
@@ -45,46 +45,51 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
// Log levels mostly used to signal intent where the log message is produced and used to route the
|
||||
// message to the correct output.
|
||||
enum class LogSeverity {
|
||||
Debug,
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
};
|
||||
namespace dawn {
|
||||
|
||||
// Essentially an ostringstream that will print itself in its destructor.
|
||||
class LogMessage {
|
||||
public:
|
||||
LogMessage(LogSeverity severity);
|
||||
~LogMessage();
|
||||
// Log levels mostly used to signal intent where the log message is produced and used to route
|
||||
// the message to the correct output.
|
||||
enum class LogSeverity {
|
||||
Debug,
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
};
|
||||
|
||||
LogMessage(LogMessage&& other) = default;
|
||||
LogMessage& operator=(LogMessage&& other) = default;
|
||||
// Essentially an ostringstream that will print itself in its destructor.
|
||||
class LogMessage {
|
||||
public:
|
||||
LogMessage(LogSeverity severity);
|
||||
~LogMessage();
|
||||
|
||||
template <typename T>
|
||||
LogMessage& operator<<(T&& value) {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
LogMessage(LogMessage&& other) = default;
|
||||
LogMessage& operator=(LogMessage&& other) = default;
|
||||
|
||||
private:
|
||||
LogMessage(const LogMessage& other) = delete;
|
||||
LogMessage& operator=(const LogMessage& other) = delete;
|
||||
template <typename T>
|
||||
LogMessage& operator<<(T&& value) {
|
||||
mStream << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogSeverity mSeverity;
|
||||
std::ostringstream mStream;
|
||||
};
|
||||
private:
|
||||
LogMessage(const LogMessage& other) = delete;
|
||||
LogMessage& operator=(const LogMessage& other) = delete;
|
||||
|
||||
// Short-hands to create a LogMessage with the respective severity.
|
||||
LogMessage DebugLog();
|
||||
LogMessage InfoLog();
|
||||
LogMessage WarningLog();
|
||||
LogMessage ErrorLog();
|
||||
LogSeverity mSeverity;
|
||||
std::ostringstream mStream;
|
||||
};
|
||||
|
||||
// DAWN_DEBUG is a helper macro that creates a DebugLog and outputs file/line/function information
|
||||
LogMessage DebugLog(const char* file, const char* function, int line);
|
||||
#define DAWN_DEBUG() DebugLog(__FILE__, __func__, __LINE__)
|
||||
// Short-hands to create a LogMessage with the respective severity.
|
||||
LogMessage DebugLog();
|
||||
LogMessage InfoLog();
|
||||
LogMessage WarningLog();
|
||||
LogMessage ErrorLog();
|
||||
|
||||
// DAWN_DEBUG is a helper macro that creates a DebugLog and outputs file/line/function
|
||||
// information
|
||||
LogMessage DebugLog(const char* file, const char* function, int line);
|
||||
#define DAWN_DEBUG() ::dawn::DebugLog(__FILE__, __func__, __LINE__)
|
||||
|
||||
} // namespace dawn
|
||||
|
||||
#endif // COMMON_LOG_H_
|
||||
|
||||
Reference in New Issue
Block a user