Skip to content

Commit 702d45c

Browse files
authored
Merge pull request #216 from worron/log_file_detection
Add extra checks before reading godot log
2 parents bdf0ada + e1a9bc0 commit 702d45c

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

addons/panku_console/modules/native_logger/godot_log_monitor.gd

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,41 @@ const UPDATE_INTERVAL := 0.1
99
const ERROR_MSG_PREFIX := "USER ERROR: "
1010
const WARNING_MSG_PREFIX := "USER WARNING: "
1111
#Any logs with three spaces at the beginning will be ignored.
12-
const IGNORE_PREFIX := " "
12+
const IGNORE_PREFIX := " "
13+
14+
var godot_log: FileAccess
15+
var godot_log_path: String
1316

14-
var godot_log:FileAccess
1517

1618
func _ready():
17-
var file_logging_enabled = ProjectSettings.get("debug/file_logging/enable_file_logging") or ProjectSettings.get("debug/file_logging/enable_file_logging.pc")
18-
if !file_logging_enabled:
19+
if not _is_log_enabled():
1920
push_warning("You have to enable file logging in order to use engine log monitor!")
2021
return
21-
22-
var log_path = ProjectSettings.get("debug/file_logging/log_path")
23-
godot_log = FileAccess.open(log_path, FileAccess.READ)
2422

25-
create_tween().set_loops(
26-
).tween_callback(_read_data
27-
).set_delay(UPDATE_INTERVAL)
23+
godot_log_path = ProjectSettings.get("debug/file_logging/log_path")
24+
if not FileAccess.file_exists(godot_log_path):
25+
push_warning("Log file not fount by path " + godot_log_path)
26+
return
27+
28+
_start_watching()
29+
30+
31+
func _start_watching() -> void:
32+
godot_log = FileAccess.open(godot_log_path, FileAccess.READ)
33+
create_tween().set_loops().tween_callback(_read_data).set_delay(UPDATE_INTERVAL)
34+
35+
36+
func _is_log_enabled() -> bool:
37+
38+
if ProjectSettings.get("debug/file_logging/enable_file_logging"):
39+
return true
40+
41+
# this feels so weird and wrong
42+
# what about other platforms?
43+
if OS.has_feature("pc") and ProjectSettings.get("debug/file_logging/enable_file_logging.pc"):
44+
return true
45+
46+
return false
2847

2948

3049
func _read_data():

0 commit comments

Comments
 (0)