From c4e43d22b46076dfd9c3a3ba7e24bd080eb9fdad Mon Sep 17 00:00:00 2001 From: Xein Date: Mon, 26 Oct 2026 10:48:46 +0100 Subject: [PATCH 1/2] Log server v2 --- .github/workflows/ci-build-windows.yml | 3 + .github/workflows/ci-linux-dev.yml | 3 + .github/workflows/ci-linux-main.yml | 51 +- .gitmodules | 3 + docs/logging_system.md | 4 +- editor/Engine/Log.cs | 11 + editor/Engine/ToastEngine.cs | 8 +- editor/Logger/LogCsv.cs | 6 + editor/Logger/LogDetailWindow.axaml | 58 +- editor/Logger/LogDetailWindow.axaml.cs | 5 + editor/Logger/LogEntry.cs | 11 +- editor/Logger/Logger.cs | 12 +- engine/CMakeLists.txt | 16 +- engine/ffi/log.h | 1 + engine/src/toast/audio/audio_system.cpp | 6 +- engine/src/toast/backtrace.cpp | 208 +++++ engine/src/toast/backtrace.hpp | 29 + engine/src/toast/crash_handler.cpp | 84 +- engine/src/toast/crash_handler.hpp | 5 +- engine/src/toast/crash_handler_posix.cpp | 256 ++++++ engine/src/toast/debugger.cpp | 140 ++++ engine/src/toast/engine.cpp | 2 +- engine/src/toast/log.hpp | 172 +++- engine/src/toast/logger.cpp | 406 +++++++--- engine/src/toast/logger.hpp | 49 +- engine/src/toast/renderer/shader_compiler.cpp | 2 +- engine/src/toast/renderer/vulkan_core.cpp | 32 +- engine/src/toast/scripting/lua_state.cpp | 7 +- engine/src/toast/window/sdl_window.cpp | 3 +- protos/logging.proto | 2 + tools/CMakeLists.txt | 25 +- tools/kenzo | 1 + tools/kenzo/CMakeLists.txt | 25 - tools/kenzo/Cargo.toml | 21 - tools/kenzo/src/app.rs | 743 ------------------ tools/kenzo/src/main.rs | 47 -- tools/kenzo/src/proto.rs | 59 -- tools/kenzo/src/tui.rs | 25 - tools/kenzo/src/ui.rs | 670 ---------------- tools/log_server/CMakeLists.txt | 85 +- tools/log_server/Cargo.toml | 16 - tools/log_server/checks/checks.cpp | 485 ++++++++++++ tools/log_server/src/main.cpp | 181 +++++ tools/log_server/src/main.rs | 50 -- tools/log_server/src/proto.rs | 69 -- tools/log_server/src/remote_config.hpp | 27 + tools/log_server/src/server.cpp | 264 +++++++ tools/log_server/src/server.hpp | 42 + tools/log_server/src/server.rs | 182 ----- tools/log_server/src/storage.cpp | 458 +++++++++++ tools/log_server/src/storage.hpp | 92 +++ tools/log_server/src/storage.rs | 80 -- tools/log_server/src/upload.cpp | 519 ++++++++++++ tools/log_server/src/upload.hpp | 63 ++ vcpkg.json | 16 + 55 files changed, 3605 insertions(+), 2235 deletions(-) create mode 100644 .gitmodules create mode 100644 engine/src/toast/backtrace.cpp create mode 100644 engine/src/toast/backtrace.hpp create mode 100644 engine/src/toast/crash_handler_posix.cpp create mode 100644 engine/src/toast/debugger.cpp create mode 160000 tools/kenzo delete mode 100644 tools/kenzo/CMakeLists.txt delete mode 100644 tools/kenzo/Cargo.toml delete mode 100644 tools/kenzo/src/app.rs delete mode 100644 tools/kenzo/src/main.rs delete mode 100644 tools/kenzo/src/proto.rs delete mode 100644 tools/kenzo/src/tui.rs delete mode 100644 tools/kenzo/src/ui.rs delete mode 100644 tools/log_server/Cargo.toml create mode 100644 tools/log_server/checks/checks.cpp create mode 100644 tools/log_server/src/main.cpp delete mode 100644 tools/log_server/src/main.rs delete mode 100644 tools/log_server/src/proto.rs create mode 100644 tools/log_server/src/remote_config.hpp create mode 100644 tools/log_server/src/server.cpp create mode 100644 tools/log_server/src/server.hpp delete mode 100644 tools/log_server/src/server.rs create mode 100644 tools/log_server/src/storage.cpp create mode 100644 tools/log_server/src/storage.hpp delete mode 100644 tools/log_server/src/storage.rs create mode 100644 tools/log_server/src/upload.cpp create mode 100644 tools/log_server/src/upload.hpp diff --git a/.github/workflows/ci-build-windows.yml b/.github/workflows/ci-build-windows.yml index 31e8b9e44..a00f75925 100644 --- a/.github/workflows/ci-build-windows.yml +++ b/.github/workflows/ci-build-windows.yml @@ -34,6 +34,7 @@ jobs: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} fetch-depth: 1 + submodules: true - name: Setup .NET uses: actions/setup-dotnet@v5 @@ -73,6 +74,7 @@ jobs: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} fetch-depth: 1 + submodules: true - name: Setup .NET uses: actions/setup-dotnet@v5 @@ -116,6 +118,7 @@ jobs: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} fetch-depth: 1 + submodules: true - name: Setup .NET uses: actions/setup-dotnet@v5 diff --git a/.github/workflows/ci-linux-dev.yml b/.github/workflows/ci-linux-dev.yml index 649e3166d..057ed08a5 100644 --- a/.github/workflows/ci-linux-dev.yml +++ b/.github/workflows/ci-linux-dev.yml @@ -27,6 +27,7 @@ jobs: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} fetch-depth: 1 + submodules: true - name: Install Nix uses: cachix/install-nix-action@v31.10.6 @@ -60,6 +61,7 @@ jobs: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} fetch-depth: 1 + submodules: true - name: Install Nix uses: cachix/install-nix-action@v31.10.6 @@ -89,6 +91,7 @@ jobs: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} fetch-depth: 1 + submodules: true - name: Install Nix uses: cachix/install-nix-action@v31.10.6 diff --git a/.github/workflows/ci-linux-main.yml b/.github/workflows/ci-linux-main.yml index 8ee8a23e6..8eae0a8ee 100644 --- a/.github/workflows/ci-linux-main.yml +++ b/.github/workflows/ci-linux-main.yml @@ -47,6 +47,7 @@ jobs: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} fetch-depth: 1 + submodules: true - name: Install Nix uses: cachix/install-nix-action@v31.10.6 @@ -81,6 +82,7 @@ jobs: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} fetch-depth: 1 + submodules: true - name: Install Nix uses: cachix/install-nix-action@v31.10.6 @@ -100,29 +102,6 @@ jobs: bash ./tools/ci/clang_tidy.sh build " - cargo-log-server: - name: Cargo log_server (${{ matrix.build_type }}) - runs-on: [self-hosted, Linux, X64] - strategy: - matrix: - build_type: [debug, release] - fail-fast: false - steps: - - name: Checkout PR branch - uses: actions/checkout@v4 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.head_ref }} - fetch-depth: 1 - - - name: Install Nix - uses: cachix/install-nix-action@v31.10.6 - - - name: Cargo build - env: - RELEASE_FLAG: ${{ matrix.build_type == 'release' && '--release' || '' }} - run: nix develop --command bash -c "rustup toolchain install stable --no-self-update && rustup default stable && cargo build --manifest-path tools/log_server/Cargo.toml $RELEASE_FLAG" - cargo-reflection-generator: name: Cargo reflection_generator (${{ matrix.build_type }}) runs-on: [self-hosted, Linux, X64] @@ -137,6 +116,7 @@ jobs: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} fetch-depth: 1 + submodules: true - name: Install Nix uses: cachix/install-nix-action@v31.10.6 @@ -146,29 +126,6 @@ jobs: RELEASE_FLAG: ${{ matrix.build_type == 'release' && '--release' || '' }} run: nix develop --command bash -c "rustup toolchain install stable --no-self-update && rustup default stable && cargo build --manifest-path tools/reflection_generator/Cargo.toml $RELEASE_FLAG" - cargo-kenzo: - name: Cargo kenzo (${{ matrix.build_type }}) - runs-on: [self-hosted, Linux, X64] - strategy: - matrix: - build_type: [debug, release] - fail-fast: false - steps: - - name: Checkout PR branch - uses: actions/checkout@v4 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.head_ref }} - fetch-depth: 1 - - - name: Install Nix - uses: cachix/install-nix-action@v31.10.6 - - - name: Cargo build - env: - RELEASE_FLAG: ${{ matrix.build_type == 'release' && '--release' || '' }} - run: nix develop --command bash -c "rustup toolchain install stable --no-self-update && rustup default stable && cargo build --manifest-path tools/kenzo/Cargo.toml $RELEASE_FLAG" - dotnet-editor: name: Dotnet editor (${{ matrix.build_type }}) runs-on: [self-hosted, Linux, X64] @@ -183,6 +140,7 @@ jobs: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} fetch-depth: 1 + submodules: true - name: Install Nix uses: cachix/install-nix-action@v31.10.6 @@ -204,6 +162,7 @@ jobs: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.head_ref }} fetch-depth: 1 + submodules: true - name: Install Nix uses: cachix/install-nix-action@v31.10.6 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..79cea7045 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tools/kenzo"] + path = tools/kenzo + url = https://github.com/ynks/kenzo diff --git a/docs/logging_system.md b/docs/logging_system.md index 7b3d5e6f0..b5ca0b5ba 100644 --- a/docs/logging_system.md +++ b/docs/logging_system.md @@ -6,8 +6,8 @@ > The logging system provides an easy way to write logs and visualize them after the program -execution has finished. It contains a C++ implementation for producing messages, a Rust -server for receiving, processing and storing messages, and a Rust TUI for easily reading +execution has finished. It contains a C++ implementation for producing messages, a C++ +server for receiving, processing and storing messages, and a TUI for easily reading and searching for information after reading. To use this system you can simply just include `` and call any of the toast diff --git a/editor/Engine/Log.cs b/editor/Engine/Log.cs index 4e681df31..95ef66bda 100644 --- a/editor/Engine/Log.cs +++ b/editor/Engine/Log.cs @@ -31,6 +31,14 @@ public static void Critical( Dispatch(toast_critical, message, Path.GetFileName(fileName), (uint)lineNumber); } + public static void InvalidateBacktraceCache() { + try { + toast_log_invalidate_backtraces(); + } catch (DllNotFoundException) { + // Nothing was resolved without the engine + } + } + // Fallback to the console if toast-engine is not loaded private static void Dispatch( Action sink, string message, string fileName, uint lineNumber) { @@ -56,4 +64,7 @@ private static void Dispatch( [LibraryImport("toast_engine", StringMarshalling = StringMarshalling.Utf8)] private static partial void toast_critical(string sink, string message, string fileName, uint lineNumber); + + [LibraryImport("toast_engine")] + private static partial void toast_log_invalidate_backtraces(); } diff --git a/editor/Engine/ToastEngine.cs b/editor/Engine/ToastEngine.cs index 29efb46f1..d226f878e 100644 --- a/editor/Engine/ToastEngine.cs +++ b/editor/Engine/ToastEngine.cs @@ -326,6 +326,7 @@ public void ReloadGame() { Log.Info($"Reloading game library: {gameDll}"); File.Copy(gameDll, newTempPath); newHandle = NativeLibrary.Load(newTempPath); + Log.InvalidateBacktraceCache(); var newCreate = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(newHandle, "game_create")); var newDestroy = @@ -347,7 +348,10 @@ public void ReloadGame() { toast_begin_application(); } catch (Exception ex) { if (!adopted) { - if (newHandle != IntPtr.Zero) NativeLibrary.Free(newHandle); + if (newHandle != IntPtr.Zero) { + NativeLibrary.Free(newHandle); + Log.InvalidateBacktraceCache(); + } TryDeleteGameTemp(newTempPath); } @@ -451,6 +455,7 @@ private string FindGameDll() { private void LoadFrom(string dllPath) { m_gameHandle = NativeLibrary.Load(dllPath); + Log.InvalidateBacktraceCache(); m_gameTempPath = dllPath; m_gameCreate = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(m_gameHandle, "game_create")); @@ -472,6 +477,7 @@ private void ReleaseGameLibraries() { } m_retiredGameLibraries.Clear(); + Log.InvalidateBacktraceCache(); } private static void TryDeleteGameTemp(string path) { diff --git a/editor/Logger/LogCsv.cs b/editor/Logger/LogCsv.cs index a34e967fd..0fd8c5473 100644 --- a/editor/Logger/LogCsv.cs +++ b/editor/Logger/LogCsv.cs @@ -12,6 +12,8 @@ namespace editor.Logger; // Mirrors the CSV format written by the log_server internal static class LogCsv { + public const string Header = "Timestamp,Severity,Filepath,Line,Sink,Message,Details,Backtrace"; + private static readonly string[] s_severityNames = ["TRACE", "INFO", "WARNING", "ERROR", "CRITICAL"]; private static readonly SearchValues s_mustQuote = SearchValues.Create(",\"\r\n"); @@ -33,6 +35,10 @@ public static string ToCsvLine(LogEntry entry) { AppendField(sb, entry.Sink); sb.Append(','); AppendField(sb, entry.Message); + sb.Append(','); + AppendField(sb, entry.Details); + sb.Append(','); + AppendField(sb, entry.Backtrace); return sb.ToString(); } diff --git a/editor/Logger/LogDetailWindow.axaml b/editor/Logger/LogDetailWindow.axaml index c893fb921..2abf4a6ba 100644 --- a/editor/Logger/LogDetailWindow.axaml +++ b/editor/Logger/LogDetailWindow.axaml @@ -10,7 +10,7 @@ x:DataType="vm:LogEntry" Width="700" MinHeight="260" - MaxHeight="640" + MaxHeight="900" SizeToContent="Height" CanResize="False" CanMaximize="False" @@ -39,7 +39,8 @@ + CornerRadius="3" + VerticalAlignment="Center"/> @@ -81,17 +86,56 @@ CornerRadius="8" Padding="8" MaxHeight="300"> + + + + + + + + + + - - - + - -