ReXGlue SDK
Loading...
Searching...
No Matches
rex::log Namespace Reference

Classes

struct  CapturedMessage
struct  CategoryState
class  ILogSink
struct  LineFormat
class  LogCaptureSink
class  LogCategory
class  LogFileSink
struct  Message
class  OncePerKey

Enumerations

enum class  Level : u8 {
  kTrace , kDev , kDebug , kInfo ,
  kWarn , kError , kCritical , kOff
}
enum class  TimestampStyle : u8 { kNone , kClock , kDateTime , kElapsed }

Functions

Result< Level > ParseLevel (std::string_view text)
std::string_view LevelName (Level level)
void Flush ()
template<typename Fn>
void NoThrow (const LogCategory &category, Fn &&fn) noexcept
std::string FormatLine (const Message &message, const LineFormat &format)
std::string_view LevelColor (Level level)
char LevelLetter (Level level)

Variables

constexpr std::array< std::string_view, 8 > kLevelNames
constexpr size_t kMessageLevelCount = 7
constexpr std::string_view kColorReset = "\x1b[0m"

Detailed Description

Log levels, categories, sinks and the logger.

Enumeration Type Documentation

◆ Level

enum class rex::log::Level : u8
strong

Severity of a log message, least severe first.

Enumerator
kTrace 

Per instruction, per packet and per iteration detail.

kDev 

Detail for people porting a title. ReX debug output and repeat stub calls.

kDebug 

State changes and intermediate values.

kInfo 

Operational events a user reads. At most a few lines per subsystem start.

kWarn 

Recoverable problems, fallbacks and unsupported features.

kError 

Failures that lose functionality.

kCritical 

Unrecoverable state, written right before an abort.

kOff 

Threshold only. Nothing is written at it.

◆ TimestampStyle

enum class rex::log::TimestampStyle : u8
strong

Timestamp written at the start of a line.

Enumerator
kClock 

Local wall clock with milliseconds.

kDateTime 

Local date and wall clock with milliseconds.

kElapsed 

Seconds since the logger started, with a leading plus sign.

Function Documentation

◆ Flush()

void rex::log::Flush ( )

Writes buffered output of every sink. For crash handlers that hold no API handle.

◆ FormatLine()

std::string rex::log::FormatLine ( const Message & message,
const LineFormat & format )

Renders a message as a single line without a line break.

Returns
The line. Color is written as ANSI SGR codes.

◆ LevelColor()

std::string_view rex::log::LevelColor ( Level level)

Returns the ANSI SGR prefix of a level, empty for Info.

◆ LevelLetter()

char rex::log::LevelLetter ( Level level)

Returns the file column letter of a level.

◆ LevelName()

std::string_view rex::log::LevelName ( Level level)

Returns the lowercase name of a level. ParseLevel accepts the name.

◆ NoThrow()

template<typename Fn>
void rex::log::NoThrow ( const LogCategory & category,
Fn && fn )
noexcept

Runs a teardown step and logs anything it throws instead of letting it escape.

Template Parameters
FnCallable that takes no arguments.
Parameters
categoryCategory of the log line for a throw.

◆ ParseLevel()

Result< Level > rex::log::ParseLevel ( std::string_view text)
nodiscard

Parses a level name.

Parameters
textOne of trace, dev, debug, info, warn, error, critical or off, in any case.
Returns
The level, or an error naming the text.

Variable Documentation

◆ kColorReset

std::string_view rex::log::kColorReset = "\x1b[0m"
inlineconstexpr

The ANSI SGR code that ends a colored run.

◆ kLevelNames

std::array<std::string_view, 8> rex::log::kLevelNames
inlineconstexpr
Initial value:
= {
"trace", "dev", "debug", "info", "warn", "error", "critical", "off"}

Lowercase level names in level order, kOff last.

◆ kMessageLevelCount

size_t rex::log::kMessageLevelCount = 7
inlineconstexpr

Number of levels a message can carry, kTrace through kCritical.