Fix logging in files with Windows includes

This commit is contained in:
Joshua Ashton 2020-08-01 04:53:21 +01:00
parent 8a65a66924
commit 134fd77247
2 changed files with 21 additions and 21 deletions

View File

@ -15,13 +15,13 @@ namespace Feather::Logging
// Since min and max are inclusive we have to add 1 here
// This assumes max > min (they better be)
static constexpr int NUM_LEVELS = ((int)Level::MAX_LEVEL - (int)Level::MIN_LEVEL) + 1;
static constexpr int NUM_LEVELS = ((int)Level::MaxLevel - (int)Level::MinLevel) + 1;
// Temporary solution while we don't have named enums
static const char *s_levelNames[NUM_LEVELS] = {"ERROR", "WARNING", "INFO", "DEBUG", "TRACE"};
// Shifts an enum value to be a positive index in s_levelNames
static constexpr int LEVEL_NAME_OFFSET = 0 - (int)Level::MIN_LEVEL;
static constexpr int LEVEL_NAME_OFFSET = 0 - (int)Level::MinLevel;
Logger::Logger()
@ -38,16 +38,16 @@ namespace Feather::Logging
// ESC (\x1B) CSI ([) <COLOR CODES> SGR (m)
switch (level)
{
case Level::WARNING:
case Level::Warning:
// 1 BRIGHT, 33 YELLOW
offset += snprintf(buffer + offset, MAX_LOG_MESSAGE_LENGTH - offset, "\x1B[1;33m");
break;
case Level::ERROR:
case Level::Error:
// 1 BRIGHT, 31 RED
offset += snprintf(buffer + offset, MAX_LOG_MESSAGE_LENGTH - offset, "\x1B[1;31m");
break;
default:
case Level::INFO:
case Level::Info:
break;
}
@ -74,7 +74,7 @@ namespace Feather::Logging
// Append ANSI style reset code 0 and newline
offset += snprintf(buffer + offset, MAX_LOG_MESSAGE_LENGTH - offset, "\x1b[0m\n");
if (level >= Level::INFO) {
if (level >= Level::Info) {
// Info and above go to stdout
printf(buffer);
} else {
@ -86,7 +86,7 @@ namespace Feather::Logging
ChannelID Logger::RegisterChannel(const char* name)
{
if (m_channelCount >= MAX_LOGGING_CHANNEL_COUNT) {
Log_Msg( LOG_LOGGING, ERROR, "Cannot register new logging channel '%s' because the maximum of %d channels has been exceeded.", name, MAX_LOGGING_CHANNEL_COUNT );
Log_Msg( LOG_LOGGING, Error, "Cannot register new logging channel '%s' because the maximum of %d channels has been exceeded.", name, MAX_LOGGING_CHANNEL_COUNT );
return LOG_GENERAL;
}
Channel *channel = new Channel(name);

View File

@ -10,23 +10,23 @@ namespace Feather::Logging
enum class Level
{
// Serious problems
ERROR = -2,
Error = -2,
// Potential problems of note
WARNING = -1,
Warning = -1,
// General messages for end-users
INFO = 0,
Info = 0,
// More advanced information for problem-solving
DEBUG = 1,
Debug = 1,
// Fine grained spew
TRACE = 2,
Trace = 2,
// These are an inclusve interval
MIN_LEVEL = ERROR,
MAX_LEVEL = TRACE,
MinLevel = Error,
MaxLevel = Trace,
};
/*==== Channels ==============================*/
@ -62,22 +62,22 @@ namespace Feather::Logging
extern Logger GlobalLogger;
}
#define REGISTER_LOGGING_CHANNEL(Name) Feather::Logging::GlobalLogger.RegisterChannel(Name);
#define REGISTER_LOGGING_CHANNEL(Name) ::Feather::Logging::GlobalLogger.RegisterChannel(Name);
// 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__)
#define Log_Msg(_Channel, _Level, _Message, ...) ::Feather::Logging::GlobalLogger.LogDirect(::Feather::Logging::_Channel, ::Feather::Logging::Level::_Level, _Message, ##__VA_ARGS__)
// Logs a general message for end-users
#define Log_Info(Message, ...) Log_Msg(LOG_GENERAL, INFO, Message, ##__VA_ARGS__)
#define Log_Info(Message, ...) Log_Msg(LOG_GENERAL, Info, Message, ##__VA_ARGS__)
// Logs a potential problem of note
#define Log_Warn(Message, ...) Log_Msg(LOG_GENERAL, WARNING, Message, ##__VA_ARGS__)
#define Log_Warn(Message, ...) Log_Msg(LOG_GENERAL, Warning, Message, ##__VA_ARGS__)
// Logs a serious problem
#define Log_Error(Message, ...) Log_Msg(LOG_GENERAL, ERROR, Message, ##__VA_ARGS__)
#define Log_Error(Message, ...) Log_Msg(LOG_GENERAL, Error, Message, ##__VA_ARGS__)
// Logs debug information for developers
#define Log_Debug(Message, ...) Log_Msg(LOG_GENERAL, DEBUG, Message, ##__VA_ARGS__)
#define Log_Debug(Message, ...) Log_Msg(LOG_GENERAL, Debug, Message, ##__VA_ARGS__)
// Logs fine grained debug information
#define Log_Trace(Message, ...) Log_Msg(LOG_GENERAL, TRACE, Message, ##__VA_ARGS__)
#define Log_Trace(Message, ...) Log_Msg(LOG_GENERAL, Trace, Message, ##__VA_ARGS__)