mirror of
https://github.com/Ed94/metadesk.git
synced 2026-06-12 23:51:37 -07:00
c8cb9f3995
perf impact of the indirection should be minimal, reduces code duplication. Ideally we'd use gencpp to just have the user specify what they want, then modify which proc is avail by doing the refactors required for using either However, it can't process execution bodies yet or expressions so thats not possible. The other way is to just utilize _Generic to generalize the codepath so that it collapses neater but that leads to a ton of implementation getting lifted to preprocessing... so no.
90 lines
2.0 KiB
C
90 lines
2.0 KiB
C
#ifdef INTELLISENSE_DIRECTIVES
|
|
# include "logger.h"
|
|
# include "thread_context.h"
|
|
#endif
|
|
|
|
// Copyright (c) 2024 Epic Games Tools
|
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
|
|
|
////////////////////////////////
|
|
//~ rjf: Globals/Thread-Locals
|
|
|
|
MD_API_C thread_static Log* log_active;
|
|
#if !BUILD_SUPPLEMENTARY_UNIT
|
|
MD_API_C thread_static Log* log_active = 0;
|
|
#endif
|
|
|
|
////////////////////////////////
|
|
//~ rjf: Log Creation/Selection
|
|
|
|
void
|
|
log_select(Log* log) {
|
|
log_active = log;
|
|
}
|
|
|
|
////////////////////////////////
|
|
//~ rjf: Log Building
|
|
|
|
void
|
|
log_msg(LogMsgKind kind, String8 string) {
|
|
if(log_active != 0 && log_active->top_scope != 0) {
|
|
String8 string_copy = push_str8_copy(log_active->arena, string);
|
|
str8_list_push(log_active->arena, &log_active->top_scope->strings[kind], string_copy);
|
|
}
|
|
}
|
|
|
|
void
|
|
log_msgf(LogMsgKind kind, char *fmt, ...) {
|
|
if(log_active != 0)
|
|
{
|
|
TempArena scratch = scratch_begin(0, 0);
|
|
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
String8 string = push_str8fv(scratch.arena, fmt, args);
|
|
log_msg(kind, string);
|
|
va_end(args);
|
|
|
|
scratch_end(scratch);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////
|
|
//~ rjf: Log Scopes
|
|
|
|
void
|
|
log_scope_begin(void) {
|
|
if (log_active != 0) {
|
|
U64 pos = arena_pos(log_active->arena);
|
|
LogScope* scope = push_array(log_active->arena, LogScope, 1);
|
|
scope->pos = pos;
|
|
sll_stack_push(log_active->top_scope, scope);
|
|
}
|
|
}
|
|
|
|
LogScopeResult
|
|
log_scope_end(Arena *arena)
|
|
{
|
|
LogScopeResult result = {0};
|
|
if(log_active != 0)
|
|
{
|
|
LogScope* scope = log_active->top_scope;
|
|
if(scope != 0)
|
|
{
|
|
sll_stack_pop(log_active->top_scope);
|
|
if(arena != 0)
|
|
{
|
|
for (each_enum_val(LogMsgKind, kind)) {
|
|
TempArena scratch = scratch_begin(&arena, 1);
|
|
String8
|
|
result_unindented = str8_list_join(scratch.arena, &scope->strings[kind], 0);
|
|
result.strings[kind] = indented_from_string(arena, result_unindented);
|
|
scratch_end(scratch);
|
|
}
|
|
}
|
|
arena_pop_to(log_active->arena, scope->pos);
|
|
}
|
|
}
|
|
return result;
|
|
}
|