mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-14 22:29:15 +01:00
[dxvk] Re-implemented logger
This commit is contained in:
parent
00e63d71a9
commit
46845e60be
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
namespace dxvk {
|
namespace dxvk {
|
||||||
|
|
||||||
Log g_logger("dxvk.log");
|
Logger g_logger("dxvk.log");
|
||||||
|
|
||||||
void log(const std::string& message) {
|
Logger* getGlobalLogger() {
|
||||||
g_logger.log(message);
|
return &g_logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -5,10 +5,6 @@
|
|||||||
|
|
||||||
namespace dxvk {
|
namespace dxvk {
|
||||||
|
|
||||||
/**
|
Logger* getGlobalLogger();
|
||||||
* \brief Adds a message to the global DXVK log
|
|
||||||
* \param [in] message Log message
|
|
||||||
*/
|
|
||||||
void log(const std::string& message);
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,26 +1,39 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
#include "../../dxvk/dxvk_main.h"
|
||||||
|
|
||||||
namespace dxvk {
|
namespace dxvk {
|
||||||
|
|
||||||
Log::Log(const std::string& filename)
|
Logger::Logger(const std::string& file_name)
|
||||||
: m_stream(filename, std::ios_base::out | std::ios_base::trunc) {
|
: m_fileStream(file_name) { }
|
||||||
|
Logger::~Logger() { }
|
||||||
|
|
||||||
|
|
||||||
|
void Logger::trace(const std::string& message) {
|
||||||
|
getGlobalLogger()->log(std::string("trace: ") + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Log::~Log() {
|
void Logger::info(const std::string& message) {
|
||||||
|
getGlobalLogger()->log(std::string("info: ") + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Log::log(const std::string& message) {
|
void Logger::warn(const std::string& message) {
|
||||||
|
getGlobalLogger()->log(std::string("warn: ") + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Logger::err(const std::string& message) {
|
||||||
|
getGlobalLogger()->log(std::string("err: ") + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Logger::log(const std::string& message) {
|
||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
std::cerr << message << std::endl;
|
std::cerr << message << std::endl;
|
||||||
std::cerr.flush();
|
m_fileStream << message << std::endl;
|
||||||
|
m_fileStream.flush();
|
||||||
m_stream << message << std::endl;
|
|
||||||
m_stream.flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -12,29 +12,28 @@ namespace dxvk {
|
|||||||
/**
|
/**
|
||||||
* \brief Logger
|
* \brief Logger
|
||||||
*
|
*
|
||||||
* Logs messages generated by DXVK and
|
* Logger for one DLL. Creates a text file and
|
||||||
* the client APIs using DXVK.
|
* writes all log messages to that file.
|
||||||
*/
|
*/
|
||||||
class Log : public RcObject {
|
class Logger {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Log(const std::string& filename);
|
Logger(const std::string& file_name);
|
||||||
~Log();
|
~Logger();
|
||||||
|
|
||||||
/**
|
static void trace(const std::string& message);
|
||||||
* \brief Adds a message to the log
|
static void info (const std::string& message);
|
||||||
*
|
static void warn (const std::string& message);
|
||||||
* Prints the message to stderr and appends
|
static void err (const std::string& message);
|
||||||
* it to the log file at the same time.
|
|
||||||
*/
|
|
||||||
void log(const std::string& message);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
std::fstream m_stream;
|
std::ofstream m_fileStream;
|
||||||
|
|
||||||
|
void log(const std::string& message);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
11
src/util/log/log_debug.cpp
Normal file
11
src/util/log/log_debug.cpp
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
45
src/util/log/log_debug.h
Normal file
45
src/util/log/log_debug.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
#define METHOD_NAME __PRETTY_FUNCTION__
|
||||||
|
|
||||||
|
#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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
util_src = files([
|
util_src = files([
|
||||||
'log/log.cpp',
|
'log/log.cpp',
|
||||||
|
'log/log_debug.cpp',
|
||||||
])
|
])
|
||||||
|
|
||||||
util_lib = static_library('util', util_src,
|
util_lib = static_library('util', util_src,
|
||||||
|
@ -112,7 +112,7 @@ int WINAPI WinMain(HINSTANCE hInstance,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const dxvk::DxvkError& e) {
|
} catch (const dxvk::DxvkError& e) {
|
||||||
dxvk::log(e.message());
|
Logger::err(e.message());
|
||||||
return msg.wParam;
|
return msg.wParam;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user