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,
2020-07-29 02:43:59 +01:00
// Potential problems of note
Warning = -1,
2020-07-29 02:43:59 +01:00
// General messages for end-users
Info = 0,
2020-07-29 02:43:59 +01:00
// More advanced information for problem-solving
Debug = 1,
2020-07-29 02:43:59 +01:00
// Fine grained spew
Trace = 2,
2020-07-29 05:32:35 +01:00
// These are an inclusve interval
MinLevel = Error,
MaxLevel = 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;
}
#define REGISTER_LOGGING_CHANNEL(Name) ::Feather::Logging::GlobalLogger.RegisterChannel(Name);
2020-07-29 05:32:35 +01:00
2020-07-29 05:37:22 +01:00
// Logs a message, specifying a channel and log level
#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
#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
#define Log_Warn(Message, ...) Log_Msg(LOG_GENERAL, Warning, Message, ##__VA_ARGS__)
2020-07-29 05:37:22 +01:00
// Logs a serious problem
#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
#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
#define Log_Trace(Message, ...) Log_Msg(LOG_GENERAL, Trace, Message, ##__VA_ARGS__)