From feae2988d6bd461bed7646311f868382981c19d4 Mon Sep 17 00:00:00 2001 From: Raffarti Date: Tue, 23 Jan 2018 13:36:31 +0100 Subject: [PATCH] Improvements for log files (#22) * Improvements for log files - Added exec name to log files - Added DXVK_LOG_PATH environment variable to specify the log folder * Remove .exe from log name * log: add log level none * log: corrected type for string position --- src/util/log/log.cpp | 23 +++++++++++++++++++---- src/util/log/log.h | 3 ++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/util/log/log.cpp b/src/util/log/log.cpp index 1f8571e8..47ab5af2 100644 --- a/src/util/log/log.cpp +++ b/src/util/log/log.cpp @@ -5,8 +5,22 @@ namespace dxvk { Logger::Logger(const std::string& file_name) - : m_minLevel(getMinLogLevel()), - m_fileStream(file_name) { } + : m_minLevel(getMinLogLevel()) + { + if (m_minLevel == LogLevel::None) + return; + + std::string path = env::getEnvVar(L"DXVK_LOG_PATH"); + std::string file = path; + if (!file.empty() && *file.rbegin() != '/') + file += '/'; + std::string name = env::getExeName(); + auto extp = name.find_last_of('.'); + if (extp != std::string::npos && name.substr(extp +1) == "exe") + name.erase(extp); + file += name + "_"; + m_fileStream = std::ofstream(file + file_name); + } Logger::~Logger() { } @@ -53,12 +67,13 @@ namespace dxvk { LogLevel Logger::getMinLogLevel() { - const std::array, 5> logLevels = {{ + const std::array, 6> logLevels = {{ { "trace", LogLevel::Trace }, { "debug", LogLevel::Debug }, { "info", LogLevel::Info }, { "warn", LogLevel::Warn }, { "error", LogLevel::Error }, + { "none", LogLevel::None }, }}; const std::string logLevelStr = env::getEnvVar(L"DXVK_LOG_LEVEL"); @@ -71,4 +86,4 @@ namespace dxvk { return LogLevel::Info; } -} \ No newline at end of file +} diff --git a/src/util/log/log.h b/src/util/log/log.h index c39bf0bb..e298765a 100644 --- a/src/util/log/log.h +++ b/src/util/log/log.h @@ -13,6 +13,7 @@ namespace dxvk { Info = 2, Warn = 3, Error = 4, + None = 5, }; /** @@ -49,4 +50,4 @@ namespace dxvk { }; -} \ No newline at end of file +}