Skip to content

Commit

Permalink
Add log_*_color macros, deprecate IConsole::Print
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Robyt3 committed Oct 23, 2024
1 parent 5a716ae commit e2df30a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/base/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
6 changes: 6 additions & 0 deletions src/engine/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e2df30a

Please sign in to comment.