mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-24 11:17:26 -04:00
sandbox logger (wip)
This commit is contained in:
parent
61d0534f07
commit
5e4a776dde
6 changed files with 84 additions and 18 deletions
56
app/scripts/sandbox/sandbox_logger.gd
Normal file
56
app/scripts/sandbox/sandbox_logger.gd
Normal 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")
|
Loading…
Add table
Add a link
Reference in a new issue