mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-18 02:52:10 +01:00
[util] Log level can now be controlled manually
This commit is contained in:
parent
d1d5f10520
commit
a0fafe3043
@ -1,39 +1,73 @@
|
||||
#include "log.h"
|
||||
|
||||
#include "../../dxvk/dxvk_main.h"
|
||||
#include "../util_env.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
Logger::Logger(const std::string& file_name)
|
||||
: m_fileStream(file_name) { }
|
||||
: m_minLevel(getMinLogLevel()),
|
||||
m_fileStream(file_name) { }
|
||||
|
||||
|
||||
Logger::~Logger() { }
|
||||
|
||||
|
||||
void Logger::trace(const std::string& message) {
|
||||
s_instance.log(std::string("trace: ") + message);
|
||||
s_instance.log(LogLevel::Trace, message);
|
||||
}
|
||||
|
||||
|
||||
void Logger::debug(const std::string& message) {
|
||||
s_instance.log(LogLevel::Debug, message);
|
||||
}
|
||||
|
||||
|
||||
void Logger::info(const std::string& message) {
|
||||
s_instance.log(std::string("info: ") + message);
|
||||
s_instance.log(LogLevel::Info, message);
|
||||
}
|
||||
|
||||
|
||||
void Logger::warn(const std::string& message) {
|
||||
s_instance.log(std::string("warn: ") + message);
|
||||
s_instance.log(LogLevel::Warn, message);
|
||||
}
|
||||
|
||||
|
||||
void Logger::err(const std::string& message) {
|
||||
s_instance.log(std::string("err: ") + message);
|
||||
s_instance.log(LogLevel::Error, message);
|
||||
}
|
||||
|
||||
|
||||
void Logger::log(const std::string& message) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::cerr << message << std::endl;
|
||||
m_fileStream << message << std::endl;
|
||||
m_fileStream.flush();
|
||||
void Logger::log(LogLevel level, const std::string& message) {
|
||||
if (level >= m_minLevel) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
static std::array<const char*, 5> s_prefixes
|
||||
= {{ "trace: ", "debug: ", "info: ", "warn: ", "err: " }};
|
||||
|
||||
std::cerr << s_prefixes.at(static_cast<uint32_t>(level)) << message << std::endl;
|
||||
m_fileStream << message << std::endl;
|
||||
m_fileStream.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LogLevel Logger::getMinLogLevel() {
|
||||
const std::array<std::pair<const char*, LogLevel>, 5> logLevels = {{
|
||||
{ "trace", LogLevel::Trace },
|
||||
{ "debug", LogLevel::Debug },
|
||||
{ "info", LogLevel::Info },
|
||||
{ "warn", LogLevel::Warn },
|
||||
{ "error", LogLevel::Error },
|
||||
}};
|
||||
|
||||
const std::string logLevelStr = env::getEnvVar(L"DXVK_LOG_LEVEL");
|
||||
|
||||
for (const auto& pair : logLevels) {
|
||||
if (logLevelStr == pair.first)
|
||||
return pair.second;
|
||||
}
|
||||
|
||||
return LogLevel::Info;
|
||||
}
|
||||
|
||||
}
|
@ -5,10 +5,16 @@
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "../rc/util_rc.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
enum class LogLevel : uint32_t {
|
||||
Trace = 0,
|
||||
Debug = 1,
|
||||
Info = 2,
|
||||
Warn = 3,
|
||||
Error = 4,
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Logger
|
||||
*
|
||||
@ -23,6 +29,7 @@ namespace dxvk {
|
||||
~Logger();
|
||||
|
||||
static void trace(const std::string& message);
|
||||
static void debug(const std::string& message);
|
||||
static void info (const std::string& message);
|
||||
static void warn (const std::string& message);
|
||||
static void err (const std::string& message);
|
||||
@ -31,10 +38,14 @@ namespace dxvk {
|
||||
|
||||
static Logger s_instance;
|
||||
|
||||
const LogLevel m_minLevel;
|
||||
|
||||
std::mutex m_mutex;
|
||||
std::ofstream m_fileStream;
|
||||
|
||||
void log(const std::string& message);
|
||||
void log(LogLevel level, const std::string& message);
|
||||
|
||||
static LogLevel getMinLogLevel();
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user