mirror of
https://github.com/Ed94/metadesk.git
synced 2026-06-12 23:51:37 -07:00
logger
This commit is contained in:
Vendored
+2
-1
@@ -45,7 +45,8 @@
|
||||
"stddef.h": "c",
|
||||
"wmmintrin.h": "c",
|
||||
"thread": "c",
|
||||
"cmath": "c"
|
||||
"cmath": "c",
|
||||
"string.h": "c"
|
||||
},
|
||||
"workbench.colorCustomizations": {
|
||||
"activityBar.activeBackground": "#713fb8",
|
||||
|
||||
@@ -61,12 +61,12 @@
|
||||
#endif
|
||||
|
||||
#if defined(GCC_VERSION_CHECK)
|
||||
# undef GCC_VERSION_CHECK
|
||||
# undef GCC_VERSION_CHECK
|
||||
#endif
|
||||
#if defined(GEN_GCC_VERSION)
|
||||
# define GCC_VERSION_CHECK(major,minor,patch) (GEN_GCC_VERSION >= GEN_VERSION_ENCODE(major, minor, patch))
|
||||
# define GCC_VERSION_CHECK(major,minor,patch) (GEN_GCC_VERSION >= GEN_VERSION_ENCODE(major, minor, patch))
|
||||
#else
|
||||
# define GCC_VERSION_CHECK(major,minor,patch) (0)
|
||||
# define GCC_VERSION_CHECK(major,minor,patch) (0)
|
||||
#endif
|
||||
|
||||
#pragma endregion Compiler Vendor
|
||||
|
||||
+33
-83
@@ -1,103 +1,53 @@
|
||||
#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
|
||||
|
||||
C_LINKAGE thread_static Log *log_active;
|
||||
MD_API_C thread_static Log *log_active;
|
||||
#if !BUILD_SUPPLEMENTARY_UNIT
|
||||
C_LINKAGE thread_static Log *log_active = 0;
|
||||
MD_API_C 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;
|
||||
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(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);
|
||||
}
|
||||
}
|
||||
|
||||
internal void
|
||||
log_msgf(LogMsgKind kind, 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(kind, string);
|
||||
va_end(args);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
void
|
||||
log_select(Log* log) {
|
||||
log_active = log;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Scopes
|
||||
|
||||
internal 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;
|
||||
SLLStackPush(log_active->top_scope, scope);
|
||||
}
|
||||
}
|
||||
|
||||
internal LogScopeResult
|
||||
LogScopeResult
|
||||
log_scope_end(Arena *arena)
|
||||
{
|
||||
LogScopeResult result = {0};
|
||||
if(log_active != 0)
|
||||
{
|
||||
LogScope *scope = log_active->top_scope;
|
||||
if(scope != 0)
|
||||
{
|
||||
SLLStackPop(log_active->top_scope);
|
||||
if(arena != 0)
|
||||
{
|
||||
for(EachEnumVal(LogMsgKind, kind))
|
||||
{
|
||||
Temp 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;
|
||||
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)) {
|
||||
// TODO(Ed): Review
|
||||
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;
|
||||
}
|
||||
|
||||
+77
-28
@@ -3,70 +3,119 @@
|
||||
# include "base_types.h"
|
||||
# include "strings.h"
|
||||
# include "arena.h"
|
||||
# include "thread_context.h"
|
||||
#endif
|
||||
|
||||
// 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 Types
|
||||
|
||||
typedef enum LogMsgKind
|
||||
typedef enum LogMsgKind LogMsgKind;
|
||||
enum LogMsgKind
|
||||
{
|
||||
LogMsgKind_Info,
|
||||
LogMsgKind_UserError,
|
||||
LogMsgKind_COUNT
|
||||
}
|
||||
LogMsgKind;
|
||||
LogMsgKind_Info,
|
||||
LogMsgKind_UserError,
|
||||
LogMsgKind_COUNT
|
||||
};
|
||||
|
||||
typedef struct LogScope LogScope;
|
||||
struct LogScope
|
||||
{
|
||||
LogScope *next;
|
||||
U64 pos;
|
||||
String8List strings[LogMsgKind_COUNT];
|
||||
LogScope* next;
|
||||
U64 pos;
|
||||
String8List strings[LogMsgKind_COUNT];
|
||||
};
|
||||
|
||||
typedef struct LogScopeResult LogScopeResult;
|
||||
struct LogScopeResult
|
||||
{
|
||||
String8 strings[LogMsgKind_COUNT];
|
||||
String8 strings[LogMsgKind_COUNT];
|
||||
};
|
||||
|
||||
typedef struct Log Log;
|
||||
struct Log
|
||||
{
|
||||
Arena *arena;
|
||||
LogScope *top_scope;
|
||||
Arena* arena;
|
||||
LogScope* top_scope;
|
||||
};
|
||||
|
||||
#ifndef LOG_DEFAULT_ARENA_BLOCK_SIZE
|
||||
#define LOG_DEFAULT_ARENA_BLOCK_SIZE VARENA_DEFAULT_RESERVE
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Creation/Selection
|
||||
|
||||
internal Log *log_alloc(void);
|
||||
internal void log_release(Log *log);
|
||||
internal void log_select(Log *log);
|
||||
Log* log_alloc(AllocatorInfo ainfo);
|
||||
void log_release(Log* log);
|
||||
MD_API void log_select (Log* log);
|
||||
|
||||
inline Log*
|
||||
log_alloc(AllocatorInfo ainfo, U64 arena_block_size) {
|
||||
if (arena_block_size == 0) {
|
||||
arena_block_size = LOG_DEFAULT_ARENA_BLOCK_SIZE;
|
||||
}
|
||||
Arena* arena = arena_alloc(.backing = ainfo, .block_size = arena_block_size);
|
||||
Log* log = push_array(arena, Log, 1);
|
||||
log->arena = arena;
|
||||
return log;
|
||||
}
|
||||
|
||||
inline void log_release(Log* log) { arena_release(log->arena); }
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Building
|
||||
|
||||
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))
|
||||
void log_msg (LogMsgKind kind, String8 string);
|
||||
void log_msgf(LogMsgKind kind, char* fmt, ...);
|
||||
|
||||
inline 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);
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
log_msgf(LogMsgKind kind, char *fmt, ...) {
|
||||
if(log_active != 0)
|
||||
{
|
||||
// TODO(Ed): Review
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
#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__)
|
||||
|
||||
#define LogInfoNamedBlock(s) DeferLoop(log_infof("%S:\n{\n", (s)), log_infof("}\n"))
|
||||
#define LogInfoNamedBlockF(fmt, ...) DeferLoop((log_infof(fmt, __VA_ARGS__), log_infof(":\n{\n")), log_infof("}\n"))
|
||||
#define log_info_named_block(s) defer_loop(log_infof("%S:\n{\n", (s)), log_infof("}\n"))
|
||||
#define log_info_named_blockf(fmt, ...) defer_loop((log_infof(fmt, __VA_ARGS__), log_infof(":\n{\n")), log_infof("}\n"))
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Log Scopes
|
||||
|
||||
internal void log_scope_begin(void);
|
||||
internal LogScopeResult log_scope_end(Arena *arena);
|
||||
void log_scope_begin(void);
|
||||
MD_API LogScopeResult log_scope_end(Arena* arena);
|
||||
|
||||
#endif // BASE_LOG_H
|
||||
inline 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);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -132,10 +132,10 @@
|
||||
//~ rjf: For-Loop Construct Macros
|
||||
|
||||
#ifndef defer_loop
|
||||
#define defer_loop(begin, end) for (int _i_ = ((begin), 0); ! _i_; _i_ += 1, (end))
|
||||
#define defer_loop(begin, end) for (int _i_ = ((begin), 0); ! _i_; _i_ += 1, (end))
|
||||
#endif
|
||||
#ifndef defer_loop_checked
|
||||
#define defer_loop_checked(begin, end) for (int _i_ = 2 * ! (begin); (_i_ == 2 ? ((end), 0) : !_i_); _i_ += 1, (end))
|
||||
#define defer_loop_checked(begin, end) for (int _i_ = 2 * ! (begin); (_i_ == 2 ? ((end), 0) : !_i_); _i_ += 1, (end))
|
||||
#endif
|
||||
|
||||
#ifndef each_enum_val
|
||||
|
||||
+1
-1
@@ -21,11 +21,11 @@ MD_NS_BEGIN
|
||||
#include "base/memory.h"
|
||||
#include "base/memory_substrate.h"
|
||||
#include "base/arena.h"
|
||||
#include "base/thread_context.h"
|
||||
#include "base/space.h"
|
||||
#include "base/math.h"
|
||||
#include "base/toolchain.h"
|
||||
#include "base/strings.h"
|
||||
#include "base/thread_context.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/markup.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user