expand base layer logging mechanism with bucketing info; make one bucket for passive log collection, another for user-facing errors; always consume user errors at the top-level and display; use user-error mechanism to communicate bad 32-bit app launches from demon

This commit is contained in:
Ryan Fleury
2024-05-14 08:10:02 -07:00
parent 6c200a59cd
commit 3085482e34
7 changed files with 104 additions and 61 deletions
+10 -7
View File
@@ -37,17 +37,17 @@ log_select(Log *log)
//~ rjf: Log Building/Clearing
internal void
log_msg(String8 string)
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, string_copy);
str8_list_push(log_active->arena, &log_active->top_scope->strings[kind], string_copy);
}
}
internal void
log_msgf(char *fmt, ...)
log_msgf(LogMsgKind kind, char *fmt, ...)
{
if(log_active != 0)
{
@@ -55,7 +55,7 @@ log_msgf(char *fmt, ...)
va_list args;
va_start(args, fmt);
String8 string = push_str8fv(scratch.arena, fmt, args);
log_msg(string);
log_msg(kind, string);
va_end(args);
scratch_end(scratch);
}
@@ -76,10 +76,10 @@ log_scope_begin(void)
}
}
internal String8
internal LogScopeResult
log_scope_end(Arena *arena)
{
String8 result = {0};
LogScopeResult result = {0};
if(log_active != 0)
{
LogScope *scope = log_active->top_scope;
@@ -88,7 +88,10 @@ log_scope_end(Arena *arena)
SLLStackPop(log_active->top_scope);
if(arena != 0)
{
result = str8_list_join(arena, &scope->strings, 0);
for(EachEnumVal(LogMsgKind, kind))
{
result.strings[kind] = str8_list_join(arena, &scope->strings[kind], 0);
}
}
arena_pop_to(log_active->arena, scope->pos);
}
+22 -4
View File
@@ -7,12 +7,26 @@
////////////////////////////////
//~ rjf: Log Types
typedef enum LogMsgKind
{
LogMsgKind_Info,
LogMsgKind_UserError,
LogMsgKind_COUNT
}
LogMsgKind;
typedef struct LogScope LogScope;
struct LogScope
{
LogScope *next;
U64 pos;
String8List strings;
String8List strings[LogMsgKind_COUNT];
};
typedef struct LogScopeResult LogScopeResult;
struct LogScopeResult
{
String8 strings[LogMsgKind_COUNT];
};
typedef struct Log Log;
@@ -32,13 +46,17 @@ internal void log_select(Log *log);
////////////////////////////////
//~ rjf: Log Building
internal void log_msg(String8 string);
internal void log_msgf(char *fmt, ...);
internal void log_msg(LogMsgKind kind, String8 string);
internal void log_msgf(LogMsgKind kind, char *fmt, ...);
#define log_info(s) log_msg(LogMsgKind_Info, (s))
#define log_infof(fmt, ...) log_msgf(LogMsgKind_Info, (fmt), __VA_ARGS__)
#define log_user_error(s) log_msg(LogMsgKind_UserError, (s))
#define log_user_errorf(fmt, ...) log_msgf(LogMsgKind_UserError, (fmt), __VA_ARGS__)
////////////////////////////////
//~ rjf: Log Scopes
internal void log_scope_begin(void);
internal String8 log_scope_end(Arena *arena);
internal LogScopeResult log_scope_end(Arena *arena);
#endif // BASE_LOG_H