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
This commit is contained in:
◱ PixelyIon 2021-02-18 11:46:26 +00:00 committed by ◱ Mark
parent 31db70f1d4
commit a621408b9c
2 changed files with 10 additions and 19 deletions

View File

@ -36,11 +36,11 @@ namespace skyline {
__android_log_write(ANDROID_LOG_INFO, "emu-cpp", str.c_str()); __android_log_write(ANDROID_LOG_INFO, "emu-cpp", str.c_str());
std::lock_guard guard(mtx); std::lock_guard guard(mtx);
logFile << "0|" << str << "\n"; logFile << "\0360\035" << str << '\n';
} }
void Logger::Write(LogLevel level, std::string str) { void Logger::Write(LogLevel level, const std::string& str) {
constexpr std::array<char, 5> levelCharacter{'0', '1', '2', '3', '4'}; // The LogLevel as written out to a file constexpr std::array<char, 5> levelCharacter{'E', 'W', 'I', 'D', 'V'}; // The LogLevel as written out to a file
constexpr std::array<int, 5> 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 constexpr std::array<int, 5> 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()) if (logTag.empty())
@ -48,12 +48,8 @@ namespace skyline {
__android_log_write(levelAlog[static_cast<u8>(level)], logTag.c_str(), str.c_str()); __android_log_write(levelAlog[static_cast<u8>(level)], logTag.c_str(), str.c_str());
for (auto &character : str)
if (character == '\n')
character = '\\';
std::lock_guard guard(mtx); std::lock_guard guard(mtx);
logFile << "1|" << levelCharacter[static_cast<u8>(level)] << '|' << threadName << '|' << str << '\n'; logFile << "\0361\035" << levelCharacter[static_cast<u8>(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> jvmManager, std::shared_ptr<Settings> settings, std::shared_ptr<Logger> logger) DeviceState::DeviceState(kernel::OS *os, std::shared_ptr<JvmManager> jvmManager, std::shared_ptr<Settings> settings, std::shared_ptr<Logger> logger)

View File

@ -430,41 +430,36 @@ namespace skyline {
*/ */
void WriteHeader(const std::string &str); void WriteHeader(const std::string &str);
void Write(LogLevel level, std::string str); void Write(LogLevel level, const std::string &str);
template<typename S, typename... Args> template<typename S, typename... Args>
inline void Error(const S &formatStr, Args &&... args) { 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)...)); Write(LogLevel::Error, fmt::format(formatStr, util::FmtCast(args)...));
}
} }
template<typename S, typename... Args> template<typename S, typename... Args>
inline void Warn(const S &formatStr, Args &&... args) { 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)...)); Write(LogLevel::Warn, fmt::format(formatStr, util::FmtCast(args)...));
}
} }
template<typename S, typename... Args> template<typename S, typename... Args>
inline void Info(const S &formatStr, Args &&... args) { 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)...)); Write(LogLevel::Info, fmt::format(formatStr, util::FmtCast(args)...));
}
} }
template<typename S, typename... Args> template<typename S, typename... Args>
inline void Debug(const S &formatStr, Args &&... args) { 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)...)); Write(LogLevel::Debug, fmt::format(formatStr, util::FmtCast(args)...));
}
} }
template<typename S, typename... Args> template<typename S, typename... Args>
inline void Verbose(const S &formatStr, Args &&... args) { 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)...)); Write(LogLevel::Verbose, fmt::format(formatStr, util::FmtCast(args)...));
}
} }
}; };