Skip to content

Commit

Permalink
Add DEPRECATED Loglevel (#1885)
Browse files Browse the repository at this point in the history
  • Loading branch information
saurtron authored Jan 9, 2025
1 parent 77c4366 commit 6cde9cd
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 44 deletions.
2 changes: 1 addition & 1 deletion rts/Game/UI/KeySet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ bool CKeySet::Parse(const std::string& token, bool showerror)

// parse the modifiers
while (!s.empty()) {
if (ParseModifier(s, "up+", "u+")) { LOG_L(L_WARNING, "KeySet: Up modifier is deprecated"); } else
if (ParseModifier(s, "up+", "u+")) { LOG_L(L_DEPRECATED, "KeySet: Up modifier is deprecated"); } else
if (ParseModifier(s, "any+", "*+")) { modifiers |= KS_ANYMOD; } else
if (ParseModifier(s, "alt+", "a+")) { modifiers |= KS_ALT; } else
if (ParseModifier(s, "ctrl+", "c+")) { modifiers |= KS_CTRL; } else
Expand Down
2 changes: 1 addition & 1 deletion rts/Lua/LuaSyncedRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6149,7 +6149,7 @@ int LuaSyncedRead::GetUnitCommands(lua_State* L)
} else {
static bool deprecatedMsgDone = false;
if (!deprecatedMsgDone) {
LOG_L(L_WARNING, "Getting the command count using GetUnitCommands/GetCommandQueue is deprecated. Please use Spring.GetUnitCommandCount instead.");
LOG_L(L_DEPRECATED, "Getting the command count using GetUnitCommands/GetCommandQueue is deprecated. Please use Spring.GetUnitCommandCount instead.");
deprecatedMsgDone = true;
}
// *get just wants the queue's size
Expand Down
15 changes: 8 additions & 7 deletions rts/Lua/LuaUnsyncedCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,13 @@ int LuaUnsyncedCtrl::Echo(lua_State* L)
* @string section
* @tparam ?number|string logLevel
* Possible values for logLevel are:
* "debug" | LOG.DEBUG
* "info" | LOG.INFO
* "notice" | LOG.NOTICE (engine default)
* "warning" | LOG.WARNING
* "error" | LOG.ERROR
* "fatal" | LOG.FATAL
* "debug" | LOG.DEBUG
* "info" | LOG.INFO
* "notice" | LOG.NOTICE (engine default)
* "deprecated" | LOG.DEPRECATED
* "warning" | LOG.WARNING
* "error" | LOG.ERROR
* "fatal" | LOG.FATAL
* @string logMessage1
* @string[opt] logMessage2
* @string[opt] logMessagen
Expand Down Expand Up @@ -2437,7 +2438,7 @@ int LuaUnsyncedCtrl::UnitIconSetDraw(lua_State* L)
{
static bool deprecatedMsgDone = false;
if (!deprecatedMsgDone) {
LOG_L(L_WARNING, "Spring.UnitIconSetDraw is deprecated. Please use Spring.SetUnitIconDraw instead.");
LOG_L(L_DEPRECATED, "Spring.UnitIconSetDraw is deprecated. Please use Spring.SetUnitIconDraw instead.");
deprecatedMsgDone = true;
}
return LuaUnsyncedCtrl::SetUnitIconDraw(L);
Expand Down
23 changes: 15 additions & 8 deletions rts/Lua/LuaUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,7 @@ bool LuaUtils::PushLogEntries(lua_State* L)
PUSH_LOG_LEVEL(DEBUG);
PUSH_LOG_LEVEL(INFO);
PUSH_LOG_LEVEL(NOTICE);
PUSH_LOG_LEVEL(DEPRECATED);
PUSH_LOG_LEVEL(WARNING);
PUSH_LOG_LEVEL(ERROR);
PUSH_LOG_LEVEL(FATAL);
Expand All @@ -1319,14 +1320,20 @@ int LuaUtils::ParseLogLevel(lua_State* L, int index)
return (lua_tonumber(L, index));

if (lua_israwstring(L, index)) {
switch (lua_tostring(L, index)[0]) {
case 'D': case 'd': { return LOG_LEVEL_DEBUG ; } break;
case 'I': case 'i': { return LOG_LEVEL_INFO ; } break;
case 'N': case 'n': { return LOG_LEVEL_NOTICE ; } break;
case 'W': case 'w': { return LOG_LEVEL_WARNING; } break;
case 'E': case 'e': { return LOG_LEVEL_ERROR ; } break;
case 'F': case 'f': { return LOG_LEVEL_FATAL ; } break;
default : { } break;
const char* logLevel = lua_tostring(L, index);
switch (logLevel[0]) {
case 'D': case 'd': {
if (strlen(logLevel) > 2 && (logLevel[2] == 'P' || logLevel[2] == 'p'))
return LOG_LEVEL_DEPRECATED;
else
return LOG_LEVEL_DEBUG;
} break;
case 'I': case 'i': { return LOG_LEVEL_INFO ; } break;
case 'N': case 'n': { return LOG_LEVEL_NOTICE ; } break;
case 'W': case 'w': { return LOG_LEVEL_WARNING ; } break;
case 'E': case 'e': { return LOG_LEVEL_ERROR ; } break;
case 'F': case 'f': { return LOG_LEVEL_FATAL ; } break;
default : { } break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions rts/System/Log/ConsoleSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ static void log_sink_record_console(int level, const char* section, const char*
if (colorizedOutput) {
if (level >= LOG_LEVEL_ERROR) {
fstr = "\033[90m%s\033[31m%s\033[39m\n";
} else if (level == LOG_LEVEL_DEPRECATED) {
fstr = "\033[90m%s\033[34m%s\033[39m\n";
} else if (level >= LOG_LEVEL_WARNING) {
fstr = "\033[90m%s\033[33m%s\033[39m\n";
} else {
Expand Down
13 changes: 7 additions & 6 deletions rts/System/Log/ILog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
*
* Aims:
* - Support a fixed set of severities levels:
* * L_DEBUG : fine-grained information that is most useful to debug
* * L_INFO : same as L_NOTICE just that it is surpressed on RELEASE builds when a non-default logSection is set
* * L_NOTICE : default log level (always outputed)
* * L_WARNING : potentially harmful situations
* * L_ERROR : errors that might still allow the application to keep running
* * L_FATAL : very severe errors that will lead the application to abort
* * L_DEBUG : fine-grained information that is most useful to debug
* * L_INFO : same as L_NOTICE just that it is surpressed on RELEASE builds when a non-default logSection is set
* * L_NOTICE : default log level (always outputed)
* * L_DEPRECATED : deprecation messages
* * L_WARNING : potentially harmful situations
* * L_ERROR : errors that might still allow the application to keep running
* * L_FATAL : very severe errors that will lead the application to abort
* (the "L_" prefix is required for disambiguation from other symbols)
* - Support arbitrary sections (strings).
* - Allow to set the minimum severity level
Expand Down
17 changes: 9 additions & 8 deletions rts/System/Log/Level.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
*/
///@{

#define LOG_LEVEL_ALL 0
#define LOG_LEVEL_ALL 0

#define LOG_LEVEL_DEBUG 20
#define LOG_LEVEL_INFO 30
#define LOG_LEVEL_NOTICE 35
#define LOG_LEVEL_WARNING 40
#define LOG_LEVEL_ERROR 50
#define LOG_LEVEL_FATAL 60
#define LOG_LEVEL_DEBUG 20
#define LOG_LEVEL_INFO 30
#define LOG_LEVEL_NOTICE 35
#define LOG_LEVEL_DEPRECATED 37
#define LOG_LEVEL_WARNING 40
#define LOG_LEVEL_ERROR 50
#define LOG_LEVEL_FATAL 60

#define LOG_LEVEL_NONE 255
#define LOG_LEVEL_NONE 255

#define DEFAULT_LOG_LEVEL_SHORT L_NOTICE
#define DEFAULT_LOG_LEVEL LOG_LEVEL_NOTICE
Expand Down
28 changes: 15 additions & 13 deletions rts/System/Log/LogUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
const char* log_util_levelToString(int level)
{
switch (level) {
case LOG_LEVEL_DEBUG: return "Debug";
case LOG_LEVEL_INFO: return "Info";
case LOG_LEVEL_NOTICE: return "Notice";
case LOG_LEVEL_WARNING: return "Warning";
case LOG_LEVEL_ERROR: return "Error";
case LOG_LEVEL_FATAL: return "Fatal";
default: return "<unknown>";
case LOG_LEVEL_DEBUG: return "Debug";
case LOG_LEVEL_INFO: return "Info";
case LOG_LEVEL_NOTICE: return "Notice";
case LOG_LEVEL_DEPRECATED: return "Deprecated";
case LOG_LEVEL_WARNING: return "Warning";
case LOG_LEVEL_ERROR: return "Error";
case LOG_LEVEL_FATAL: return "Fatal";
default: return "<unknown>";
}
}

Expand All @@ -33,12 +34,13 @@ char log_util_levelToChar(int level)

int log_util_getNearestLevel(int level)
{
if (level >= LOG_LEVEL_FATAL) return LOG_LEVEL_FATAL;
if (level >= LOG_LEVEL_ERROR) return LOG_LEVEL_ERROR;
if (level >= LOG_LEVEL_WARNING) return LOG_LEVEL_WARNING;
if (level >= LOG_LEVEL_NOTICE) return LOG_LEVEL_NOTICE;
if (level >= LOG_LEVEL_INFO) return LOG_LEVEL_INFO;
if (level >= LOG_LEVEL_DEBUG) return LOG_LEVEL_DEBUG;
if (level >= LOG_LEVEL_FATAL) return LOG_LEVEL_FATAL;
if (level >= LOG_LEVEL_ERROR) return LOG_LEVEL_ERROR;
if (level >= LOG_LEVEL_WARNING) return LOG_LEVEL_WARNING;
if (level >= LOG_LEVEL_DEPRECATED) return LOG_LEVEL_DEPRECATED;
if (level >= LOG_LEVEL_NOTICE) return LOG_LEVEL_NOTICE;
if (level >= LOG_LEVEL_INFO) return LOG_LEVEL_INFO;
if (level >= LOG_LEVEL_DEBUG) return LOG_LEVEL_DEBUG;
return DEFAULT_LOG_LEVEL;
}

Expand Down

0 comments on commit 6cde9cd

Please sign in to comment.