From ccffd51904fdc8642e4db9896bb0e16b4c2ed851 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Thu, 5 Sep 2019 23:05:16 +0800 Subject: [PATCH] Update logging system - Update to fmt 6.0.0 - Updated logging system to be macro based - Fixed a bug with including --- externals/fmt | 2 +- src/common/CMakeLists.txt | 1 + src/common/logging/log.cpp | 18 ++++++++++++++ src/common/logging/log.h | 51 +++++++++++++++++--------------------- src/core/inner_fat.h | 4 +-- 5 files changed, 45 insertions(+), 31 deletions(-) create mode 100644 src/common/logging/log.cpp diff --git a/externals/fmt b/externals/fmt index 5a4b246..7512a55 160000 --- a/externals/fmt +++ b/externals/fmt @@ -1 +1 @@ -Subproject commit 5a4b24613ba16cc689977c3b5bd8274a3ba1dd1f +Subproject commit 7512a55aa3ae309587ca89668ef9ec4074a51a1f diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index bc70cd6..d21a5eb 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -6,6 +6,7 @@ add_library(common STATIC common_types.h file_util.cpp file_util.h + logging/log.cpp logging/log.h misc.cpp scope_exit.h diff --git a/src/common/logging/log.cpp b/src/common/logging/log.cpp new file mode 100644 index 0000000..7881687 --- /dev/null +++ b/src/common/logging/log.cpp @@ -0,0 +1,18 @@ +// Copyright 2019 threeSD Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include "common/logging/log.h" +#include "common/string_util.h" + +std::uint64_t GetLoggingTime() { + static auto time_origin = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(std::chrono::steady_clock::now() - + time_origin) + .count(); +} + +std::string StandardizeLogClass(const std::string& log_class) { + return Common::ReplaceAll(log_class, "_", "."); +} diff --git a/src/common/logging/log.h b/src/common/logging/log.h index e982ed2..682ccdb 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h @@ -4,51 +4,46 @@ // This is simplified version of Citra's logging system. // Only stderr/stderr output is enabled and color is implemented -// for the UNIX-like. +// with fmt tools. #pragma once -#include #include -#include +#include #include -#include "common/string_util.h" -#include +std::uint64_t GetLoggingTime(); +std::string StandardizeLogClass(const std::string& log_class); -template -void PrintLog(std::FILE* f, const std::string& log_class, const std::string& level, - const std::string& color, const std::string& file, int line, const std::string& func, - const std::string& format, Args&&... args) { - static auto time_origin = std::chrono::steady_clock::now(); - const u64 us = std::chrono::duration_cast( - std::chrono::steady_clock::now() - time_origin) - .count(); - const auto real_class = Common::ReplaceAll(log_class, "_", "."); - try { - fmt::print(f, "\x1b{}[{:12.6f}] {} <{}> {}:{}:{}: " + format + "\x1b[0m\n", color, - us / 1000000.0, real_class, level, file, line, func, args...); - fflush(stderr); - } catch (...) { - std::cerr << "(unexpected) fmt failed with exception" << std::endl; +// TODO: Use a standard variant of ##__VA_ARGS__? +#define LOG_PRINT(log_class, level, text_style, file, line, func, format, ...) \ + { \ + fmt::print(stderr, text_style, "[{:12.6f}] {} <{}> {}:{}:{}: " format "\n", \ + GetLoggingTime() / 1000000.0, StandardizeLogClass(log_class), level, file, \ + line, func, ##__VA_ARGS__); \ + fflush(stderr); \ } -} #ifdef _DEBUG #define LOG_TRACE(log_class, ...) \ - (void(0)) // PrintLog(stderr, #log_class, "Trace", "[1;30m", __FILE__, __LINE__, __func__, - // __VA_ARGS__) + LOG_PRINT(#log_class, "Trace", fmt::fg(fmt::terminal_color::bright_black), __FILE__, __LINE__, \ + __func__, __VA_ARGS__) #else #define LOG_TRACE(log_class, fmt, ...) (void(0)) #endif #define LOG_DEBUG(log_class, ...) \ - PrintLog(stderr, #log_class, "Debug", "[0;36m", __FILE__, __LINE__, __func__, __VA_ARGS__) + LOG_PRINT(#log_class, "Debug", fmt::fg(fmt::terminal_color::cyan), __FILE__, __LINE__, \ + __func__, __VA_ARGS__) #define LOG_INFO(log_class, ...) \ - PrintLog(stderr, #log_class, "Info", "[0;37m", __FILE__, __LINE__, __func__, __VA_ARGS__) + LOG_PRINT(#log_class, "Info", fmt::fg(fmt::terminal_color::white), __FILE__, __LINE__, \ + __func__, __VA_ARGS__) #define LOG_WARNING(log_class, ...) \ - PrintLog(stderr, #log_class, "Warning", "[1;33m", __FILE__, __LINE__, __func__, __VA_ARGS__) + LOG_PRINT(#log_class, "Warning", fmt::fg(fmt::terminal_color::bright_yellow), __FILE__, \ + __LINE__, __func__, __VA_ARGS__) #define LOG_ERROR(log_class, ...) \ - PrintLog(stderr, #log_class, "Error", "[1;31m", __FILE__, __LINE__, __func__, __VA_ARGS__) + LOG_PRINT(#log_class, "Error", fmt::fg(fmt::terminal_color::bright_red), __FILE__, __LINE__, \ + __func__, __VA_ARGS__) #define LOG_CRITICAL(log_class, ...) \ - PrintLog(stderr, #log_class, "Critical", "[1;35m", __FILE__, __LINE__, __func__, __VA_ARGS__) + LOG_PRINT(#log_class, "Critical", fmt::fg(fmt::terminal_color::bright_magenta), __FILE__, \ + __LINE__, __func__, __VA_ARGS__) diff --git a/src/core/inner_fat.h b/src/core/inner_fat.h index b06fc73..8e876d0 100644 --- a/src/core/inner_fat.h +++ b/src/core/inner_fat.h @@ -4,8 +4,6 @@ #pragma once -namespace Core { - #include #include #include @@ -14,6 +12,8 @@ namespace Core { #include "common/common_types.h" #include "common/swap.h" +namespace Core { + class SDMCDecryptor; /// Parameters of the archive, as specified in the Create or Format call.