Logging: Add customizable logging backends and fmtlib based macros
* Change the logging backend to support multiple sinks through the Backend Interface * Add a new set of logging macros to use fmtlib instead. * Qt: Compile as GUI application on windows to make the console hidden by default. Add filter configuration and a button to open log location. * SDL: Migrate to the new logging macros
This commit is contained in:
parent
3cda637cb1
commit
0daac3020e
25 changed files with 527 additions and 140 deletions
|
@ -18,50 +18,26 @@
|
|||
|
||||
namespace Log {
|
||||
|
||||
// TODO(bunnei): This should be moved to a generic path manipulation library
|
||||
const char* TrimSourcePath(const char* path, const char* root) {
|
||||
const char* p = path;
|
||||
|
||||
while (*p != '\0') {
|
||||
const char* next_slash = p;
|
||||
while (*next_slash != '\0' && *next_slash != '/' && *next_slash != '\\') {
|
||||
++next_slash;
|
||||
}
|
||||
|
||||
bool is_src = Common::ComparePartialString(p, next_slash, root);
|
||||
p = next_slash;
|
||||
|
||||
if (*p != '\0') {
|
||||
++p;
|
||||
}
|
||||
if (is_src) {
|
||||
path = p;
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len) {
|
||||
std::string FormatLogMessage(const Entry& entry) {
|
||||
unsigned int time_seconds = static_cast<unsigned int>(entry.timestamp.count() / 1000000);
|
||||
unsigned int time_fractional = static_cast<unsigned int>(entry.timestamp.count() % 1000000);
|
||||
|
||||
const char* class_name = GetLogClassName(entry.log_class);
|
||||
const char* level_name = GetLevelName(entry.log_level);
|
||||
|
||||
snprintf(out_text, text_len, "[%4u.%06u] %s <%s> %s: %s", time_seconds, time_fractional,
|
||||
class_name, level_name, TrimSourcePath(entry.location.c_str()), entry.message.c_str());
|
||||
return fmt::format("[{:4d}.{:06d}] {} <{}> {}:{}:{}: {}", time_seconds, time_fractional,
|
||||
class_name, level_name, entry.filename, entry.function, entry.line_num,
|
||||
entry.message);
|
||||
}
|
||||
|
||||
void PrintMessage(const Entry& entry) {
|
||||
std::array<char, 4 * 1024> format_buffer;
|
||||
FormatLogMessage(entry, format_buffer.data(), format_buffer.size());
|
||||
fputs(format_buffer.data(), stderr);
|
||||
fputc('\n', stderr);
|
||||
auto str = FormatLogMessage(entry) + "\n";
|
||||
fputs(str.c_str(), stderr);
|
||||
}
|
||||
|
||||
void PrintColoredMessage(const Entry& entry) {
|
||||
#ifdef _WIN32
|
||||
static HANDLE console_handle = GetStdHandle(STD_ERROR_HANDLE);
|
||||
HANDLE console_handle = GetStdHandle(STD_ERROR_HANDLE);
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO original_info = {0};
|
||||
GetConsoleScreenBufferInfo(console_handle, &original_info);
|
||||
|
@ -129,4 +105,4 @@ void PrintColoredMessage(const Entry& entry) {
|
|||
#undef ESC
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // namespace Log
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue