3#ifndef _FRAY_ENGINE_LOG_SINK_HPP_
4#define _FRAY_ENGINE_LOG_SINK_HPP_
7#include <condition_variable>
45 std::condition_variable
idle;
61 std::lock_guard<std::mutex> lock(
state->mutex);
62 if (--
state->active == 0)
63 state->idle.notify_all();
75 std::shared_ptr<State>
_state = std::make_shared<State>();
83 std::unique_lock<std::mutex> lock(
_state->mutex);
90 _state->idle.wait(lock, [
this] {
return _state->active == 0; });
91 if (!
_state->pending.empty())
93 std::fprintf(stderr,
"Cannot store %zu startup log entries: log sink was never attached.\n",
110 thread_local bool busy =
false;
115 const auto now = std::chrono::system_clock::now().time_since_epoch();
116 Captured entry{level, thread, project,
message,
static_cast<std::uint64_t
>(
117 std::chrono::duration_cast<std::chrono::microseconds>(now).count()),
consoleVisible};
121 std::lock_guard<std::mutex> lock(
state->mutex);
126 state->pending.push_back(std::move(entry));
166 std::lock_guard<std::mutex> lock(sink.
_state->mutex);
168 throw std::logic_error(
"Engine log sink is already attached or detached.");
169 for (
const auto& entry : sink.
_state->pending)
170 app.
recordEngineLog(entry.level.c_str(), entry.thread, entry.project, entry.text.c_str(), &
ipc,
171 entry.arrivedUs, entry.consoleVisible);
172 sink.
_state->pending.clear();
187 std::lock_guard<std::mutex> lock(
_state->mutex);
188 _state->forwarding =
false;
Owns and coordinates projects, their queues, application work, prompts, and logs. Project work runs o...
void recordEngineLog(const char *level, F_long thread, const std::string &project, const char *text, ipc::IPCManager *ipc, std::uint64_t arrivedUs=0, bool consoleVisible=true)
Prepares an Engine log line and independently queues Console delivery and persistence.
Owns the TCP servers and the threads around them.
Attachment(EngineLogSink &sink, FrayManager &app, ipc::IPCManager &ipc)
Attaches the managers and submits buffered startup lines in capture order.
~Attachment()
Detaches before the managers are destroyed.
Attachment & operator=(const Attachment &)=delete
Attachment(const Attachment &)=delete
F_void stopForwarding()
Stops forwarding to the renderer while continuing to store Engine logs.
~EngineLogSink()
Removes the sink if it has not already been detached.
EngineLogSink & operator=(const EngineLogSink &)=delete
std::shared_ptr< State > _state
EngineLogSink(const EngineLogSink &)=delete
EngineLogSink()
Installs the startup buffer before the managers are created.
void detach()
Stops accepting sink calls and waits for existing calls to release the manager references....
bool & consoleVisible()
Whether the calling thread's log entries may be shown in the Console.
F_void setSink(Sink sink)
Replace the sink; an empty function removes it. Locks sinkMutex; an in-flight logging call may still ...
Releases an in-flight call even if recording throws.
~ActiveCall()
Marks the callback complete and wakes a detaching owner.
std::shared_ptr< State > state
An owned log line captured before the managers were attached.
Restores the thread-local recursion guard.
~RecursionGuard()
Clears the guard on every exit path.
Shared callback state, kept alive by in-flight sink snapshots.
std::condition_variable idle
std::vector< Captured > pending
int32_t F_long
Signed 32-bit integer (also the base of F_err).
void F_void
Alias for void.
char F_char
Alias for char.