Skip to content

Commit

Permalink
Merge pull request #216 from worron/log_file_detection
Browse files Browse the repository at this point in the history
Add extra checks before reading godot log
  • Loading branch information
worron authored Dec 16, 2024
2 parents bdf0ada + e1a9bc0 commit 702d45c
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions addons/panku_console/modules/native_logger/godot_log_monitor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 702d45c

Please sign in to comment.