FeatherMC/src/logging/Logger.h

84 lines
2.2 KiB
C
Raw Normal View History

2020-07-29 02:43:59 +01:00
#pragma once
namespace Feather::Logging
{
2020-07-29 05:32:35 +01:00
const int MAX_LOG_MESSAGE_LENGTH = 2048;
const int MAX_LOGGING_CHANNEL_COUNT = 256;
/*==== Severity Levels ==============================*/
2020-07-29 02:43:59 +01:00
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,
2020-07-29 05:32:35 +01:00
// These are an inclusve interval
MIN_LEVEL = ERROR,
MAX_LEVEL = TRACE,
2020-07-29 02:43:59 +01:00
};
2020-07-29 05:32:35 +01:00
/*==== Channels ==============================*/
typedef int ChannelID;
2020-07-29 02:43:59 +01:00
class Channel
2020-07-29 05:32:35 +01:00
{
const char* m_name;
public:
Channel(const char* name) : m_name(name) {}
2020-07-29 02:43:59 +01:00
2020-07-29 05:32:35 +01:00
inline const char* GetName() { return m_name; }
2020-07-29 02:43:59 +01:00
};
2020-07-29 05:32:35 +01:00
extern ChannelID LOG_GENERAL;
/*==== Logger ==============================*/
2020-07-29 02:43:59 +01:00
class Logger
{
public:
2020-07-29 05:32:35 +01:00
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;
2020-07-29 02:43:59 +01:00
};
extern Logger GlobalLogger;
}
2020-07-29 05:32:35 +01:00
#define REGISTER_LOGGING_CHANNEL(Name) Feather::Logging::GlobalLogger.RegisterChannel(Name);
2020-07-29 05:37:22 +01:00
// Logs a message, specifying a channel and log level
2020-07-29 05:32:35 +01:00
#define Log_Msg(_Channel, _Level, _Message, ...) Feather::Logging::GlobalLogger.LogDirect(Feather::Logging::_Channel, Feather::Logging::Level::_Level, _Message, ##__VA_ARGS__)
2020-07-29 02:43:59 +01:00
2020-07-29 05:37:22 +01:00
// Logs a general message for end-users
2020-07-29 05:32:35 +01:00
#define Log_Info(Message, ...) Log_Msg(LOG_GENERAL, INFO, Message, ##__VA_ARGS__)
2020-07-29 05:37:22 +01:00
// Logs a potential problem of note
2020-07-29 05:32:35 +01:00
#define Log_Warn(Message, ...) Log_Msg(LOG_GENERAL, WARNING, Message, ##__VA_ARGS__)
2020-07-29 05:37:22 +01:00
// Logs a serious problem
2020-07-29 05:32:35 +01:00
#define Log_Error(Message, ...) Log_Msg(LOG_GENERAL, ERROR, Message, ##__VA_ARGS__)
2020-07-29 05:37:22 +01:00
// Logs debug information for developers
2020-07-29 05:32:35 +01:00
#define Log_Debug(Message, ...) Log_Msg(LOG_GENERAL, DEBUG, Message, ##__VA_ARGS__)
2020-07-29 05:37:22 +01:00
// Logs fine grained debug information
2020-07-29 05:32:35 +01:00
#define Log_Trace(Message, ...) Log_Msg(LOG_GENERAL, TRACE, Message, ##__VA_ARGS__)