Fix logging in files with Windows includes
This commit is contained in:
parent
8a65a66924
commit
134fd77247
|
@ -15,13 +15,13 @@ namespace Feather::Logging
|
||||||
|
|
||||||
// Since min and max are inclusive we have to add 1 here
|
// Since min and max are inclusive we have to add 1 here
|
||||||
// This assumes max > min (they better be)
|
// 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
|
// Temporary solution while we don't have named enums
|
||||||
static const char *s_levelNames[NUM_LEVELS] = {"ERROR", "WARNING", "INFO", "DEBUG", "TRACE"};
|
static const char *s_levelNames[NUM_LEVELS] = {"ERROR", "WARNING", "INFO", "DEBUG", "TRACE"};
|
||||||
|
|
||||||
// Shifts an enum value to be a positive index in s_levelNames
|
// 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()
|
Logger::Logger()
|
||||||
|
@ -38,16 +38,16 @@ namespace Feather::Logging
|
||||||
// ESC (\x1B) CSI ([) <COLOR CODES> SGR (m)
|
// ESC (\x1B) CSI ([) <COLOR CODES> SGR (m)
|
||||||
switch (level)
|
switch (level)
|
||||||
{
|
{
|
||||||
case Level::WARNING:
|
case Level::Warning:
|
||||||
// 1 BRIGHT, 33 YELLOW
|
// 1 BRIGHT, 33 YELLOW
|
||||||
offset += snprintf(buffer + offset, MAX_LOG_MESSAGE_LENGTH - offset, "\x1B[1;33m");
|
offset += snprintf(buffer + offset, MAX_LOG_MESSAGE_LENGTH - offset, "\x1B[1;33m");
|
||||||
break;
|
break;
|
||||||
case Level::ERROR:
|
case Level::Error:
|
||||||
// 1 BRIGHT, 31 RED
|
// 1 BRIGHT, 31 RED
|
||||||
offset += snprintf(buffer + offset, MAX_LOG_MESSAGE_LENGTH - offset, "\x1B[1;31m");
|
offset += snprintf(buffer + offset, MAX_LOG_MESSAGE_LENGTH - offset, "\x1B[1;31m");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case Level::INFO:
|
case Level::Info:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ namespace Feather::Logging
|
||||||
// Append ANSI style reset code 0 and newline
|
// Append ANSI style reset code 0 and newline
|
||||||
offset += snprintf(buffer + offset, MAX_LOG_MESSAGE_LENGTH - offset, "\x1b[0m\n");
|
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
|
// Info and above go to stdout
|
||||||
printf(buffer);
|
printf(buffer);
|
||||||
} else {
|
} else {
|
||||||
|
@ -86,7 +86,7 @@ namespace Feather::Logging
|
||||||
ChannelID Logger::RegisterChannel(const char* name)
|
ChannelID Logger::RegisterChannel(const char* name)
|
||||||
{
|
{
|
||||||
if (m_channelCount >= MAX_LOGGING_CHANNEL_COUNT) {
|
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;
|
return LOG_GENERAL;
|
||||||
}
|
}
|
||||||
Channel *channel = new Channel(name);
|
Channel *channel = new Channel(name);
|
||||||
|
|
|
@ -10,23 +10,23 @@ namespace Feather::Logging
|
||||||
enum class Level
|
enum class Level
|
||||||
{
|
{
|
||||||
// Serious problems
|
// Serious problems
|
||||||
ERROR = -2,
|
Error = -2,
|
||||||
|
|
||||||
// Potential problems of note
|
// Potential problems of note
|
||||||
WARNING = -1,
|
Warning = -1,
|
||||||
|
|
||||||
// General messages for end-users
|
// General messages for end-users
|
||||||
INFO = 0,
|
Info = 0,
|
||||||
|
|
||||||
// More advanced information for problem-solving
|
// More advanced information for problem-solving
|
||||||
DEBUG = 1,
|
Debug = 1,
|
||||||
|
|
||||||
// Fine grained spew
|
// Fine grained spew
|
||||||
TRACE = 2,
|
Trace = 2,
|
||||||
|
|
||||||
// These are an inclusve interval
|
// These are an inclusve interval
|
||||||
MIN_LEVEL = ERROR,
|
MinLevel = Error,
|
||||||
MAX_LEVEL = TRACE,
|
MaxLevel = Trace,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*==== Channels ==============================*/
|
/*==== Channels ==============================*/
|
||||||
|
@ -62,22 +62,22 @@ namespace Feather::Logging
|
||||||
extern Logger GlobalLogger;
|
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
|
// 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
|
// 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
|
// 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
|
// 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
|
// 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
|
// 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__)
|
||||||
|
|
Loading…
Reference in New Issue