mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-04 14:08:37 +00:00
Move Log.h to util/logs.hpp
This commit is contained in:
parent
a166d3680e
commit
e4a81b1d13
25 changed files with 39 additions and 32 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "Utilities/types.h"
|
||||
#include "Utilities/StrFmt.h"
|
||||
#include "Utilities/Log.h"
|
||||
#include "util/logs.hpp"
|
||||
#include "util/atomic.hpp"
|
||||
#include "util/shared_cptr.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include "JIT.h"
|
||||
#include "StrFmt.h"
|
||||
#include "File.h"
|
||||
#include "Log.h"
|
||||
#include "util/logs.hpp"
|
||||
#include "mutex.h"
|
||||
#include "sysinfo.h"
|
||||
#include "VirtualMemory.h"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "Log.h"
|
||||
#include "util/logs.hpp"
|
||||
#include "File.h"
|
||||
#include "StrFmt.h"
|
||||
#include "sema.h"
|
||||
|
|
@ -279,9 +279,12 @@ void logs::listener::add(logs::listener* _new)
|
|||
std::lock_guard lock(g_mutex);
|
||||
|
||||
// Install new listener at the end of linked list
|
||||
while (lis->m_next || !lis->m_next.compare_and_swap_test(nullptr, _new))
|
||||
listener* null = nullptr;
|
||||
|
||||
while (lis->m_next || !lis->m_next.compare_exchange_strong(null, _new))
|
||||
{
|
||||
lis = lis->m_next;
|
||||
null = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
171
Utilities/Log.h
171
Utilities/Log.h
|
|
@ -1,171 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
#include "StrFmt.h"
|
||||
#include "util/atomic.hpp"
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
namespace logs
|
||||
{
|
||||
enum class level : uint
|
||||
{
|
||||
always, // Highest log severity (unused, cannot be disabled)
|
||||
fatal,
|
||||
error,
|
||||
todo,
|
||||
success,
|
||||
warning,
|
||||
notice,
|
||||
trace, // Lowest severity (usually disabled)
|
||||
};
|
||||
|
||||
struct channel;
|
||||
|
||||
// Message information
|
||||
struct message
|
||||
{
|
||||
channel* ch;
|
||||
level sev;
|
||||
|
||||
private:
|
||||
// Send log message to global logger instance
|
||||
void broadcast(const char*, const fmt_type_info*, ...) const;
|
||||
|
||||
friend struct channel;
|
||||
};
|
||||
|
||||
struct stored_message
|
||||
{
|
||||
message m;
|
||||
u64 stamp;
|
||||
std::string prefix;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
class listener
|
||||
{
|
||||
// Next listener (linked list)
|
||||
atomic_t<listener*> m_next{};
|
||||
|
||||
friend struct message;
|
||||
|
||||
public:
|
||||
constexpr listener() = default;
|
||||
|
||||
virtual ~listener();
|
||||
|
||||
// Process log message
|
||||
virtual void log(u64 stamp, const message& msg, const std::string& prefix, const std::string& text) = 0;
|
||||
|
||||
// Add new listener
|
||||
static void add(listener*);
|
||||
|
||||
// Special purpose
|
||||
void broadcast(const stored_message&) const;
|
||||
};
|
||||
|
||||
struct channel
|
||||
{
|
||||
// Channel prefix (added to every log message)
|
||||
const char* const name;
|
||||
|
||||
// The lowest logging level enabled for this channel (used for early filtering)
|
||||
std::atomic<level> enabled;
|
||||
|
||||
// Initialize channel
|
||||
constexpr channel(const char* name) noexcept
|
||||
: name(name)
|
||||
, enabled(level::notice)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
#if __cpp_char8_t >= 201811
|
||||
using char2 = char8_t;
|
||||
#else
|
||||
using char2 = uchar;
|
||||
#endif
|
||||
|
||||
#define GEN_LOG_METHOD(_sev)\
|
||||
const message msg_##_sev{this, level::_sev};\
|
||||
template <std::size_t N, typename... Args>\
|
||||
void _sev(const char(&fmt)[N], const Args&... args)\
|
||||
{\
|
||||
if (level::_sev <= enabled.load(std::memory_order_relaxed)) [[unlikely]]\
|
||||
{\
|
||||
static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make<fmt_unveil_t<Args>>()...};\
|
||||
msg_##_sev.broadcast(fmt, type_list, u64{fmt_unveil<Args>::get(args)}...);\
|
||||
}\
|
||||
}\
|
||||
template <std::size_t N, typename... Args>\
|
||||
void _sev(const char2(&fmt)[N], const Args&... args)\
|
||||
{\
|
||||
if (level::_sev <= enabled.load(std::memory_order_relaxed)) [[unlikely]]\
|
||||
{\
|
||||
static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make<fmt_unveil_t<Args>>()...};\
|
||||
msg_##_sev.broadcast(reinterpret_cast<const char*>(+fmt), type_list, u64{fmt_unveil<Args>::get(args)}...);\
|
||||
}\
|
||||
}\
|
||||
|
||||
public:
|
||||
GEN_LOG_METHOD(fatal)
|
||||
GEN_LOG_METHOD(error)
|
||||
GEN_LOG_METHOD(todo)
|
||||
GEN_LOG_METHOD(success)
|
||||
GEN_LOG_METHOD(warning)
|
||||
GEN_LOG_METHOD(notice)
|
||||
GEN_LOG_METHOD(trace)
|
||||
|
||||
#undef GEN_LOG_METHOD
|
||||
};
|
||||
|
||||
struct registerer
|
||||
{
|
||||
registerer(channel& _ch);
|
||||
};
|
||||
|
||||
// Log level control: set all channels to level::notice
|
||||
void reset();
|
||||
|
||||
// Log level control: set all channels to level::always
|
||||
void silence();
|
||||
|
||||
// Log level control: register channel if necessary, set channel level
|
||||
void set_level(const std::string&, level);
|
||||
|
||||
// Log level control: get channel level
|
||||
level get_level(const std::string&);
|
||||
|
||||
// Get all registered log channels
|
||||
std::vector<std::string> get_channels();
|
||||
|
||||
// Helper: no additional name specified
|
||||
constexpr const char* make_channel_name(const char* name)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
// Helper: special channel name specified
|
||||
constexpr const char* make_channel_name(const char*, const char* name, ...)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
// Called in main()
|
||||
std::unique_ptr<logs::listener> make_file_listener(const std::string& path, u64 max_size);
|
||||
|
||||
// Called in main()
|
||||
void set_init(std::initializer_list<stored_message>);
|
||||
}
|
||||
|
||||
#if __cpp_constinit >= 201907
|
||||
#define LOG_CONSTINIT constinit
|
||||
#else
|
||||
#define LOG_CONSTINIT
|
||||
#endif
|
||||
|
||||
#define LOG_CHANNEL(ch, ...) LOG_CONSTINIT inline ::logs::channel ch(::logs::make_channel_name(#ch, ##__VA_ARGS__)); \
|
||||
namespace logs { inline ::logs::registerer reg_##ch{ch}; }
|
||||
|
||||
LOG_CHANNEL(rsx_log, "RSX");
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
#endif
|
||||
|
||||
#include "sync.h"
|
||||
#include "Log.h"
|
||||
#include "util/logs.hpp"
|
||||
|
||||
LOG_CHANNEL(sig_log);
|
||||
LOG_CHANNEL(sys_log, "SYS");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "stdafx.h"
|
||||
#include "Utilities/Log.h"
|
||||
#include "util/logs.hpp"
|
||||
#include "VirtualMemory.h"
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue