Skip to content

Commit

Permalink
Add support for verbose trace level logging (#1764)
Browse files Browse the repository at this point in the history
* Add support for verbose trace level logging

* Set trace log color to white and debug log color to cyan
  • Loading branch information
rh101 authored Mar 25, 2024
1 parent d1cf78b commit f0c0c75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/base/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ AX_API LogItem& preprocessLog(LogItem&& item)
std::string_view levelName;
switch (item.level_)
{
case LogLevel::Trace:
levelName = "T/"sv;
break;
case LogLevel::Debug:
levelName = "D/"sv;
break;
Expand All @@ -140,6 +143,10 @@ AX_API LogItem& preprocessLog(LogItem&& item)
constexpr auto colorCodeOfLevel = [](LogLevel level) -> std::string_view {
switch (level)
{
case LogLevel::Trace:
return "\x1b[37m"sv;
case LogLevel::Debug:
return "\x1b[36m"sv;
case LogLevel::Info:
return "\x1b[92m"sv;
case LogLevel::Warn:
Expand Down
2 changes: 2 additions & 0 deletions core/base/Console.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ NS_AX_BEGIN

enum class LogLevel
{
Trace,
Debug,
Info,
Warn,
Expand Down Expand Up @@ -163,6 +164,7 @@ inline void printLogT(_FmtType&& fmt, LogItem& item, _Types&&... args)
#define AXLOG_WITH_LEVEL(level, fmtOrMsg, ...) \
ax::printLogT(FMT_COMPILE("{}" fmtOrMsg), ax::preprocessLog(ax::LogItem{level}), ##__VA_ARGS__)

#define AXLOGT(fmtOrMsg, ...) AXLOG_WITH_LEVEL(ax::LogLevel::Trace, fmtOrMsg, ##__VA_ARGS__)
#define AXLOGD(fmtOrMsg, ...) AXLOG_WITH_LEVEL(ax::LogLevel::Debug, fmtOrMsg, ##__VA_ARGS__)
#define AXLOGI(fmtOrMsg, ...) AXLOG_WITH_LEVEL(ax::LogLevel::Info, fmtOrMsg, ##__VA_ARGS__)
#define AXLOGW(fmtOrMsg, ...) AXLOG_WITH_LEVEL(ax::LogLevel::Warn, fmtOrMsg, ##__VA_ARGS__)
Expand Down

0 comments on commit f0c0c75

Please sign in to comment.