From: Brendan Hansen Date: Sun, 25 Dec 2022 04:38:22 +0000 (-0600) Subject: switched to using the builtin logger system X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=05dd1dce2895bb1f02b3120df5fec4f8e7edc45f;p=bar-game.git switched to using the builtin logger system --- diff --git a/onyx-pkg.ini b/onyx-pkg.ini index a321e07..27fd7a2 100644 --- a/onyx-pkg.ini +++ b/onyx-pkg.ini @@ -18,7 +18,7 @@ library= [dependencies] git://onyxlang.io/repo/openal=0.0.2 -git://onyxlang.io/repo/ogre=0.0.8 +git://onyxlang.io/repo/ogre=0.0.10 [dependency_folders] git://onyxlang.io/repo/openal=openal diff --git a/src/entity/components/dispenser.onyx b/src/entity/components/dispenser.onyx index 683713e..98a8329 100644 --- a/src/entity/components/dispenser.onyx +++ b/src/entity/components/dispenser.onyx @@ -22,7 +22,7 @@ DispenserComponent :: struct { entity.flags |= .Interactable; if entity->has(InteractableComponent) { - debug_log(.Error, "DispenserComponent expected entity to not have an InteractableComponent"); + log(.Error, "DispenserComponent expected entity to not have an InteractableComponent"); } scene->modify_component(entity, InteractableComponent) { @@ -49,7 +49,7 @@ DispenserComponent :: struct { item := scene->create_from_schematic("Item_Entity"); if item == null { - debug_log(.Error, "Bad schematic type."); + log(.Error, "Bad schematic type."); return; } diff --git a/src/entity/components/patron.onyx b/src/entity/components/patron.onyx index 2ec578c..a68e1d4 100644 --- a/src/entity/components/patron.onyx +++ b/src/entity/components/patron.onyx @@ -138,7 +138,7 @@ PatronComponent :: struct { array.free(^path); collision_mask := scene->first_component(CollisionMaskComponent); if !(collision_mask->get_path(entity.pos, target_location, ^path)) { - debug_log(.Warning, "No path for patron."); + log(.Warning, "No path for patron."); return; } diff --git a/src/entity/items.onyx b/src/entity/items.onyx index 2ef7baa..c69715b 100644 --- a/src/entity/items.onyx +++ b/src/entity/items.onyx @@ -36,7 +36,7 @@ item_store_load_items_from_file :: (use this: ^Item_Store, path: str) { err, input_file := os.open(path, .Read); if err != .None { - debug_log(.Error, "Failed to open file: {}", path); + logf(.Error, "Failed to open file: {}", path); return; } defer os.close(^input_file); @@ -58,7 +58,7 @@ item_store_load_items_from_file :: (use this: ^Item_Store, path: str) { |> string.strip_whitespace(); if items->has(item_id) { - debug_log(.Warning, "Duplicate definition for item with id '{}', on line: {}.", item_id); + logf(.Warning, "Duplicate definition for item with id '{}', on line: {}.", item_id); } item_id = string.alloc_copy(item_id, allocator=item_allocator); @@ -77,12 +77,12 @@ item_store_load_items_from_file :: (use this: ^Item_Store, path: str) { member := any_nested_selector(as_any(current_item), var_name); if member.data == null { - debug_log(.Warning, "'{}' is not a valid member of Item on line {}.", var_name, line_number); + logf(.Warning, "'{}' is not a valid member of Item on line {}.", var_name, line_number); continue; } if !conv.parse_any(member.data, member.type, line) { - debug_log(.Warning, "Unable to parse '{}' for type '{}' on line {}.", line, member.type, line_number); + logf(.Warning, "Unable to parse '{}' for type '{}' on line {}.", line, member.type, line_number); continue; } } diff --git a/src/entity/scene.onyx b/src/entity/scene.onyx index 9e0a80a..31e1756 100644 --- a/src/entity/scene.onyx +++ b/src/entity/scene.onyx @@ -221,7 +221,7 @@ scene_create :: (width, height: f32) -> Scene { s_info := cast(^Type_Info_Struct) it; if struct_inherits(~~ index, Component) { - debug_log(.Debug, "Discovered component: '{}'", s_info.name); + logf(.Debug, "Discovered component: '{}'", s_info.name); comp_type := cast(type_expr) index; if !(component_vtables->has(comp_type)) { @@ -237,7 +237,7 @@ scene_create :: (width, height: f32) -> Scene { schematic.create = *cast(^(^Scene) -> ^Entity) ^it.func; schematics[schematic.name] = schematic; - debug_log(.Debug, "Discovered schematic: '{}'", schematic.name); + logf(.Debug, "Discovered schematic: '{}'", schematic.name); } } diff --git a/src/entity/store.onyx b/src/entity/store.onyx index ae5edd7..c9af714 100644 --- a/src/entity/store.onyx +++ b/src/entity/store.onyx @@ -78,7 +78,7 @@ scene_save_to_file :: (use this: ^Scene, filename: str) { case #default { msg := conv.format(output_buffer, "Unhandled output case: {}\n", it.type); - debug_log(.Error, msg); + logf(.Error, msg); } } } @@ -89,7 +89,7 @@ scene_save_to_file :: (use this: ^Scene, filename: str) { scene_load_from_file :: (use this: ^Scene, filename: str, reset_scene := true) { err, input_file := os.open(filename, .Read); if err != .None { - debug_log(.Error, "Failed to open file: {}", filename); + logf(.Error, "Failed to open file: {}", filename); return; } defer os.close(^input_file); @@ -121,13 +121,13 @@ scene_load_from_file :: (use this: ^Scene, filename: str, reset_scene := true) { entity_kind := string.advance(line) |> (x => str.{x.data, x.count - 1})(); // In the grossest way possible remove one character from the end. - debug_log(.Debug, "Creating entity from schematic: {}.", entity_kind); + logf(.Debug, "Creating entity from schematic: {}.", entity_kind); if entity_kind == "Custom" { current_entity = this->make(); } else { current_entity = this->create_from_schematic(entity_kind); if current_entity == null { - debug_log(.Error, "Unknown entity kind '{}' on line {}.", entity_kind, line_number); + logf(.Error, "Unknown entity kind '{}' on line {}.", entity_kind, line_number); current_entity = null; continue; } @@ -138,7 +138,7 @@ scene_load_from_file :: (use this: ^Scene, filename: str, reset_scene := true) { if line[0] == #char ":" { if current_entity == null { - debug_log(.Error, "Attempt to create a component when no entity is specified on line {}.", line_number); + logf(.Error, "Attempt to create a component when no entity is specified on line {}.", line_number); continue; } @@ -149,7 +149,7 @@ scene_load_from_file :: (use this: ^Scene, filename: str, reset_scene := true) { } else { current_component = scene->create_component(component_type); - debug_log(.Debug, "Adding {} to entity.", component_type); + logf(.Debug, "Adding {} to entity.", component_type); current_entity->add(current_component); } @@ -167,12 +167,12 @@ scene_load_from_file :: (use this: ^Scene, filename: str, reset_scene := true) { member := any_nested_selector(any.{ptr, type}, var_name); if member.data == null { t_info := cast(^Type_Info_Struct) get_type_info(type); - debug_log(.Warning, "'{}' is not a valid member of '{}' on line {}.", var_name, t_info.name, line_number); + logf(.Warning, "'{}' is not a valid member of '{}' on line {}.", var_name, t_info.name, line_number); continue; } if !conv.parse_any(member.data, member.type, line) { - debug_log(.Warning, "Unable to parse '{}' for type '{}' on line {}.", line, member.type, line_number); + logf(.Warning, "Unable to parse '{}' for type '{}' on line {}.", line, member.type, line_number); continue; } } diff --git a/src/game.onyx b/src/game.onyx index b4bc5a3..6fe7412 100644 --- a/src/game.onyx +++ b/src/game.onyx @@ -52,12 +52,12 @@ game_update :: (dt: f32) { Audio_Manager.tick(); if is_key_just_up(GLFW_KEY_F8) { - debug_log(.Info, "Saving to '{}'.", quick_save_file); + log(.Info, "Saving to '{}'.", quick_save_file); scene->save_to_file(quick_save_file); } if is_key_just_up(GLFW_KEY_F9) { - debug_log(.Info, "Loading from '{}'.", quick_save_file); + log(.Info, "Loading from '{}'.", quick_save_file); scene->load_from_file(quick_save_file); } diff --git a/src/main.onyx b/src/main.onyx index 3ed2e18..f03afb1 100644 --- a/src/main.onyx +++ b/src/main.onyx @@ -13,7 +13,7 @@ window: Window init :: () { if !ogre_init() { - debug_log(.Critical, "Failed to initialize OGRE!"); + log(.Critical, "Failed to initialize OGRE!"); os.exit(1); } @@ -100,7 +100,8 @@ run :: () { main :: () { random.set_seed(os.time()); - debug_set_level(.Info); + default_log_level(.Info); + init(); run(); deinit(); diff --git a/src/sfx/audio_manager.onyx b/src/sfx/audio_manager.onyx index 9398137..0dcaa15 100644 --- a/src/sfx/audio_manager.onyx +++ b/src/sfx/audio_manager.onyx @@ -16,7 +16,7 @@ Audio_Manager :: struct { alcMakeContextCurrent(audio_context); if alGetError() != AL_NO_ERROR { - debug_log(.Critical, "Error creating audio context!!"); + log(.Critical, "Error creating audio context!!"); } } @@ -42,7 +42,7 @@ Audio_Manager :: struct { buffer: u32; alGenBuffers(1, ^buffer); if alGetError() != AL_NO_ERROR { - debug_log(.Error, "Error creating audio buffer!"); + log(.Error, "Error creating audio buffer!"); return .{0}; } diff --git a/src/utils/asset_loader.onyx b/src/utils/asset_loader.onyx index 761eb61..ad92c90 100644 --- a/src/utils/asset_loader.onyx +++ b/src/utils/asset_loader.onyx @@ -52,15 +52,15 @@ load_assets :: () { *out_texture = texture; } else { - debug_log(.Error, "Failed to load texture '{}' for asset queued here: {}:{},{}.\n", path, location.file, location.line, location.column); + logf(.Error, "Failed to load texture '{}' for asset queued here: {}:{},{}.\n", path, location.file, location.line, location.column); } } else { - debug_log(.Error, "Texture path not found for texture asset load here: {}:{},{}.\n", location.file, location.line, location.column); + logf(.Error, "Texture path not found for texture asset load here: {}:{},{}.\n", location.file, location.line, location.column); } } case #default { - debug_log(.Warning, "Asset loader does not know how to load a '{}'.\n", type); + logf(.Warning, "Asset loader does not know how to load a '{}'.\n", type); } } } diff --git a/src/utils/logger.onyx b/src/utils/logger.onyx index 57b0ffc..6c9b44c 100644 --- a/src/utils/logger.onyx +++ b/src/utils/logger.onyx @@ -1,57 +1,9 @@ // // This may become an in-game or external file logger in the future, // but for now this is just for logging to the command line. +// -use package core - -Enable_Log_Colors :: false - -Log_Level :: enum { - Debug; - Info; - Warning; - Error; - Critical; -} - -debug_set_level :: (level: Log_Level) { - log_level = level; -} - -debug_log :: (level: Log_Level, format: str, args: ..any) { - debug_log_va(level, format, ~~args); -} - -debug_log_va :: (level: Log_Level, format: str, args: [] any) { - if level < log_level do return; - +logf :: (level: Log_Level, format: str, args: ..any) { buf: [2048] u8; - output := conv.format_va(buf, format, args); - #if Enable_Log_Colors { - color_spec: str; - switch level { - case .Critical do color_spec = "1;91"; - case .Error do color_spec = "1;31"; - case .Warning do color_spec = "1;33"; - case .Info do color_spec = "94"; - } - - printf("\x1b[{}m[{w5}] {}\x1b[0m\n", color_spec, level_string(level), output); - } else { - printf("[{w5}] {}\n", level_string(level), output); - } + log(level, core.conv.format_va(buf, format, args)); } - -#local level_string :: (level: Log_Level) => { - switch level { - case .Debug do return "DEBUG"; - case .Info do return "INFO"; - case .Warning do return "WARN"; - case .Error do return "ERROR"; - case .Critical do return "CRIT"; - } - - return ""; -} - -#local log_level := Log_Level.Debug; \ No newline at end of file