From e1a9bc0a6aea84da207d965f95a3ed60bf4a68f1 Mon Sep 17 00:00:00 2001 From: worron Date: Sun, 15 Dec 2024 20:28:28 +0300 Subject: [PATCH] Add godot log file check More strict checks for godot log monitoring mechanics. --- .../native_logger/godot_log_monitor.gd | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/addons/panku_console/modules/native_logger/godot_log_monitor.gd b/addons/panku_console/modules/native_logger/godot_log_monitor.gd index 97cf92a..45cd568 100644 --- a/addons/panku_console/modules/native_logger/godot_log_monitor.gd +++ b/addons/panku_console/modules/native_logger/godot_log_monitor.gd @@ -9,22 +9,41 @@ const UPDATE_INTERVAL := 0.1 const ERROR_MSG_PREFIX := "USER ERROR: " const WARNING_MSG_PREFIX := "USER WARNING: " #Any logs with three spaces at the beginning will be ignored. -const IGNORE_PREFIX := " " +const IGNORE_PREFIX := " " + +var godot_log: FileAccess +var godot_log_path: String -var godot_log:FileAccess func _ready(): - var file_logging_enabled = ProjectSettings.get("debug/file_logging/enable_file_logging") or ProjectSettings.get("debug/file_logging/enable_file_logging.pc") - if !file_logging_enabled: + if not _is_log_enabled(): push_warning("You have to enable file logging in order to use engine log monitor!") return - - var log_path = ProjectSettings.get("debug/file_logging/log_path") - godot_log = FileAccess.open(log_path, FileAccess.READ) - create_tween().set_loops( - ).tween_callback(_read_data - ).set_delay(UPDATE_INTERVAL) + godot_log_path = ProjectSettings.get("debug/file_logging/log_path") + if not FileAccess.file_exists(godot_log_path): + push_warning("Log file not fount by path " + godot_log_path) + return + + _start_watching() + + +func _start_watching() -> void: + godot_log = FileAccess.open(godot_log_path, FileAccess.READ) + create_tween().set_loops().tween_callback(_read_data).set_delay(UPDATE_INTERVAL) + + +func _is_log_enabled() -> bool: + + if ProjectSettings.get("debug/file_logging/enable_file_logging"): + return true + + # this feels so weird and wrong + # what about other platforms? + if OS.has_feature("pc") and ProjectSettings.get("debug/file_logging/enable_file_logging.pc"): + return true + + return false func _read_data():