simplify log and mt_tweak_color

This commit is contained in:
Krzosa Karol
2025-01-20 09:03:57 +01:00
parent ac2763f87b
commit 63cc0d92f1
8 changed files with 68 additions and 212 deletions

View File

@@ -17,6 +17,5 @@ gb_thread thread_ctx_t tcx = {
.log = {
.break_on_fatal = true,
.log_proc = default_log_proc,
.flags = log_flag_file_path,
}
};

View File

@@ -1,7 +1,5 @@
const i32 module_lex = 1;
#define lex_error(TOKEN, STRING) do {\
errorf(module_lex, STRING);\
errorf(STRING);\
TOKEN->kind = lex_kind_error;\
TOKEN->string = s8_lit(STRING);\
} while (0)

View File

@@ -1,51 +1,32 @@
fn char *log_level_str(log_level_t level) {
fn void log_basef(log_level_t level, s8_t file_and_line, const char *str, ...) {
ma_temp_t scratch = ma_begin_scratch();
S8_FMT(scratch.arena, str, string);
tcx.log.log_proc(level, file_and_line, string);
ma_end_scratch(scratch);
}
fn void default_log_proc(log_level_t level, s8_t file_and_line, s8_t string) {
ma_temp_t scratch = ma_begin_scratch();
switch(level) {
case log_level_debug: return "DEBUG";
case log_level_info: return "INFO";
case log_level_warning: return "WARN";
case log_level_error: return "ERROR";
case log_level_fatal: return "FATAL";
default: return "INVALID";
}
}
fn void log_base(i32 module, log_level_t level, s8_t file_and_line, s8_t string) {
tcx.log.log_proc((log_event_t){module, level, file_and_line, string});
}
fn void log_basef(i32 module, log_level_t level, s8_t file_and_line, const char *str, ...) {
ma_temp_t scratch = ma_begin_scratch();
S8_FMT(scratch.arena, str, str8);
log_base(module, level, file_and_line, str8);
ma_end_scratch(scratch);
}
fn void default_log_proc(log_event_t ev) {
ma_temp_t scratch = ma_begin_scratch();
sb8_t *sb = sb8_serial_begin(scratch.arena);
if (tcx.log.flags & log_flag_level) {
sb8_printf(sb, "%-5s ", log_level_str(ev.level));
}
if (tcx.log.flags & log_flag_file_path) {
sb8_printf(sb, "%S: ", ev.file_and_line);
}
sb8_printf(sb, "%S\n", ev.string);
s8_t result = sb8_serial_end(scratch.arena, sb);
if (ev.level != log_level_fatal) {
os_console_log(result.str);
} else {
os_error_box(result.str);
#if PLATFORM_WASM
debug_break();
#else
if (tcx.log.break_on_fatal) {
debug_break();
} else {
exit(1);
}
#endif
case log_level_debug:
case log_level_info: {
os_console_log(s8_printf(scratch.arena, "%S\n", string).str);
} break;
case log_level_warning: {
os_console_log(s8_printf(scratch.arena, "%S: warning: %S\n", file_and_line, string).str);
if (tcx.log.break_on_warning) debug_break();
} break;
case log_level_error: {
os_console_log(s8_printf(scratch.arena, "%S: error: %S\n", file_and_line, string).str);
if (tcx.log.break_on_error) debug_break();
} break;
case log_level_fatal: {
os_error_box(s8_printf(scratch.arena, "%S: fatal error: %S\n", file_and_line, string).str);
if (tcx.log.break_on_fatal) debug_break();
exit(1);
} break;
default_is_invalid;
}
ma_end_scratch(scratch);

View File

@@ -16,15 +16,6 @@
**
**
*/
const i32 module_null = 0;
typedef enum {
log_flag_null = 0,
log_flag_level = 1,
log_flag_file_path = 8,
log_flag_all = log_flag_level | log_flag_file_path,
} log_flag_t;
typedef enum { // AFTER_CHANGING: modify type_info and log_level_str
log_level_debug,
log_level_info,
@@ -33,34 +24,27 @@ typedef enum { // AFTER_CHANGING: modify type_info and log_level_str
log_level_fatal,
} log_level_t;
typedef struct log_event_t log_event_t;
struct log_event_t {
i32 module;
log_level_t level;
s8_t file_and_line;
s8_t string;
};
typedef struct logger_t logger_t;
struct logger_t {
void (*log_proc)(log_event_t);
void (*log_proc)(log_level_t level, s8_t file_and_line, s8_t string);
void *user_data;
log_flag_t flags;
b32 break_on_fatal;
b8 break_on_fatal;
b8 break_on_error;
b8 break_on_warning;
};
///////////////////////////////
// main api
#define debugf(...) log_basef(module_null, log_level_debug, S8_FILE_AND_LINE, __VA_ARGS__)
#define errorf(MODULE, ...) log_basef(MODULE, log_level_error, S8_FILE_AND_LINE, __VA_ARGS__)
#define fatalf(...) (log_basef(module_null, log_level_fatal, S8_FILE_AND_LINE, __VA_ARGS__), 0)
#define debugf(...) log_basef(log_level_debug, S8_FILE_AND_LINE, __VA_ARGS__)
#define errorf(...) log_basef(log_level_error, S8_FILE_AND_LINE, __VA_ARGS__)
#define fatalf(...) (log_basef(log_level_fatal, S8_FILE_AND_LINE, __VA_ARGS__), 0)
fn void default_log_proc(log_event_t ev);
fn void default_log_proc(log_level_t level, s8_t file_and_line, s8_t string);
fn void log_basef(log_level_t level, s8_t file_and_line, const char *str, ...);
#define program_version "---"
#if PLATFORM_DEBUG_ASSERT
#define assert(x) (!(x) && (os_error_box(FILE_AND_LINE ": internal program error! assertion failed: " #x ", program version: " program_version "\n"), debug_break()))
#define assert(x) (!(x) && (os_error_box(FILE_AND_LINE ": assertion failed: " #x "\n"), debug_break()))
#else
#define assert(x) (void)(x)
#endif
@@ -69,132 +53,3 @@ fn void default_log_proc(log_event_t ev);
#define default_is_invalid default: assert(!"invalid default case")
#define else_is_invalid else { assert(!"else was not expected to be executed!"); }
fn void log_base(i32 module, log_level_t level, s8_t file_and_line, s8_t string);
fn void log_basef(i32 module, log_level_t level, s8_t file_and_line, const char *str, ...);
/*
Seems like there are 2 logging categories:
1. Logging in a graphical program where you have control over how logs are displayed
2. Logging in a console program where you dump shit into conso
DESIGN ANALYSIS
///////////////////////////////
// rxi log.c api:
// > 22:54:32 INFO src/memes/memes.c:65: message
log_trace(const char *fmt, ...);
log_debug(const char *fmt, ...);
log_info(const char *fmt, ...);
log_warn(const char *fmt, ...);
log_error(const char *fmt, ...);
log_fatal(const char *fmt, ...);
log_set_quiet(bool enable)
log_set_level(level)
log_add_fp(file, level)
log_add_callback(func, user_data, level)
log_set_lock(lock_func, void *user_data)
///////////////////////////////
// odin log package
Logger_Proc :: #type proc(data: rawptr, level: Level,
text: string, options: Options, location := #caller_location);
Logger :: struct {
procedure: Logger_Proc,
data: rawptr,
lowest_level: Level,
options: Logger_Options,
}
Option :: enum {
Level,
Date,
Time,
Short_File_Path,
Long_File_Path,
Line,
Procedure,
Terminal_Color
}
Logger_Level :: enum {
Debug = 0,
Info = 10,
Warning = 20,
Error = 30,
Fatal = 40,
}
debugf()
infof()
warnf()
errorf()
fatalf()
panic()
panicf()
assert()
assertf()
///////////////////////////////
// raddebugger log
Log { arena, LogScope *top_scope } (stack of LogScopes)
LogScope { LogScope *next, pos in arena to pop, StringList[LogMsgKinds] }
LogScopeResult { String[LogMsgKinds] }
internal Log *log_alloc(void);
internal void log_release(Log *log);
internal void log_select(
internal void log_scope_begin(void);
internal LogScopeResult log_scope_end(Arena *are
#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"))
{
log_scope_begin();
log_infof("user2ctrl_msg:{kind:\"%S\"}\n", ctrl_string_from_msg_kind(msg->kind));
LogInfoNamedBlockF("dmn_event")
{
log_infof("kind: %S\n", dmn_event_kind_string_table[ev->kind]);
log_infof("exception_kind: %S\n", dmn_exception_kind_string_table[ev->exception_kind]);
log_infof("process: [%I64u]\n", ev->process.u64[0]);
log_infof("thread: [%I64u]\n", ev->thread.u64[0]);
log_infof("module: [%I64u]\n", ev->module.u64[0]);
log_infof("arch: %S\n", string_from_arch(ev->arch));
log_infof("address: 0x%I64x\n", ev->address);
log_infof("string: \"%S\"\n", ev->string);
log_infof("ip_vaddr: 0x%I64x\n", ev->instruction_pointer);
}
LogScopeResult log = log_scope_end(scratch.arena);
ctrl_thread__flush_info_log(log.strings[LogMsgKind_Info]);
if(log.strings[LogMsgKind_UserError].size != 0)
{
Show to user
}
}
*/

View File

@@ -205,9 +205,9 @@ union r3i64_t {
#define rgba_macro_const(r, g, b, a) { r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f }
gb_read_only v4f32_t primary_color_global = rgba_macro_const(245, 238, 230, 255);
gb_read_only v4f32_t secondary_color_global = rgba_macro_const(255, 248, 227, 255);
gb_read_only v4f32_t accent1_color_global = rgba_macro_const(243, 215, 202, 255);
gb_read_only v4f32_t accent2_color_global = rgba_macro_const(230, 164, 180, 255);
gb_read_only v4f32_t white_color_global = rgba_macro_const(255, 255, 255, 255);
gb_read_only v4f32_t black_color_global = rgba_macro_const(0, 0, 0, 255);
gb v4f32_t primary_color_global = rgba_macro_const(245, 238, 230, 255);
gb v4f32_t secondary_color_global = rgba_macro_const(255, 248, 227, 255);
gb v4f32_t accent1_color_global = rgba_macro_const(243, 215, 202, 255);
gb v4f32_t accent2_color_global = rgba_macro_const(230, 164, 180, 255);
gb v4f32_t white_color_global = rgba_macro_const(255, 255, 255, 255);
gb v4f32_t black_color_global = rgba_macro_const(0, 0, 0, 255);

View File

@@ -59,6 +59,7 @@ struct mt_tweak_t {
};
#define mt_embed_file(name, path)
#define mt_tweak_f32(name, default, min, max)
#define mt_tweak_color(name, ...)
#define mt_tweak_b32(name, default)
//