From e2df30a59e874068a9a3a8256c88cb9736be9704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 21 Oct 2024 23:06:43 +0200 Subject: [PATCH] Add `log_*_color` macros, deprecate `IConsole::Print` Add `log_error_color`, `log_warn_color`, `log_info_color`, `log_debug_color` and `log_trace_color` macros to wrap `log_log_color` function with specific log levels. Add comment to mark the `IConsole::Print` function as deprecated in favor of the `log_*` functions, which should be preferred for the following reasons: - They support `printf`-formatting without a separate buffer. - They support all five log levels. - They do not require a pointer to `IConsole` to be used. - Consistency of logging code. --- src/base/log.h | 6 ++++++ src/engine/console.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/base/log.h b/src/base/log.h index 059fae74703..8fab8edd12a 100644 --- a/src/base/log.h +++ b/src/base/log.h @@ -32,6 +32,12 @@ struct LOG_COLOR #define log_debug(sys, ...) log_log(LEVEL_DEBUG, sys, __VA_ARGS__) #define log_trace(sys, ...) log_log(LEVEL_TRACE, sys, __VA_ARGS__) +#define log_error_color(color, sys, ...) log_log_color(LEVEL_ERROR, color, sys, __VA_ARGS__) +#define log_warn_color(color, sys, ...) log_log_color(LEVEL_WARN, color, sys, __VA_ARGS__) +#define log_info_color(color, sys, ...) log_log_color(LEVEL_INFO, color, sys, __VA_ARGS__) +#define log_debug_color(color, sys, ...) log_log_color(LEVEL_DEBUG, color, sys, __VA_ARGS__) +#define log_trace_color(color, sys, ...) log_log_color(LEVEL_TRACE, color, sys, __VA_ARGS__) + /** * @defgroup Log * diff --git a/src/engine/console.h b/src/engine/console.h index 88597b8bb8b..7490dc9ea73 100644 --- a/src/engine/console.h +++ b/src/engine/console.h @@ -110,6 +110,12 @@ class IConsole : public IInterface virtual void ExecuteLineStroked(int Stroke, const char *pStr, int ClientId = -1, bool InterpretSemicolons = true) = 0; virtual bool ExecuteFile(const char *pFilename, int ClientId = -1, bool LogFailure = false, int StorageType = IStorage::TYPE_ALL) = 0; + /** + * @deprecated Prefer using the `log_*` functions from base/log.h instead of this function for the following reasons: + * - They support `printf`-formatting without a separate buffer. + * - They support all five log levels. + * - They do not require a pointer to `IConsole` to be used. + */ virtual void Print(int Level, const char *pFrom, const char *pStr, ColorRGBA PrintColor = gs_ConsoleDefaultColor) const = 0; virtual void SetTeeHistorianCommandCallback(FTeeHistorianCommandCallback pfnCallback, void *pUser) = 0; virtual void SetUnknownCommandCallback(FUnknownCommandCallback pfnCallback, void *pUser) = 0;