From a621408b9ceda8d9577b3aa46ce59b8c38f5ac67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=97=B1=20PixelyIon?= Date: Thu, 18 Feb 2021 11:46:26 +0000 Subject: [PATCH] Move to using ASCII separators for Logger We've moved to using RS and GS from ASCII as delimiters rather than '\n' and '|', this allows more robust parsing and increases the readability of the log files --- app/src/main/cpp/skyline/common.cpp | 12 ++++-------- app/src/main/cpp/skyline/common.h | 17 ++++++----------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/app/src/main/cpp/skyline/common.cpp b/app/src/main/cpp/skyline/common.cpp index 800084f8..76fd1d30 100644 --- a/app/src/main/cpp/skyline/common.cpp +++ b/app/src/main/cpp/skyline/common.cpp @@ -36,11 +36,11 @@ namespace skyline { __android_log_write(ANDROID_LOG_INFO, "emu-cpp", str.c_str()); std::lock_guard guard(mtx); - logFile << "0|" << str << "\n"; + logFile << "\0360\035" << str << '\n'; } - void Logger::Write(LogLevel level, std::string str) { - constexpr std::array levelCharacter{'0', '1', '2', '3', '4'}; // The LogLevel as written out to a file + void Logger::Write(LogLevel level, const std::string& str) { + constexpr std::array levelCharacter{'E', 'W', 'I', 'D', 'V'}; // The LogLevel as written out to a file constexpr std::array levelAlog{ANDROID_LOG_ERROR, ANDROID_LOG_WARN, ANDROID_LOG_INFO, ANDROID_LOG_DEBUG, ANDROID_LOG_VERBOSE}; // This corresponds to LogLevel and provides it's equivalent for NDK Logging if (logTag.empty()) @@ -48,12 +48,8 @@ namespace skyline { __android_log_write(levelAlog[static_cast(level)], logTag.c_str(), str.c_str()); - for (auto &character : str) - if (character == '\n') - character = '\\'; - std::lock_guard guard(mtx); - logFile << "1|" << levelCharacter[static_cast(level)] << '|' << threadName << '|' << str << '\n'; + logFile << "\0361\035" << levelCharacter[static_cast(level)] << '\035' << threadName << '\035' << str << '\n'; // We use RS (\036) and GS (\035) as our delimiters } DeviceState::DeviceState(kernel::OS *os, std::shared_ptr jvmManager, std::shared_ptr settings, std::shared_ptr logger) diff --git a/app/src/main/cpp/skyline/common.h b/app/src/main/cpp/skyline/common.h index e9be34e3..75b9fe63 100644 --- a/app/src/main/cpp/skyline/common.h +++ b/app/src/main/cpp/skyline/common.h @@ -430,41 +430,36 @@ namespace skyline { */ void WriteHeader(const std::string &str); - void Write(LogLevel level, std::string str); + void Write(LogLevel level, const std::string &str); template inline void Error(const S &formatStr, Args &&... args) { - if (LogLevel::Error <= configLevel) { + if (LogLevel::Error <= configLevel) Write(LogLevel::Error, fmt::format(formatStr, util::FmtCast(args)...)); - } } template inline void Warn(const S &formatStr, Args &&... args) { - if (LogLevel::Warn <= configLevel) { + if (LogLevel::Warn <= configLevel) Write(LogLevel::Warn, fmt::format(formatStr, util::FmtCast(args)...)); - } } template inline void Info(const S &formatStr, Args &&... args) { - if (LogLevel::Info <= configLevel) { + if (LogLevel::Info <= configLevel) Write(LogLevel::Info, fmt::format(formatStr, util::FmtCast(args)...)); - } } template inline void Debug(const S &formatStr, Args &&... args) { - if (LogLevel::Debug <= configLevel) { + if (LogLevel::Debug <= configLevel) Write(LogLevel::Debug, fmt::format(formatStr, util::FmtCast(args)...)); - } } template inline void Verbose(const S &formatStr, Args &&... args) { - if (LogLevel::Verbose <= configLevel) { + if (LogLevel::Verbose <= configLevel) Write(LogLevel::Verbose, fmt::format(formatStr, util::FmtCast(args)...)); - } } };