69 if constexpr (std::is_same_v<T, bool>)
72 arg.
text = value ?
"true" :
"false";
74 else if constexpr (std::is_enum_v<T>)
77 arg.i =
static_cast<int64_t
>(value);
79 else if constexpr (std::is_integral_v<T> && std::is_signed_v<T>)
84 else if constexpr (std::is_integral_v<T>)
89 else if constexpr (std::is_floating_point_v<T>)
92 arg.f =
static_cast<double>(value);
96 static_assert(std::is_convertible_v<const T&, std::string_view>,
"unsupported log argument type");
98 arg.
text = std::string_view(value);
150 std::span<const LogArg> args,
const char* file =
"", uint32_t line = 0);
169 template<
typename... Args>
171 std::string_view messageTemplate,
const Args&... args)
173 static_assert(
sizeof...(Args) <=
kMaxLogArgs,
"too many log arguments");
177 LogMessage(category, severity, messageTemplate, std::span<const LogArg>(packed,
sizeof...(Args)), file, line);
182#define TACHYON_LOG_TRACE(category, ...) ::tachyon::Diagnostics::Log(category, ::tachyon::Diagnostics::LogSeverity::Trace, __FILE__, __LINE__, __VA_ARGS__)
183#define TACHYON_LOG_DEBUG(category, ...) ::tachyon::Diagnostics::Log(category, ::tachyon::Diagnostics::LogSeverity::Debug, __FILE__, __LINE__, __VA_ARGS__)
184#define TACHYON_LOG_INFO(category, ...) ::tachyon::Diagnostics::Log(category, ::tachyon::Diagnostics::LogSeverity::Info, __FILE__, __LINE__, __VA_ARGS__)
185#define TACHYON_LOG_WARNING(category, ...) ::tachyon::Diagnostics::Log(category, ::tachyon::Diagnostics::LogSeverity::Warning, __FILE__, __LINE__, __VA_ARGS__)
186#define TACHYON_LOG_ERROR(category, ...) ::tachyon::Diagnostics::Log(category, ::tachyon::Diagnostics::LogSeverity::Error, __FILE__, __LINE__, __VA_ARGS__)
187#define TACHYON_LOG_CRITICAL(category, ...) ::tachyon::Diagnostics::Log(category, ::tachyon::Diagnostics::LogSeverity::Critical, __FILE__, __LINE__, __VA_ARGS__)
uint32_t CopyRecentLogRecords(std::span< LogRecord > out)
Copies up to out.size() of the most recent records, oldest first.
constexpr int kLogRingCapacity
Definition gui_logging.h:105
void SetMinimumLogSeverity(LogSeverity severity)
Records below the minimum severity are dropped before any work is done.
void RemoveLogSink(LogSinkFn sink, void *context)
Unregisters a sink added with the same sink and context. [MainThread].
bool AddLogSink(LogSinkFn sink, void *context)
Registers sink, called with every record and context.
void SetLogConsoleOutput(bool enabled)
Turns the built-in stdout/stderr/debugger sink on or off (on by default). [AnyThread].
void(*)(const LogRecord &record, void *context) LogSinkFn
A log sink. Sinks run on the emitting thread, under the logger's lock.
Definition gui_logging.h:141
void LogMessage(LogCategory category, LogSeverity severity, std::string_view messageTemplate, std::span< const LogArg > args, const char *file="", uint32_t line=0)
Emits one record. Prefer the TACHYON_LOG_* macros, which add the source location. [AnyThread].
constexpr LogCategory MakeLogCategory(std::string_view staticName)
A category named staticName, which must be a static string.
Definition gui_logging.h:41
std::string_view LogArgText(const LogRecord &record, const LogArg &arg)
constexpr int kMaxLogArgs
Definition gui_logging.h:103
void ReportMisuse(LogCategory category, const char *message)
API misuse (an unbalanced Begin/End, a call outside its frame, ...) is reported, not fatal: the calle...
const char * LogSeverityName(LogSeverity severity)
LogSeverity
Definition gui_logging.h:28
void ResetMisuseReports()
Lets every misuse be reported again (tests). [AnyThread].
size_t FormatLogMessage(const LogRecord &record, std::span< char > out)
Writes the template with its arguments substituted, NUL-terminated and truncated to out.
constexpr int kMaxLogSinks
Definition gui_logging.h:106
LogSeverity GetMinimumLogSeverity()
Records below the minimum severity are dropped before any work is done.
constexpr int kLogTextCapacity
bytes shared by a record's text arguments
Definition gui_logging.h:104
uint64_t LatestLogSequence()
Sequence number of the newest record (0 before the first). [AnyThread].
void Log(LogCategory category, LogSeverity severity, const char *file, uint32_t line, std::string_view messageTemplate, const Args &... args)
Emits a record with args (at most kMaxLogArgs) for the {} in messageTemplate; what the TACHYON_LOG_* ...
Definition gui_logging.h:170
LogArg MakeLogArg(const T &value)
Definition gui_logging.h:66
@ Warning
Definition gui_logging.h:28
@ Critical
Definition gui_logging.h:28
@ Info
Definition gui_logging.h:28
@ Debug
Definition gui_logging.h:28
@ Trace
Definition gui_logging.h:28
@ None
Definition gui_element_flags.h:19
Definition gui_logging.h:24
constexpr uint64_t CalculateConst(std::string_view str, uint64_t hash=Basis)
FNV-1a hash of str, usable at compile time; hash continues an earlier hash.
Definition gui_hash.h:18
One argument.
Definition gui_logging.h:49
Kind kind
Picks i, u, f or the text.
Definition gui_logging.h:53
uint16_t textLength
record only: the text's length in bytes
Definition gui_logging.h:62
Kind
Which value the argument holds.
Definition gui_logging.h:51
@ Int
Definition gui_logging.h:51
@ Float
Definition gui_logging.h:51
@ None
Definition gui_logging.h:51
@ Text
Definition gui_logging.h:51
@ Uint
Definition gui_logging.h:51
uint16_t textOffset
record only: where the text starts in LogRecord::text
Definition gui_logging.h:61
std::string_view text
Kind::Text, while passed to LogMessage.
Definition gui_logging.h:60
A subsystem's log category.
Definition gui_logging.h:35
std::string_view name
Shown with each record.
Definition gui_logging.h:37
One message as sinks and CopyRecentLogRecords see it.
Definition gui_logging.h:111
LogCategory category
Where it comes from.
Definition gui_logging.h:115
const char * file
Source file of the call (FILE).
Definition gui_logging.h:118
uint64_t sequence
1-based, increases by one per record
Definition gui_logging.h:112
LogArg args[kMaxLogArgs]
The arguments; read text ones with LogArgText.
Definition gui_logging.h:121
int64_t timestampNanos
steady clock, see SteadyClockNowNanos
Definition gui_logging.h:113
uint8_t argCount
How many of args are used.
Definition gui_logging.h:120
LogSeverity severity
How serious it is.
Definition gui_logging.h:116
uint32_t line
Source line of the call.
Definition gui_logging.h:119
char text[kLogTextCapacity]
The text arguments' bytes.
Definition gui_logging.h:122
std::string_view messageTemplate
Static, with a {} per argument.
Definition gui_logging.h:117
uint64_t threadId
Hash of the emitting thread's std::thread::id.
Definition gui_logging.h:114
A failure: its category and a human-readable message.
Definition gui_result.h:26