mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-23 08:17:34 -04:00
api send logs
This commit is contained in:
parent
5e4a776dde
commit
fc6bf939c0
9 changed files with 97 additions and 21 deletions
|
@ -19,7 +19,7 @@ script_export_mode=2
|
|||
[preset.0.options]
|
||||
|
||||
custom_template/debug=""
|
||||
custom_template/release="/media/common/Projects/thegates-folder/thegates/godot/bin/godot.linuxbsd.template_release.x86_64"
|
||||
custom_template/release="/home/nordup/projects/thegates-folder/thegates/godot/bin/godot.linuxbsd.template_release.x86_64"
|
||||
debug/export_console_wrapper=1
|
||||
binary_format/embed_pck=true
|
||||
texture_format/s3tc_bptc=true
|
||||
|
|
|
@ -30,7 +30,8 @@ grow_vertical = 2
|
|||
theme_override_styles/panel = SubResource("StyleBoxFlat_eeptt")
|
||||
|
||||
[node name="RichTextLabel" type="RichTextLabel" parent="Window/Background"]
|
||||
layout_mode = 0
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=36 format=3 uid="uid://kywrsqro3d5i"]
|
||||
[gd_scene load_steps=37 format=3 uid="uid://kywrsqro3d5i"]
|
||||
|
||||
[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"]
|
||||
|
@ -14,6 +14,7 @@
|
|||
[ext_resource type="Shader" path="res://shaders/render_result.gdshader" id="10_2auwe"]
|
||||
[ext_resource type="Texture2D" uid="uid://cykx425p6ylwr" path="res://assets/textures/background.png" id="10_23bjc"]
|
||||
[ext_resource type="Script" path="res://scripts/sandbox/command_sync.gd" id="10_cqo55"]
|
||||
[ext_resource type="Resource" uid="uid://cjcdum6fm4ta0" path="res://resources/api_settings.tres" id="10_vhc7k"]
|
||||
[ext_resource type="Script" path="res://scripts/sandbox/process_checker.gd" id="11_72cjp"]
|
||||
[ext_resource type="Script" path="res://scripts/ui/world/world_ui.gd" id="12_jdwjt"]
|
||||
[ext_resource type="Script" path="res://scripts/ui/world/splash_screen.gd" id="13_3b6nd"]
|
||||
|
@ -312,6 +313,7 @@ snbx_env = ExtResource("8_a6dvr")
|
|||
[node name="SandboxLogger" type="Node" parent="."]
|
||||
script = ExtResource("9_fikc8")
|
||||
gate_events = ExtResource("2_q7cvi")
|
||||
api = ExtResource("10_vhc7k")
|
||||
|
||||
[node name="InputSync" type="Node" parent="." node_paths=PackedStringArray("render_result")]
|
||||
script = ExtResource("8_1blsi")
|
||||
|
|
|
@ -17,3 +17,19 @@ func request(url: String, callback: Callable,
|
|||
remove_child(http)
|
||||
|
||||
return err
|
||||
|
||||
|
||||
func request_raw(url: String, callback: Callable,
|
||||
data: PackedByteArray, method: int = HTTPClient.METHOD_GET) -> Error:
|
||||
var headers = []
|
||||
|
||||
var http = HTTPRequest.new()
|
||||
http.use_threads = true
|
||||
add_child(http)
|
||||
|
||||
var err = http.request_raw(url, headers, method, data)
|
||||
var res = await http.request_completed
|
||||
callback.call(res[0], res[1], res[2], res[3])
|
||||
remove_child(http)
|
||||
|
||||
return err
|
||||
|
|
|
@ -3,7 +3,12 @@ extends RichTextLabel
|
|||
|
||||
func _ready() -> void:
|
||||
Debug.logged.connect(add_log)
|
||||
meta_clicked.connect(on_meta_clicked)
|
||||
|
||||
|
||||
func add_log(msg: String) -> void:
|
||||
append_text(msg + "\n")
|
||||
|
||||
|
||||
func on_meta_clicked(meta) -> void:
|
||||
OS.shell_open(str(meta))
|
||||
|
|
|
@ -30,3 +30,6 @@ var search: String :
|
|||
|
||||
var prompt: String :
|
||||
get: return url + "/api/prompt?query="
|
||||
|
||||
var send_logs: String :
|
||||
get: return url + "/api/send_logs?url="
|
||||
|
|
|
@ -2,30 +2,60 @@ extends Node
|
|||
class_name SandboxLogger
|
||||
|
||||
@export var gate_events: GateEvents
|
||||
@export var api: ApiSettings
|
||||
|
||||
const LOG_FOLDER := "user://logs"
|
||||
const LOG_FILE := "log.txt"
|
||||
const PRINT_LOGS_ARG := "--sandbox-logs"
|
||||
const FLUSH_DELAY = 5
|
||||
|
||||
var flush_timer: Timer
|
||||
|
||||
var log_file: FileAccess
|
||||
var pipe: Dictionary
|
||||
var gate: Gate
|
||||
|
||||
var print_logs: bool
|
||||
var is_started: bool
|
||||
var logs_sent: bool
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
gate_events.not_responding.connect(send_logs)
|
||||
print_logs = PRINT_LOGS_ARG in OS.get_cmdline_args()
|
||||
|
||||
|
||||
func start(_pipe: Dictionary, gate: Gate) -> void:
|
||||
func start(_pipe: Dictionary, _gate: Gate) -> void:
|
||||
pipe = _pipe
|
||||
gate = _gate
|
||||
is_started = true
|
||||
|
||||
var gate_folder = gate.url.replace("http://", "").replace("https://", "").replace(".gate", "")
|
||||
var path = LOG_FOLDER + "/" + gate_folder + "/" + LOG_FILE
|
||||
var path = LOG_FOLDER + "/" + get_folder_name(gate.url) + "/" + LOG_FILE
|
||||
var global_path = ProjectSettings.globalize_path(path)
|
||||
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)
|
||||
Debug.logclr("Logs written to [url]%s[/url]" % [global_path], Color.GRAY)
|
||||
|
||||
start_flush_timer()
|
||||
|
||||
|
||||
func get_folder_name(url: String) -> String:
|
||||
var folder = gate.url.replace("http://", "").replace("https://", "").replace(".gate", "")
|
||||
folder = folder.replace(":", "_") # remove ':' before port
|
||||
return folder
|
||||
|
||||
|
||||
func start_flush_timer() -> void:
|
||||
flush_timer = Timer.new()
|
||||
add_child(flush_timer)
|
||||
flush_timer.timeout.connect(flush_logs)
|
||||
flush_timer.start(FLUSH_DELAY)
|
||||
|
||||
|
||||
func flush_logs() -> void:
|
||||
if not log_file.is_open(): return
|
||||
log_file.flush()
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
|
@ -45,12 +75,28 @@ func _process(_delta: float) -> void:
|
|||
break;
|
||||
|
||||
if !buffer.is_empty():
|
||||
printraw(buffer.get_string_from_utf8())
|
||||
if print_logs: printraw(buffer.get_string_from_utf8())
|
||||
log_file.store_buffer(buffer)
|
||||
|
||||
|
||||
func send_logs() -> void:
|
||||
if not is_started: return
|
||||
if logs_sent: return
|
||||
logs_sent = true
|
||||
|
||||
Debug.logr("logs sent")
|
||||
flush_logs()
|
||||
var data = FileAccess.get_file_as_bytes(log_file.get_path())
|
||||
var length = data.size()
|
||||
|
||||
await send_logs_request(data, length)
|
||||
|
||||
|
||||
func send_logs_request(data: PackedByteArray, length: int) -> void:
|
||||
var url = api.send_logs + gate.url.uri_encode()
|
||||
var callback = func(_result, code, _headers, _body):
|
||||
if code == 200:
|
||||
Debug.logclr("Logs were sent %.2fKB" % [length / 1024.0], Color.DIM_GRAY)
|
||||
else: Debug.logclr("Sending logs failed. Code " + str(code), Color.RED)
|
||||
|
||||
var err = await Backend.request_raw(url, callback, data, HTTPClient.METHOD_POST)
|
||||
if err != HTTPRequest.RESULT_SUCCESS: Debug.logclr("Cannot send request send_logs", Color.RED)
|
||||
|
|
|
@ -39,10 +39,9 @@ func start_sandbox_linux(gate: Gate) -> void:
|
|||
var args = [
|
||||
snbx_env.start.get_base_dir(), # cd to dir
|
||||
"--main-pack", snbx_env.main_pack,
|
||||
"--resolution", "%dx%d" % [render_result.width, render_result.height]
|
||||
"--resolution", "%dx%d" % [render_result.width, render_result.height],
|
||||
"--verbose"
|
||||
]
|
||||
if OS.is_stdout_verbose(): args += ["--verbose"]
|
||||
args += ["--verbose"]
|
||||
Debug.logclr(snbx_env.start + " " + " ".join(args), Color.DIM_GRAY)
|
||||
|
||||
var pipe = OS.execute_with_pipe(snbx_env.start, args, false)
|
||||
|
@ -62,13 +61,15 @@ func start_sandbox_windows(gate: Gate) -> void:
|
|||
var shared_libs = ProjectSettings.globalize_path(gate.shared_libs_dir)
|
||||
var args = [
|
||||
"--main-pack", pack_file,
|
||||
"--resolution", "%dx%d" % [render_result.width, render_result.height]
|
||||
"--resolution", "%dx%d" % [render_result.width, render_result.height],
|
||||
"--verbose"
|
||||
]
|
||||
if not shared_libs.is_empty(): args += ["--gdext-libs-dir", shared_libs]
|
||||
if OS.is_stdout_verbose(): args += ["--verbose"]
|
||||
|
||||
Debug.logclr(snbx_executable.path + " " + " ".join(args), Color.DIM_GRAY)
|
||||
snbx_pid = OS.create_process(snbx_executable.path, args)
|
||||
|
||||
var pipe = OS.execute_with_pipe(snbx_executable.start, args, false)
|
||||
snbx_logger.start(pipe, gate)
|
||||
snbx_pid = pipe["pid"]
|
||||
|
||||
gate_events.gate_entered_emit()
|
||||
|
||||
|
@ -81,13 +82,15 @@ func start_sandbox_macos(gate: Gate) -> void:
|
|||
var shared_libs = ProjectSettings.globalize_path(gate.shared_libs_dir)
|
||||
var args = [
|
||||
"--main-pack", pack_file,
|
||||
"--resolution", "%dx%d" % [render_result.width, render_result.height]
|
||||
"--resolution", "%dx%d" % [render_result.width, render_result.height],
|
||||
"--verbose"
|
||||
]
|
||||
if not shared_libs.is_empty(): args += ["--gdext-libs-dir", shared_libs]
|
||||
if OS.is_stdout_verbose(): args += ["--verbose"]
|
||||
|
||||
Debug.logclr(snbx_executable.path + " " + " ".join(args), Color.DIM_GRAY)
|
||||
snbx_pid = OS.create_process(snbx_executable.path, args)
|
||||
|
||||
var pipe = OS.execute_with_pipe(snbx_executable.start, args, false)
|
||||
snbx_logger.start(pipe, gate)
|
||||
snbx_pid = pipe["pid"]
|
||||
|
||||
gate_events.gate_entered_emit()
|
||||
|
||||
|
|
2
godot
2
godot
|
@ -1 +1 @@
|
|||
Subproject commit 44488e0c7605c258ab9a6f1cde659868a491f6f8
|
||||
Subproject commit 36cbe3cb18c96a196032159b4d2ec4993d7c9479
|
Loading…
Add table
Add a link
Reference in a new issue