2014-06-17 17:44:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
2016-02-01 22:55:43 +01:00
|
|
|
#include "types.h"
|
|
|
|
#include "Atomic.h"
|
2016-08-03 22:51:05 +02:00
|
|
|
#include "StrFmt.h"
|
2014-06-17 17:44:03 +02:00
|
|
|
|
2016-05-13 16:01:48 +02:00
|
|
|
namespace logs
|
2014-06-17 17:44:03 +02:00
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
enum class level : uint
|
2014-06-17 17:44:03 +02:00
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
always, // highest level (unused, cannot be disabled)
|
|
|
|
fatal,
|
|
|
|
error,
|
|
|
|
todo,
|
|
|
|
success,
|
|
|
|
warning,
|
|
|
|
notice,
|
|
|
|
trace, // lowest level (usually disabled)
|
2014-06-17 17:44:03 +02:00
|
|
|
};
|
|
|
|
|
2016-07-21 00:00:31 +02:00
|
|
|
struct channel;
|
|
|
|
|
|
|
|
// Message information (temporary data)
|
|
|
|
struct message
|
|
|
|
{
|
|
|
|
const channel* ch;
|
|
|
|
level sev;
|
|
|
|
|
2016-08-05 18:49:45 +02:00
|
|
|
// Send log message to global logger instance
|
|
|
|
void broadcast(const char*, const fmt_type_info*, const u64*);
|
2016-07-21 00:00:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class listener
|
|
|
|
{
|
|
|
|
// Next listener (linked list)
|
|
|
|
atomic_t<listener*> m_next{};
|
|
|
|
|
2016-08-05 18:49:45 +02:00
|
|
|
friend struct message;
|
2016-07-21 00:00:31 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
constexpr listener() = default;
|
|
|
|
|
2017-01-25 00:22:19 +01:00
|
|
|
virtual ~listener();
|
2016-07-21 00:00:31 +02:00
|
|
|
|
|
|
|
// Process log message
|
2017-02-22 10:52:03 +01:00
|
|
|
virtual void log(u64 stamp, const message& msg, const std::string& prefix, const std::string& text) = 0;
|
2016-07-21 00:00:31 +02:00
|
|
|
|
|
|
|
// Add new listener
|
|
|
|
static void add(listener*);
|
|
|
|
};
|
|
|
|
|
2016-01-12 22:57:16 +01:00
|
|
|
struct channel
|
2014-06-17 17:44:03 +02:00
|
|
|
{
|
2016-02-01 22:55:43 +01:00
|
|
|
// Channel prefix (added to every log message)
|
|
|
|
const char* const name;
|
2016-01-12 22:57:16 +01:00
|
|
|
|
|
|
|
// The lowest logging level enabled for this channel (used for early filtering)
|
2016-02-01 22:55:43 +01:00
|
|
|
atomic_t<level> enabled;
|
2016-01-12 22:57:16 +01:00
|
|
|
|
2016-02-01 22:55:43 +01:00
|
|
|
// Constant initialization: name and initial log level
|
|
|
|
constexpr channel(const char* name, level enabled = level::trace)
|
2016-04-27 00:27:24 +02:00
|
|
|
: name(name)
|
|
|
|
, enabled(enabled)
|
2016-01-12 22:57:16 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-04-27 00:27:24 +02:00
|
|
|
// Formatting function
|
2016-01-12 22:57:16 +01:00
|
|
|
template<typename... Args>
|
2016-08-05 18:49:45 +02:00
|
|
|
SAFE_BUFFERS FORCE_INLINE void format(level sev, const char* fmt, const Args&... args) const
|
2016-01-12 22:57:16 +01:00
|
|
|
{
|
2016-08-03 22:51:05 +02:00
|
|
|
if (UNLIKELY(sev <= enabled))
|
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
message{this, sev}.broadcast(fmt, fmt::get_type_info<fmt_unveil_t<Args>...>(), fmt_args_t<Args...>{fmt_unveil<Args>::get(args)...});
|
2016-08-03 22:51:05 +02:00
|
|
|
}
|
2016-01-12 22:57:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define GEN_LOG_METHOD(_sev)\
|
|
|
|
template<typename... Args>\
|
2016-08-03 22:51:05 +02:00
|
|
|
SAFE_BUFFERS void _sev(const char* fmt, const Args&... args) const\
|
2016-01-12 22:57:16 +01:00
|
|
|
{\
|
|
|
|
return format<Args...>(level::_sev, fmt, args...);\
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2014-06-17 17:44:03 +02:00
|
|
|
};
|
|
|
|
|
2016-04-27 00:27:24 +02:00
|
|
|
/* Small set of predefined channels */
|
2016-01-12 22:57:16 +01:00
|
|
|
|
|
|
|
extern channel GENERAL;
|
|
|
|
extern channel LOADER;
|
|
|
|
extern channel MEMORY;
|
|
|
|
extern channel RSX;
|
|
|
|
extern channel HLE;
|
|
|
|
extern channel PPU;
|
|
|
|
extern channel SPU;
|
|
|
|
extern channel ARMv7;
|
2014-06-27 15:26:46 +02:00
|
|
|
}
|
2016-01-12 22:57:16 +01:00
|
|
|
|
|
|
|
// Legacy:
|
|
|
|
|
2016-08-14 23:04:42 +02:00
|
|
|
#define LOG_SUCCESS(ch, fmt, ...) logs::ch.success("" fmt, ##__VA_ARGS__)
|
|
|
|
#define LOG_NOTICE(ch, fmt, ...) logs::ch.notice ("" fmt, ##__VA_ARGS__)
|
|
|
|
#define LOG_WARNING(ch, fmt, ...) logs::ch.warning("" fmt, ##__VA_ARGS__)
|
|
|
|
#define LOG_ERROR(ch, fmt, ...) logs::ch.error ("" fmt, ##__VA_ARGS__)
|
|
|
|
#define LOG_TODO(ch, fmt, ...) logs::ch.todo ("" fmt, ##__VA_ARGS__)
|
|
|
|
#define LOG_TRACE(ch, fmt, ...) logs::ch.trace ("" fmt, ##__VA_ARGS__)
|
|
|
|
#define LOG_FATAL(ch, fmt, ...) logs::ch.fatal ("" fmt, ##__VA_ARGS__)
|