switched to using the builtin logger system
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 25 Dec 2022 04:38:22 +0000 (22:38 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 25 Dec 2022 04:38:22 +0000 (22:38 -0600)
onyx-pkg.ini
src/entity/components/dispenser.onyx
src/entity/components/patron.onyx
src/entity/items.onyx
src/entity/scene.onyx
src/entity/store.onyx
src/game.onyx
src/main.onyx
src/sfx/audio_manager.onyx
src/utils/asset_loader.onyx
src/utils/logger.onyx

index a321e07902adefdaa446e9664432c55dc1c26c4d..27fd7a2909fdcc0b10597809d7660212e1aa4e31 100644 (file)
@@ -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
index 683713e2d7dd0234bf7bbdfafec7e79c734b5ced..98a8329bc5e57e3fd72aa6a4c814b0779e55c254 100644 (file)
@@ -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;
             }
 
index 2ec578c248faa46c1931d922b58df41d160e3d10..a68e1d46db7b94b8475a0104b2f70ee82a1fb7f8 100644 (file)
@@ -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;
                     }
 
index 2ef7baa32e989407371489214c544b98402df54b..c69715bc0c7167fb59fbf1dc978905279484e7cf 100644 (file)
@@ -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;
         }
     }
index 9e0a80a781f8f35b0eaaaa0280deb7f3dc661c89..31e1756819e5558d3b32305a65b1b59e0420c793 100644 (file)
@@ -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);
     }
 }
 
index ae5edd7312687bc747fd1c1c9d571552a524633b..c9af714116b4668d86d263fff1ef71635ccc0dbc 100644 (file)
@@ -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;
             }
         }
index b4bc5a30fccdd926530e9b8088272c8cedb7992f..6fe741246054842208dfc787e65d10dd312ee453 100644 (file)
@@ -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);
     }
 
index 3ed2e186e4c40f40033f51f0c5fe4fe76139e964..f03afb152cd78a9633a814feffb0d5b2abfb3ddc 100644 (file)
@@ -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();
index 93981375633e6084118ddd447c0c3bdadc011bb7..0dcaa1503cff69017e1f14260147ae441745cfe7 100644 (file)
@@ -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};
         }
 
index 761eb6163672adb6c99ecbc39e80c3148152c698..ad92c905f3bbbf973aac8b4d8dc9b003bef613ab 100644 (file)
@@ -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);
             }
         }
     }
index 57b0ffc976bc127798ff4d74303c70bf7991e348..6c9b44c7b610e84e62842f30d4823b8dda791933 100644 (file)
@@ -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