From ce33c964f7b6b12acd8de44afabf5081d0f3733d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 14 Aug 2026 17:00:40 +0200 Subject: [PATCH] Debugger: add log.channels.list/log.channel.set over the WebSocket API Lets a client query all log categories (Common/Log.h's Log enum) with their current level/enabled state, and change a channel's level and/or enabled state at runtime - same data LogConfigScreen already exposes in the UI, now reachable from the debugger protocol. Levels are named strings (notice, error, warning, info, debug, verbose) rather than the 1-6 numbers the existing passive 'log' event uses (LogBroadcaster.cpp, left unchanged) - clearer for a config-style API where you're not scanning a stream. Registered as a new subscriber alongside the others in WebSocket.cpp, and wired into all the build systems that need a new source file (CMake, the Windows and UWP vcxprojs, Android.mk - libretro's Makefile.common doesn't build any WebSocket debugger files so needs no entry). Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9 --- Core/CMakeLists.txt | 2 + Core/Core.vcxproj | 2 + Core/Core.vcxproj.filters | 6 + Core/Debugger/WebSocket.cpp | 2 + .../WebSocket/LogConfigSubscriber.cpp | 136 ++++++++++++++++++ Core/Debugger/WebSocket/LogConfigSubscriber.h | 25 ++++ UWP/CoreUWP/CoreUWP.vcxproj | 2 + UWP/CoreUWP/CoreUWP.vcxproj.filters | 2 + android/jni/Android.mk | 1 + docs/WebSocketDebugger.md | 1 + 10 files changed, 179 insertions(+) create mode 100644 Core/Debugger/WebSocket/LogConfigSubscriber.cpp create mode 100644 Core/Debugger/WebSocket/LogConfigSubscriber.h diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index d0c96c8018..b7c36137d9 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -321,6 +321,8 @@ add_library(Core STATIC Debugger/WebSocket/InputSubscriber.h Debugger/WebSocket/LogBroadcaster.cpp Debugger/WebSocket/LogBroadcaster.h + Debugger/WebSocket/LogConfigSubscriber.cpp + Debugger/WebSocket/LogConfigSubscriber.h Debugger/WebSocket/MemoryInfoSubscriber.cpp Debugger/WebSocket/MemoryInfoSubscriber.h Debugger/WebSocket/MemorySubscriber.cpp diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 6021f1af71..a9f98de6a3 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -456,6 +456,7 @@ + @@ -1002,6 +1003,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index b29f7341b6..e47b6ce596 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -718,6 +718,9 @@ Debugger\WebSocket + + Debugger\WebSocket + Debugger\WebSocket @@ -1989,6 +1992,9 @@ Debugger\WebSocket + + Debugger\WebSocket + Debugger\WebSocket diff --git a/Core/Debugger/WebSocket.cpp b/Core/Debugger/WebSocket.cpp index d885a5544a..abbdcded06 100644 --- a/Core/Debugger/WebSocket.cpp +++ b/Core/Debugger/WebSocket.cpp @@ -63,6 +63,7 @@ #include "Core/Debugger/WebSocket/GPUStatsSubscriber.h" #include "Core/Debugger/WebSocket/HLESubscriber.h" #include "Core/Debugger/WebSocket/InputSubscriber.h" +#include "Core/Debugger/WebSocket/LogConfigSubscriber.h" #include "Core/Debugger/WebSocket/MemoryInfoSubscriber.h" #include "Core/Debugger/WebSocket/MemorySubscriber.h" #include "Core/Debugger/WebSocket/ReplaySubscriber.h" @@ -81,6 +82,7 @@ static const std::vector subscribers({ &WebSocketGPUStatsInit, &WebSocketHLEInit, &WebSocketInputInit, + &WebSocketLogConfigInit, &WebSocketMemoryInfoInit, &WebSocketMemoryInit, &WebSocketReplayInit, diff --git a/Core/Debugger/WebSocket/LogConfigSubscriber.cpp b/Core/Debugger/WebSocket/LogConfigSubscriber.cpp new file mode 100644 index 0000000000..96acf51304 --- /dev/null +++ b/Core/Debugger/WebSocket/LogConfigSubscriber.cpp @@ -0,0 +1,136 @@ +// Copyright (c) 2026- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +// This is about the log *channels themselves* (their level/enabled state) - the actual log +// message stream is a separate, passive broadcast, see LogBroadcaster.cpp's "log" event (which +// keeps its existing numeric 'level' - only this newer API uses level names, for readability). + +#include "Common/Log/LogManager.h" +#include "Core/Debugger/WebSocket/LogConfigSubscriber.h" +#include "Core/Debugger/WebSocket/WebSocketUtils.h" + +static const char *LogLevelToString(LogLevel level) { + switch (level) { + case LogLevel::LNOTICE: return "notice"; + case LogLevel::LERROR: return "error"; + case LogLevel::LWARNING: return "warning"; + case LogLevel::LINFO: return "info"; + case LogLevel::LDEBUG: return "debug"; + case LogLevel::LVERBOSE: return "verbose"; + default: return "unknown"; + } +} + +static bool LogLevelFromString(const std::string &s, LogLevel *out) { + if (s == "notice") *out = LogLevel::LNOTICE; + else if (s == "error") *out = LogLevel::LERROR; + else if (s == "warning") *out = LogLevel::LWARNING; + else if (s == "info") *out = LogLevel::LINFO; + else if (s == "debug") *out = LogLevel::LDEBUG; + else if (s == "verbose") *out = LogLevel::LVERBOSE; + else return false; + return true; +} + +DebuggerSubscriber *WebSocketLogConfigInit(DebuggerEventHandlerMap &map) { + map["log.channels.list"] = &WebSocketLogChannelsList; + map["log.channel.set"] = &WebSocketLogChannelSet; + return nullptr; +} + +// List all log channels and their current level/enabled state (log.channels.list) +// +// No parameters. +// +// Response (same event name): +// - channels: array of objects, each with properties: +// - name: string channel name - pass this back as 'channel' to log.channel.set. +// - level: string severity level, one of 'notice', 'error', 'warning', 'info', 'debug', +// 'verbose' (in that order, least to most noisy.) A message is only actually logged for +// this channel if its own level is at or above this severity, and the channel is enabled. +// - enabled: boolean, whether this channel logs anything at all right now. +void WebSocketLogChannelsList(DebuggerRequest &req) { + JsonWriter &json = req.Respond(); + json.pushArray("channels"); + for (int i = 0; i < LogManager::GetNumChannels(); ++i) { + Log type = (Log)i; + const LogChannel *chan = g_logManager.GetLogChannel(type); + json.pushDict(); + json.writeString("name", LogManager::GetLogTypeName(type)); + json.writeString("level", LogLevelToString(chan->level)); + json.writeBool("enabled", chan->enabled); + json.pop(); + } + json.pop(); +} + +// Change a log channel's level and/or enabled state (log.channel.set) +// +// Parameters: +// - channel: string, channel name (as returned by log.channels.list - case sensitive.) +// - level: optional string, one of 'notice', 'error', 'warning', 'info', 'debug', 'verbose' - +// see log.channels.list for what this means. +// - enabled: optional boolean, whether this channel should log at all. +// +// At least one of level/enabled must be given. +// +// Response (same event name): +// - name: channel name, repeated back. +// - level: the channel's resulting level (string, see log.channels.list.) +// - enabled: the channel's resulting enabled state. +void WebSocketLogChannelSet(DebuggerRequest &req) { + std::string channelName; + if (!req.ParamString("channel", &channelName)) + return; + + bool hasLevel = req.HasParam("level"); + LogLevel level = LogLevel::LNOTICE; + if (hasLevel) { + std::string levelStr; + if (!req.ParamString("level", &levelStr, DebuggerParamType::OPTIONAL)) + return; + if (!LogLevelFromString(levelStr, &level)) + return req.Fail("Invalid 'level', must be notice, error, warning, info, debug, or verbose"); + } + bool hasEnabled = req.HasParam("enabled"); + bool enabled = false; + if (hasEnabled && !req.ParamBool("enabled", &enabled, DebuggerParamType::OPTIONAL)) + return; + + if (!hasLevel && !hasEnabled) + return req.Fail("Must specify 'level' and/or 'enabled'"); + + for (int i = 0; i < LogManager::GetNumChannels(); ++i) { + Log type = (Log)i; + if (channelName != LogManager::GetLogTypeName(type)) + continue; + + if (hasLevel) + g_logManager.SetLogLevel(type, level); + if (hasEnabled) + g_logManager.SetEnabled(type, enabled); + + const LogChannel *chan = g_logManager.GetLogChannel(type); + JsonWriter &json = req.Respond(); + json.writeString("name", channelName); + json.writeString("level", LogLevelToString(chan->level)); + json.writeBool("enabled", chan->enabled); + return; + } + + req.Fail("No log channel found with that name"); +} diff --git a/Core/Debugger/WebSocket/LogConfigSubscriber.h b/Core/Debugger/WebSocket/LogConfigSubscriber.h new file mode 100644 index 0000000000..8afa4f6498 --- /dev/null +++ b/Core/Debugger/WebSocket/LogConfigSubscriber.h @@ -0,0 +1,25 @@ +// Copyright (c) 2026- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#pragma once + +#include "Core/Debugger/WebSocket/WebSocketUtils.h" + +DebuggerSubscriber *WebSocketLogConfigInit(DebuggerEventHandlerMap &map); + +void WebSocketLogChannelsList(DebuggerRequest &req); +void WebSocketLogChannelSet(DebuggerRequest &req); diff --git a/UWP/CoreUWP/CoreUWP.vcxproj b/UWP/CoreUWP/CoreUWP.vcxproj index c04ada6bc4..83fc21a149 100644 --- a/UWP/CoreUWP/CoreUWP.vcxproj +++ b/UWP/CoreUWP/CoreUWP.vcxproj @@ -115,6 +115,7 @@ + @@ -390,6 +391,7 @@ + diff --git a/UWP/CoreUWP/CoreUWP.vcxproj.filters b/UWP/CoreUWP/CoreUWP.vcxproj.filters index 5112630af1..fda2d43b13 100644 --- a/UWP/CoreUWP/CoreUWP.vcxproj.filters +++ b/UWP/CoreUWP/CoreUWP.vcxproj.filters @@ -28,6 +28,7 @@ + @@ -446,6 +447,7 @@ + diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 34af103035..d46c49a8f9 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -671,6 +671,7 @@ EXEC_AND_LIB_FILES := \ $(SRC)/Core/Debugger/WebSocket/InputBroadcaster.cpp \ $(SRC)/Core/Debugger/WebSocket/InputSubscriber.cpp \ $(SRC)/Core/Debugger/WebSocket/LogBroadcaster.cpp \ + $(SRC)/Core/Debugger/WebSocket/LogConfigSubscriber.cpp \ $(SRC)/Core/Debugger/WebSocket/MemorySubscriber.cpp \ $(SRC)/Core/Debugger/WebSocket/MemoryInfoSubscriber.cpp \ $(SRC)/Core/Debugger/WebSocket/ReplaySubscriber.cpp \ diff --git a/docs/WebSocketDebugger.md b/docs/WebSocketDebugger.md index ba529af390..1062d414a8 100644 --- a/docs/WebSocketDebugger.md +++ b/docs/WebSocketDebugger.md @@ -123,6 +123,7 @@ file - this is just an index. | Input injection | `input.buttons.send`, `input.buttons.press`, `input.analog.send` | `InputSubscriber.cpp` | | Replay | `replay.begin/abort/flush/execute/status`, `replay.time.get/set` | `ReplaySubscriber.cpp` | | Client config | `broadcast.config.get/set` | `ClientConfigSubscriber.cpp` | +| Log channels | `log.channels.list`, `log.channel.set` - query/change a log channel's level (string: `notice`/`error`/`warning`/`info`/`debug`/`verbose`) and/or enabled state; the `log` event itself (the passive message stream, unaffected by this) keeps its existing numeric `level`, see `LogBroadcaster.cpp` | `LogConfigSubscriber.cpp` | ## Enabling it