Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
console_capture.hpp
Go to the documentation of this file.
1// console_capture.hpp — JS console log interception for the inspector
2#pragma once
3
4#include <chrono>
5#include <cstdint>
6#include <functional>
7#include <mutex>
8#include <string>
9#include <string_view>
10#include <vector>
11
12namespace pulp::inspect {
13
23public:
25 struct Entry {
26 std::string level; // "log", "warn", "error", "info", "debug"
27 std::string message;
28 std::chrono::steady_clock::time_point time;
29 uint64_t seq = 0; // strictly increasing capture sequence (>= 1)
30 };
31
32 using LogCallback = std::function<void(std::string_view level, std::string_view message)>;
34 using EntrySink = std::function<void(const Entry&)>;
35
39
41 std::vector<Entry> entries() const;
42
48 std::vector<Entry> entries_since(uint64_t after_seq, uint64_t& next_seq) const;
49
51 uint64_t latest_seq() const;
52
56
58 void clear();
59
60private:
61 mutable std::mutex mutex_;
62 std::vector<Entry> entries_;
63 EntrySink sink_;
64 uint64_t next_seq_ = 0;
65 static constexpr size_t kMaxEntries = 200;
66};
67
68} // namespace pulp::inspect
Captures JS console output (console.log/warn/error) for inspector display.
Definition console_capture.hpp:22
void set_entry_sink(EntrySink sink)
Install a sink invoked synchronously for every newly captured entry.
std::function< void(std::string_view level, std::string_view message)> LogCallback
Definition console_capture.hpp:32
std::function< void(const Entry &)> EntrySink
Fired on the capturing (engine/UI) thread for each new entry.
Definition console_capture.hpp:34
void clear()
Clear all entries (does not reset the sequence counter).
uint64_t latest_seq() const
The highest sequence assigned so far (0 when nothing captured).
std::vector< Entry > entries() const
Get all captured entries (ring buffer, last 200).
LogCallback callback(LogCallback previous={})
Install the capture.
std::vector< Entry > entries_since(uint64_t after_seq, uint64_t &next_seq) const
Get only entries whose seq is strictly greater than after_seq, plus the highest seq observed so far (...
Definition agent_context.hpp:7
A captured log entry.
Definition console_capture.hpp:25
std::chrono::steady_clock::time_point time
Definition console_capture.hpp:28
std::string level
Definition console_capture.hpp:26
uint64_t seq
Definition console_capture.hpp:29
std::string message
Definition console_capture.hpp:27