74 lines
2.0 KiB
C++
74 lines
2.0 KiB
C++
#pragma once
|
|
|
|
namespace Feather::Logging
|
|
{
|
|
const int MAX_LOG_MESSAGE_LENGTH = 2048;
|
|
const int MAX_LOGGING_CHANNEL_COUNT = 256;
|
|
|
|
/*==== Severity Levels ==============================*/
|
|
|
|
enum class Level
|
|
{
|
|
// Serious problems
|
|
ERROR = -2,
|
|
|
|
// Potential problems of note
|
|
WARNING = -1,
|
|
|
|
// General messages for end-users
|
|
INFO = 0,
|
|
|
|
// More advanced information for problem-solving
|
|
DEBUG = 1,
|
|
|
|
// Fine grained spew
|
|
TRACE = 2,
|
|
|
|
// These are an inclusve interval
|
|
MIN_LEVEL = ERROR,
|
|
MAX_LEVEL = TRACE,
|
|
};
|
|
|
|
/*==== Channels ==============================*/
|
|
|
|
typedef int ChannelID;
|
|
|
|
class Channel
|
|
{
|
|
const char* m_name;
|
|
public:
|
|
Channel(const char* name) : m_name(name) {}
|
|
|
|
inline const char* GetName() { return m_name; }
|
|
};
|
|
|
|
extern ChannelID LOG_GENERAL;
|
|
|
|
/*==== Logger ==============================*/
|
|
|
|
class Logger
|
|
{
|
|
public:
|
|
Logger();
|
|
void LogDirect(ChannelID channel, Level level, const char* message, ...);
|
|
|
|
ChannelID RegisterChannel(const char* name);
|
|
|
|
private:
|
|
Channel* m_channels[MAX_LOGGING_CHANNEL_COUNT];
|
|
ChannelID m_channelCount = 0;
|
|
};
|
|
|
|
extern Logger GlobalLogger;
|
|
}
|
|
|
|
#define REGISTER_LOGGING_CHANNEL(Name) Feather::Logging::GlobalLogger.RegisterChannel(Name);
|
|
|
|
#define Log_Msg(_Channel, _Level, _Message, ...) Feather::Logging::GlobalLogger.LogDirect(Feather::Logging::_Channel, Feather::Logging::Level::_Level, _Message, ##__VA_ARGS__)
|
|
|
|
#define Log_Info(Message, ...) Log_Msg(LOG_GENERAL, INFO, Message, ##__VA_ARGS__)
|
|
#define Log_Warn(Message, ...) Log_Msg(LOG_GENERAL, WARNING, Message, ##__VA_ARGS__)
|
|
#define Log_Error(Message, ...) Log_Msg(LOG_GENERAL, ERROR, Message, ##__VA_ARGS__)
|
|
#define Log_Debug(Message, ...) Log_Msg(LOG_GENERAL, DEBUG, Message, ##__VA_ARGS__)
|
|
#define Log_Trace(Message, ...) Log_Msg(LOG_GENERAL, TRACE, Message, ##__VA_ARGS__)
|