Captures JS console output (console.log/warn/error) for inspector display. More...
#include <console_capture.hpp>
Classes | |
| struct | Entry |
| A captured log entry. More... | |
Public Types | |
| using | LogCallback = std::function<void(std::string_view level, std::string_view message)> |
| using | EntrySink = std::function<void(const Entry&)> |
| Fired on the capturing (engine/UI) thread for each new entry. | |
Public Member Functions | |
| LogCallback | callback (LogCallback previous={}) |
| Install the capture. | |
| std::vector< Entry > | entries () const |
| Get all captured entries (ring buffer, last 200). | |
| 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 (as the next cursor). | |
| uint64_t | latest_seq () const |
| The highest sequence assigned so far (0 when nothing captured). | |
| void | set_entry_sink (EntrySink sink) |
| Install a sink invoked synchronously for every newly captured entry. | |
| void | clear () |
| Clear all entries (does not reset the sequence counter). | |
Captures JS console output (console.log/warn/error) for inspector display.
Chains on an existing log callback — does not replace it.
Each entry carries a strictly increasing seq, so a device-log client can poll only what is new since its last cursor (entries_since) instead of re-reading the whole ring buffer. An optional sink fires synchronously on each capture so a canonical control router can also push live Console.messageAdded events.
| using pulp::inspect::ConsoleCapture::EntrySink = std::function<void(const Entry&)> |
Fired on the capturing (engine/UI) thread for each new entry.
| using pulp::inspect::ConsoleCapture::LogCallback = std::function<void(std::string_view level, std::string_view message)> |
| LogCallback pulp::inspect::ConsoleCapture::callback | ( | LogCallback | previous = {} | ) |
Install the capture.
Chains with the previous callback. Call with the ScriptEngine's set_log_callback: engine.set_log_callback(capture.callback());
| void pulp::inspect::ConsoleCapture::clear | ( | ) |
Clear all entries (does not reset the sequence counter).
| std::vector< Entry > pulp::inspect::ConsoleCapture::entries | ( | ) | const |
Get all captured entries (ring buffer, last 200).
| std::vector< Entry > pulp::inspect::ConsoleCapture::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 (as the next cursor).
A client passes back the previous next_seq to page forward without duplicates. Because the buffer is bounded, entries older than the retained window are dropped; the returned next_seq still advances past them.
| uint64_t pulp::inspect::ConsoleCapture::latest_seq | ( | ) | const |
The highest sequence assigned so far (0 when nothing captured).
| void pulp::inspect::ConsoleCapture::set_entry_sink | ( | EntrySink | sink | ) |
Install a sink invoked synchronously for every newly captured entry.
Pass {} to clear. Used for live event push; polling works without it.