sketch out logging stub, to begin marking up debugger layers with logging - high level stuff still wip

This commit is contained in:
Ryan Fleury
2024-04-17 14:32:09 -07:00
parent a954317500
commit b995909997
12 changed files with 183 additions and 3 deletions
+1
View File
@@ -15,4 +15,5 @@
#include "base_thread_context.c"
#include "base_command_line.c"
#include "base_markup.c"
#include "base_log.c"
#include "base_entry_point.c"
+1
View File
@@ -17,6 +17,7 @@
#include "base_thread_context.h"
#include "base_command_line.h"
#include "base_markup.h"
#include "base_log.h"
#include "base_entry_point.h"
#endif // BASE_INC_H
+72
View File
@@ -0,0 +1,72 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Globals/Thread-Locals
C_LINKAGE thread_static Log *log_active;
#if !BUILD_SUPPLEMENTARY_UNIT
C_LINKAGE thread_static Log *log_active = 0;
#endif
////////////////////////////////
//~ rjf: Log Creation/Selection
internal Log *
log_alloc(void)
{
Arena *arena = arena_alloc();
Log *log = push_array(arena, Log, 1);
log->arena = arena;
log->log_buffer_start_pos = arena_pos(arena);
return log;
}
internal void
log_release(Log *log)
{
arena_release(log->arena);
}
internal void
log_select(Log *log)
{
log_active = log;
}
////////////////////////////////
//~ rjf: Log Building/Clearing
internal void
log_msg(String8 string)
{
if(log_active != 0)
{
str8_list_push(log_active->arena, &log_active->log_buffer_strings, string);
}
}
internal void
log_msgf(char *fmt, ...)
{
if(log_active != 0)
{
Temp scratch = scratch_begin(0, 0);
va_list args;
va_start(args, fmt);
String8 string = push_str8fv(scratch.arena, fmt, args);
log_msg(string);
va_end(args);
scratch_end(scratch);
}
}
internal void
log_clear(void)
{
if(log_active != 0)
{
arena_pop_to(log_active->arena, log_active->log_buffer_start_pos);
MemoryZeroStruct(&log_active->log_buffer_strings);
}
}
+32
View File
@@ -0,0 +1,32 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_LOG_H
#define BASE_LOG_H
////////////////////////////////
//~ rjf: Log Type
typedef struct Log Log;
struct Log
{
Arena *arena;
U64 log_buffer_start_pos;
String8List log_buffer_strings;
};
////////////////////////////////
//~ rjf: Log Creation/Selection
internal Log *log_alloc(void);
internal void log_release(Log *log);
internal void log_select(Log *log);
////////////////////////////////
//~ rjf: Log Building/Clearing
internal void log_msg(String8 string);
internal void log_msgf(char *fmt, ...);
internal void log_clear(void);
#endif // BASE_LOG_H
+2 -2
View File
@@ -4,9 +4,9 @@
#ifndef BASE_MARKUP_H
#define BASE_MARKUP_H
internal void thread_namef(char *fmt, ...);
internal void thread_name(String8 string);
internal void thread_namef(char *fmt, ...);
#define ThreadNameF(...) (ProfThreadName(__VA_ARGS__), thread_namef(__VA_ARGS__))
#define ThreadName(str) (ProfThreadName("%s", str8_varg(str)), thread_name(str))
#define ThreadName(str) (ProfThreadName("%.*s", str8_varg(str)), thread_name(str))
#endif // BASE_MARKUP_H