sandbox logger (wip)

This commit is contained in:
Nordup 2024-10-30 07:28:05 +04:00
parent 61d0534f07
commit 5e4a776dde
6 changed files with 84 additions and 18 deletions

View file

@ -9,7 +9,7 @@ custom_features=""
export_filter="all_resources" export_filter="all_resources"
include_filter="" include_filter=""
exclude_filter="" exclude_filter=""
export_path="../../AppBuilds/Linux/TheGates.x86_64" export_path="../../../../../../media/common/Projects/thegates-folder/AppBuilds/Linux/TheGates.x86_64"
encryption_include_filters="" encryption_include_filters=""
encryption_exclude_filters="" encryption_exclude_filters=""
encrypt_pck=false encrypt_pck=false

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=35 format=3 uid="uid://kywrsqro3d5i"] [gd_scene load_steps=36 format=3 uid="uid://kywrsqro3d5i"]
[ext_resource type="Script" path="res://scripts/loading/gate_loader.gd" id="1_uxhy6"] [ext_resource type="Script" path="res://scripts/loading/gate_loader.gd" id="1_uxhy6"]
[ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://resources/gate_events.res" id="2_q7cvi"] [ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://resources/gate_events.res" id="2_q7cvi"]
@ -8,6 +8,7 @@
[ext_resource type="Script" path="res://scripts/sandbox/sandbox_manager.gd" id="6_368sj"] [ext_resource type="Script" path="res://scripts/sandbox/sandbox_manager.gd" id="6_368sj"]
[ext_resource type="Script" path="res://scripts/sandbox/input_sync.gd" id="8_1blsi"] [ext_resource type="Script" path="res://scripts/sandbox/input_sync.gd" id="8_1blsi"]
[ext_resource type="Resource" uid="uid://bo6qgr210aamc" path="res://resources/sandbox_env.tres" id="8_a6dvr"] [ext_resource type="Resource" uid="uid://bo6qgr210aamc" path="res://resources/sandbox_env.tres" id="8_a6dvr"]
[ext_resource type="Script" path="res://scripts/sandbox/sandbox_logger.gd" id="9_fikc8"]
[ext_resource type="Resource" uid="uid://crjhix0osmtnf" path="res://resources/ui_events.res" id="9_ir58h"] [ext_resource type="Resource" uid="uid://crjhix0osmtnf" path="res://resources/ui_events.res" id="9_ir58h"]
[ext_resource type="Script" path="res://scripts/ui/world/world_canvas.gd" id="9_ncfxj"] [ext_resource type="Script" path="res://scripts/ui/world/world_canvas.gd" id="9_ncfxj"]
[ext_resource type="Shader" path="res://shaders/render_result.gdshader" id="10_2auwe"] [ext_resource type="Shader" path="res://shaders/render_result.gdshader" id="10_2auwe"]
@ -300,13 +301,18 @@ script = ExtResource("1_uxhy6")
gate_events = ExtResource("2_q7cvi") gate_events = ExtResource("2_q7cvi")
connect_timeout = 10.0 connect_timeout = 10.0
[node name="SandboxManager" type="Node" parent="." node_paths=PackedStringArray("render_result")] [node name="SandboxManager" type="Node" parent="." node_paths=PackedStringArray("render_result", "snbx_logger")]
script = ExtResource("6_368sj") script = ExtResource("6_368sj")
gate_events = ExtResource("2_q7cvi") gate_events = ExtResource("2_q7cvi")
render_result = NodePath("../HBoxContainer/WorldCanvas/RenderResult") render_result = NodePath("../HBoxContainer/WorldCanvas/RenderResult")
snbx_logger = NodePath("../SandboxLogger")
snbx_executable = ExtResource("4_shus3") snbx_executable = ExtResource("4_shus3")
snbx_env = ExtResource("8_a6dvr") snbx_env = ExtResource("8_a6dvr")
[node name="SandboxLogger" type="Node" parent="."]
script = ExtResource("9_fikc8")
gate_events = ExtResource("2_q7cvi")
[node name="InputSync" type="Node" parent="." node_paths=PackedStringArray("render_result")] [node name="InputSync" type="Node" parent="." node_paths=PackedStringArray("render_result")]
script = ExtResource("8_1blsi") script = ExtResource("8_1blsi")
gate_events = ExtResource("2_q7cvi") gate_events = ExtResource("2_q7cvi")

View file

@ -0,0 +1,56 @@
extends Node
class_name SandboxLogger
@export var gate_events: GateEvents
const LOG_FOLDER := "user://logs"
const LOG_FILE := "log.txt"
var log_file: FileAccess
var pipe: Dictionary
var is_started: bool
var logs_sent: bool
func _ready() -> void:
gate_events.not_responding.connect(send_logs)
func start(_pipe: Dictionary, gate: Gate) -> void:
pipe = _pipe
is_started = true
var gate_folder = gate.url.replace("http://", "").replace("https://", "").replace(".gate", "")
var path = LOG_FOLDER + "/" + gate_folder + "/" + LOG_FILE
DirAccess.make_dir_recursive_absolute(path.get_base_dir())
log_file = FileAccess.open(path, FileAccess.WRITE_READ)
Debug.logclr("Logs written to " + path, Color.DIM_GRAY)
func _process(_delta: float) -> void:
if not is_started: return
if pipe["stdio"].is_open():
var buffer = PackedByteArray()
while true:
buffer.append_array(pipe["stdio"].get_buffer(2048))
if pipe["stdio"].get_error() != OK:
break;
while true:
buffer.append_array(pipe["stderr"].get_buffer(2048))
if pipe["stderr"].get_error() != OK:
break;
if !buffer.is_empty():
printraw(buffer.get_string_from_utf8())
log_file.store_buffer(buffer)
func send_logs() -> void:
if logs_sent: return
logs_sent = true
Debug.logr("logs sent")

View file

@ -3,12 +3,13 @@ class_name SandboxManager
@export var gate_events: GateEvents @export var gate_events: GateEvents
@export var render_result: RenderResult @export var render_result: RenderResult
@export var snbx_logger: SandboxLogger
@export var snbx_executable: SandboxExecutable @export var snbx_executable: SandboxExecutable
@export var snbx_env: SandboxEnv @export var snbx_env: SandboxEnv
const IPC_FOLDER := "sandbox" const IPC_FOLDER := "sandbox"
var sandbox_pid: int var snbx_pid: int
func _ready() -> void: func _ready() -> void:
@ -41,9 +42,12 @@ func start_sandbox_linux(gate: Gate) -> void:
"--resolution", "%dx%d" % [render_result.width, render_result.height] "--resolution", "%dx%d" % [render_result.width, render_result.height]
] ]
if OS.is_stdout_verbose(): args += ["--verbose"] if OS.is_stdout_verbose(): args += ["--verbose"]
args += ["--verbose"]
Debug.logclr(snbx_env.start + " " + " ".join(args), Color.DIM_GRAY) Debug.logclr(snbx_env.start + " " + " ".join(args), Color.DIM_GRAY)
sandbox_pid = OS.create_process(snbx_env.start, args)
var pipe = OS.execute_with_pipe(snbx_env.start, args, false)
snbx_logger.start(pipe, gate)
snbx_pid = pipe["pid"]
gate_events.gate_entered_emit() gate_events.gate_entered_emit()
@ -64,7 +68,7 @@ func start_sandbox_windows(gate: Gate) -> void:
if OS.is_stdout_verbose(): args += ["--verbose"] if OS.is_stdout_verbose(): args += ["--verbose"]
Debug.logclr(snbx_executable.path + " " + " ".join(args), Color.DIM_GRAY) Debug.logclr(snbx_executable.path + " " + " ".join(args), Color.DIM_GRAY)
sandbox_pid = OS.create_process(snbx_executable.path, args) snbx_pid = OS.create_process(snbx_executable.path, args)
gate_events.gate_entered_emit() gate_events.gate_entered_emit()
@ -83,7 +87,7 @@ func start_sandbox_macos(gate: Gate) -> void:
if OS.is_stdout_verbose(): args += ["--verbose"] if OS.is_stdout_verbose(): args += ["--verbose"]
Debug.logclr(snbx_executable.path + " " + " ".join(args), Color.DIM_GRAY) Debug.logclr(snbx_executable.path + " " + " ".join(args), Color.DIM_GRAY)
sandbox_pid = OS.create_process(snbx_executable.path, args) snbx_pid = OS.create_process(snbx_executable.path, args)
gate_events.gate_entered_emit() gate_events.gate_entered_emit()
@ -101,10 +105,10 @@ func kill_sandbox() -> void:
func kill_sandbox_linux() -> void: func kill_sandbox_linux() -> void:
if sandbox_pid == 0: return if snbx_pid == 0: return
var pids = snbx_env.get_subprocesses(sandbox_pid) var pids = snbx_env.get_subprocesses(snbx_pid)
pids.append(sandbox_pid) pids.append(snbx_pid)
for pid in pids: for pid in pids:
OS.kill(pid) OS.kill(pid)
@ -114,15 +118,15 @@ func kill_sandbox_linux() -> void:
func kill_sandbox_windows() -> void: func kill_sandbox_windows() -> void:
if OS.is_process_running(sandbox_pid): if OS.is_process_running(snbx_pid):
OS.kill(sandbox_pid) OS.kill(snbx_pid)
Debug.logclr("Process killed " + str(sandbox_pid), Color.DIM_GRAY) Debug.logclr("Process killed " + str(snbx_pid), Color.DIM_GRAY)
func kill_sandbox_macos() -> void: func kill_sandbox_macos() -> void:
if OS.is_process_running(sandbox_pid): if OS.is_process_running(snbx_pid):
OS.kill(sandbox_pid) OS.kill(snbx_pid)
Debug.logclr("Process killed " + str(sandbox_pid), Color.DIM_GRAY) Debug.logclr("Process killed " + str(snbx_pid), Color.DIM_GRAY)
func _exit_tree() -> void: func _exit_tree() -> void:

2
godot

@ -1 +1 @@
Subproject commit 8fa7f8db356dd32f8a8404cadab8d3980c05516c Subproject commit 44488e0c7605c258ab9a6f1cde659868a491f6f8

0
sandbox/kinda-safe-godot/create_sandbox_env.sh Normal file → Executable file
View file