1
0
mirror of https://github.com/EduApps-CDG/OpenDX synced 2024-12-30 09:45:37 +01:00
OpenDX/src/util/log/log.cpp

73 lines
1.7 KiB
C++
Raw Normal View History

2017-10-10 23:32:13 +02:00
#include "log.h"
#include "../util_env.h"
2017-10-10 23:44:06 +02:00
2017-10-10 23:32:13 +02:00
namespace dxvk {
2017-10-10 23:44:06 +02:00
Logger::Logger(const std::string& file_name)
: m_minLevel(getMinLogLevel()),
m_fileStream(file_name) { }
2017-10-10 23:44:06 +02:00
Logger::~Logger() { }
void Logger::trace(const std::string& message) {
s_instance.log(LogLevel::Trace, message);
}
void Logger::debug(const std::string& message) {
s_instance.log(LogLevel::Debug, message);
2017-10-10 23:44:06 +02:00
}
void Logger::info(const std::string& message) {
s_instance.log(LogLevel::Info, message);
2017-10-10 23:44:06 +02:00
}
void Logger::warn(const std::string& message) {
s_instance.log(LogLevel::Warn, message);
2017-10-10 23:32:13 +02:00
}
2017-10-10 23:44:06 +02:00
void Logger::err(const std::string& message) {
s_instance.log(LogLevel::Error, message);
}
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();
}
2017-10-10 23:32:13 +02:00
}
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;
2017-10-10 23:32:13 +02:00
}
}