diff options
Diffstat (limited to 'src/libs/dxvk-native-1.9.2a/src/util/log')
-rw-r--r-- | src/libs/dxvk-native-1.9.2a/src/util/log/log.cpp | 146 | ||||
-rw-r--r-- | src/libs/dxvk-native-1.9.2a/src/util/log/log.h | 71 | ||||
-rw-r--r-- | src/libs/dxvk-native-1.9.2a/src/util/log/log_debug.cpp | 11 | ||||
-rw-r--r-- | src/libs/dxvk-native-1.9.2a/src/util/log/log_debug.h | 49 |
4 files changed, 277 insertions, 0 deletions
diff --git a/src/libs/dxvk-native-1.9.2a/src/util/log/log.cpp b/src/libs/dxvk-native-1.9.2a/src/util/log/log.cpp new file mode 100644 index 00000000..e096ee2f --- /dev/null +++ b/src/libs/dxvk-native-1.9.2a/src/util/log/log.cpp @@ -0,0 +1,146 @@ +#ifdef VBOX +#include <iprt/log.h> +#endif + +#include "log.h" + +#include "../util_env.h" + +namespace dxvk { + + Logger::Logger(const std::string& file_name) + : m_minLevel(getMinLogLevel()) { + if (m_minLevel != LogLevel::None) { + auto path = getFileName(file_name); + + if (!path.empty()) { +#ifdef _WIN32 + m_fileStream = std::ofstream(str::tows(path.c_str()).c_str()); +#else + m_fileStream = std::ofstream(path.c_str()); +#endif + } + } + } + + + Logger::~Logger() { } + + + void Logger::trace(const std::string& message) { +#ifndef VBOX + s_instance.emitMsg(LogLevel::Trace, message); +#else + LogRel2(("%s", message.c_str())); +#endif + } + + + void Logger::debug(const std::string& message) { +#ifndef VBOX + s_instance.emitMsg(LogLevel::Debug, message); +#else + LogFlow(("%s", message.c_str())); +#endif + } + + + void Logger::info(const std::string& message) { +#ifndef VBOX + s_instance.emitMsg(LogLevel::Info, message); +#else + Log(("%s", message.c_str())); +#endif + } + + + void Logger::warn(const std::string& message) { +#ifndef VBOX + s_instance.emitMsg(LogLevel::Warn, message); +#else + LogRel(("%s", message.c_str())); +#endif + } + + + void Logger::err(const std::string& message) { +#ifndef VBOX + s_instance.emitMsg(LogLevel::Error, message); +#else + LogRel(("%s", message.c_str())); +#endif + } + + + void Logger::log(LogLevel level, const std::string& message) { +#ifndef VBOX + s_instance.emitMsg(level, message); +#else + Log(("%s", message.c_str())); +#endif + } + +#ifndef VBOX + void Logger::emitMsg(LogLevel level, const std::string& message) { + if (level >= m_minLevel) { + std::lock_guard<dxvk::mutex> lock(m_mutex); + + static std::array<const char*, 5> s_prefixes + = {{ "trace: ", "debug: ", "info: ", "warn: ", "err: " }}; + + const char* prefix = s_prefixes.at(static_cast<uint32_t>(level)); + + std::stringstream stream(message); + std::string line; + + while (std::getline(stream, line, '\n')) { + std::cerr << prefix << line << std::endl; + + if (m_fileStream) + m_fileStream << prefix << line << std::endl; + } + } + } +#endif + + LogLevel Logger::getMinLogLevel() { +#ifndef VBOX + const std::array<std::pair<const char*, LogLevel>, 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("DXVK_LOG_LEVEL"); + + for (const auto& pair : logLevels) { + if (logLevelStr == pair.first) + return pair.second; + } +#endif + return LogLevel::Info; + } + + + std::string Logger::getFileName(const std::string& base) { +#ifndef VBOX + std::string path = env::getEnvVar("DXVK_LOG_PATH"); + + if (path == "none") + return ""; + + if (!path.empty() && *path.rbegin() != '/') + path += '/'; + + std::string exeName = env::getExeBaseName(); + path += exeName + "_" + base; + return path; +#else + return ""; +#endif + } + +} diff --git a/src/libs/dxvk-native-1.9.2a/src/util/log/log.h b/src/libs/dxvk-native-1.9.2a/src/util/log/log.h new file mode 100644 index 00000000..93c05ffb --- /dev/null +++ b/src/libs/dxvk-native-1.9.2a/src/util/log/log.h @@ -0,0 +1,71 @@ +#pragma once + +#include <array> +#include <fstream> +#include <iostream> +#include <string> + +#include "../thread.h" + +namespace dxvk { + + enum class LogLevel : uint32_t { + Trace = 0, + Debug = 1, + Info = 2, + Warn = 3, + Error = 4, + None = 5, + }; + + /** + * \brief Logger + * + * Logger for one DLL. Creates a text file and + * writes all log messages to that file. + */ + class Logger { + + public: + + Logger(const std::string& file_name); + ~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); + static void log (LogLevel level, const std::string& message); + + static LogLevel logLevel() { +#ifndef VBOX + return s_instance.m_minLevel; +#else + return LogLevel::Info; +#endif + } + + private: + +#ifndef VBOX + static Logger s_instance; +#endif + + const LogLevel m_minLevel; + + dxvk::mutex m_mutex; + std::ofstream m_fileStream; + +#ifndef VBOX + void emitMsg(LogLevel level, const std::string& message); +#endif + + static LogLevel getMinLogLevel(); + + static std::string getFileName( + const std::string& base); + + }; + +} diff --git a/src/libs/dxvk-native-1.9.2a/src/util/log/log_debug.cpp b/src/libs/dxvk-native-1.9.2a/src/util/log/log_debug.cpp new file mode 100644 index 00000000..c67742ab --- /dev/null +++ b/src/libs/dxvk-native-1.9.2a/src/util/log/log_debug.cpp @@ -0,0 +1,11 @@ +#include "log_debug.h" + +namespace dxvk::debug { + + std::string methodName(const std::string& prettyName) { + size_t end = prettyName.find("("); + size_t begin = prettyName.substr(0, end).rfind(" ") + 1; + return prettyName.substr(begin,end - begin); + } + +} diff --git a/src/libs/dxvk-native-1.9.2a/src/util/log/log_debug.h b/src/libs/dxvk-native-1.9.2a/src/util/log/log_debug.h new file mode 100644 index 00000000..c5084320 --- /dev/null +++ b/src/libs/dxvk-native-1.9.2a/src/util/log/log_debug.h @@ -0,0 +1,49 @@ +#pragma once + +#include <sstream> + +#include "log.h" + +#ifdef _MSC_VER +#define METHOD_NAME __FUNCSIG__ +#else +#define METHOD_NAME __PRETTY_FUNCTION__ +#endif + +#define TRACE_ENABLED + +#ifdef TRACE_ENABLED +#define TRACE(...) \ + do { dxvk::debug::trace(METHOD_NAME, ##__VA_ARGS__); } while (0) +#else +#define TRACE(...) \ + do { } while (0) +#endif + +namespace dxvk::debug { + + std::string methodName(const std::string& prettyName); + + inline void traceArgs(std::stringstream& stream) { } + + template<typename Arg1> + void traceArgs(std::stringstream& stream, const Arg1& arg1) { + stream << arg1; + } + + template<typename Arg1, typename Arg2, typename... Args> + void traceArgs(std::stringstream& stream, const Arg1& arg1, const Arg2& arg2, const Args&... args) { + stream << arg1 << ","; + traceArgs(stream, arg2, args...); + } + + template<typename... Args> + void trace(const std::string& funcName, const Args&... args) { + std::stringstream stream; + stream << methodName(funcName) << "("; + traceArgs(stream, args...); + stream << ")"; + Logger::trace(stream.str()); + } + +} |