|
Entropic 2.3.8
Local-first agentic inference engine
|
spdlog initialization and logger access. More...
#include <entropic/entropic_export.h>#include <spdlog/spdlog.h>#include <spdlog/sinks/stdout_color_sinks.h>#include <chrono>#include <filesystem>#include <memory>#include <string>
Go to the source code of this file.
Classes | |
| class | entropic::log::HandleLogScope |
| gh#59 (v2.3.1): RAII guard — sets thread's current handle_id. More... | |
Namespaces | |
| namespace | entropic |
| Activate model on GPU (WARM → ACTIVE). | |
Functions | |
| ENTROPIC_EXPORT void | entropic::log::init (spdlog::level::level_enum level=spdlog::level::info) |
| Initialize the logging subsystem. | |
| ENTROPIC_EXPORT void | entropic::log::add_file_sink (const std::filesystem::path &path) |
| Add a file sink to all loggers (truncated per run). | |
| ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > | entropic::log::get (const std::string &name) |
| Get or create a named logger. | |
| ENTROPIC_EXPORT void | entropic::log::setup_session (const std::filesystem::path &log_dir) |
| Set up session logging for a project directory. | |
| ENTROPIC_EXPORT void | entropic::log::set_console_enabled (bool enabled) |
| Enable or disable the stderr console sink process-wide. | |
| ENTROPIC_EXPORT void | entropic::log::register_handle_log (int handle_id, const std::filesystem::path &log_dir) |
| gh#59 (v2.3.1): register a per-handle session.log file. | |
| ENTROPIC_EXPORT void | entropic::log::unregister_handle_log (int handle_id) |
| gh#59 (v2.3.1): release a handle's session.log file sink. | |
| ENTROPIC_EXPORT int | entropic::log::current_handle_id () |
| gh#59 (v2.3.1): query the current thread's handle_id. | |
| auto | entropic::log::now () |
| Get current time for timing measurements. | |
| double | entropic::log::elapsed_ms (std::chrono::steady_clock::time_point start, std::chrono::steady_clock::time_point end) |
| Compute elapsed milliseconds between two time points. | |
| ENTROPIC_EXPORT std::string | entropic::log::escape_content (const std::string &text) |
| Escape content for safe spdlog formatting. | |
| ENTROPIC_EXPORT void | entropic::log::log_content (const std::shared_ptr< spdlog::logger > &logger, spdlog::level::level_enum level, const std::string &label, const std::string &text) |
| Log full content with escaping applied. | |
| ENTROPIC_EXPORT void | entropic::log::log_timing (const std::shared_ptr< spdlog::logger > &logger, const std::string &label, double ms) |
| Log a timing measurement. | |
| ENTROPIC_EXPORT void | entropic::log::log_tokens (const std::shared_ptr< spdlog::logger > &logger, int count, double time_ms) |
| Log token count with throughput. | |
| ENTROPIC_EXPORT void | entropic::log::log_decision (const std::shared_ptr< spdlog::logger > &logger, const std::string &label, const std::string &key, const std::string &value) |
| Log a decision/routing event. | |
spdlog initialization and logger access.
Every .so in the entropic project uses spdlog for structured logging. This header establishes the initialization pattern used from v1.8.0 onward. All loggers are created through this interface.
Definition in file logging.h.
| void entropic::log::add_file_sink | ( | const std::filesystem::path & | path | ) |
Add a file sink to all loggers (truncated per run).
Add a rotating file sink to all loggers.
Creates the parent directory, opens the file (truncating any existing content), adds the sink to the default logger, and applies it to every logger already registered. Loggers created after this call inherit the sink automatically via get().
| path | Log file path. |
Creates the log directory, adds the sink to the default logger, then walks every registered logger and adds the same sink. Future loggers created via get() inherit it automatically.
| path | Log file path. |
| max_size | Max bytes before rotation. |
| max_files | Rotated files to keep. @utility |
Definition at line 179 of file logging.cpp.
| int entropic::log::current_handle_id | ( | ) |
gh#59 (v2.3.1): query the current thread's handle_id.
gh#59 public entry — see header.
Returns 0 if no HandleLogScope is active on this thread. Mostly for tests; production code should rely on the dispatcher routing.
@utility
Definition at line 540 of file logging.cpp.
|
inline |
| std::string entropic::log::escape_content | ( | const std::string & | text | ) |
Escape content for safe spdlog formatting.
Replaces embedded newlines with \n, ANSI escape sequences with their hex representation, and curly braces (fmt specifiers) with doubled braces so spdlog/fmt does not interpret them.
| text | Raw content (user input or model output). |
Replaces embedded newlines with \n, carriage returns with \r, ANSI escape sequences with [ESC...], and curly braces with doubled braces so spdlog/fmt does not interpret them as format specifiers.
| text | Raw content. |
Definition at line 409 of file logging.cpp.
| std::shared_ptr< spdlog::logger > entropic::log::get | ( | const std::string & | name | ) |
Get or create a named logger.
Get or create a named logger sharing current sinks.
Returns the existing logger if already created, or creates a new one sharing the root sink configuration.
| name | Logger name (e.g., "types", "inference", "mcp"). |
New loggers inherit sinks from the default logger rather than the original s_sink. This ensures loggers created after test infrastructure replaces sinks via spdlog::apply_all() still write to the correct destinations (e.g., per-test file sinks).
| name | Logger name. |
Definition at line 211 of file logging.cpp.
| void entropic::log::init | ( | spdlog::level::level_enum | level = spdlog::level::info | ) |
Initialize the logging subsystem.
Call once at engine startup (in entropic_create). Sets the global log level and output format. Subsequent calls are no-ops.
| level | spdlog level (trace, debug, info, warn, error, critical). |
Uses stderr so that engine diagnostic output does not interleave with the stdout streaming token callback used by TUI consumers.
| level | spdlog level. Subsequent calls are no-ops. @utility |
Definition at line 145 of file logging.cpp.
| void entropic::log::log_content | ( | const std::shared_ptr< spdlog::logger > & | logger, |
| spdlog::level::level_enum | level, | ||
| const std::string & | label, | ||
| const std::string & | text | ||
| ) |
Log full content with escaping applied.
| logger | Target logger. |
| level | spdlog level. |
| label | Prefix label (e.g., "Content", "Input"). |
| text | Raw text — escaped before formatting. @utility |
| logger | Target logger. |
| level | spdlog level. |
| label | Prefix label. |
| text | Raw text — escaped before formatting. @utility |
Definition at line 431 of file logging.cpp.
| void entropic::log::log_decision | ( | const std::shared_ptr< spdlog::logger > & | logger, |
| const std::string & | label, | ||
| const std::string & | key, | ||
| const std::string & | value | ||
| ) |
Log a decision/routing event.
| logger | Target logger. |
| label | Decision category (e.g., "Route", "Grammar"). |
| key | Decision input. |
| value | Decision output. @utility |
| logger | Target logger. |
| label | Decision category. |
| key | Decision input. |
| value | Decision output. @utility |
Definition at line 484 of file logging.cpp.
| void entropic::log::log_timing | ( | const std::shared_ptr< spdlog::logger > & | logger, |
| const std::string & | label, | ||
| double | ms | ||
| ) |
Log a timing measurement.
| logger | Target logger. |
| label | Operation label. |
| ms | Elapsed milliseconds. @utility |
Definition at line 448 of file logging.cpp.
| void entropic::log::log_tokens | ( | const std::shared_ptr< spdlog::logger > & | logger, |
| int | count, | ||
| double | time_ms | ||
| ) |
Log token count with throughput.
| logger | Target logger. |
| count | Token count. |
| time_ms | Generation time in milliseconds. @utility |
Definition at line 464 of file logging.cpp.
|
inline |
| void entropic::log::register_handle_log | ( | int | handle_id, |
| const std::filesystem::path & | log_dir | ||
| ) |
gh#59 (v2.3.1): register a per-handle session.log file.
gh#59 public entry — see header.
Replaces the old global-mutation behavior of add_file_sink for the multi-handle case. Each handle registers its own log_dir under a unique handle_id. The process-wide HandleAwareSink consults the calling thread's current_handle_id (set via HandleLogScope) and writes only to that handle's file. No cross-handle bleed.
Idempotent: registering the same id twice replaces the old sink. Safe to call before or after init().
| handle_id | Monotonic handle identifier (engine_handle::log_id). |
| log_dir | Directory containing session.log + session_model.log. |
@utility
Definition at line 500 of file logging.cpp.
| void entropic::log::set_console_enabled | ( | bool | enabled | ) |
Enable or disable the stderr console sink process-wide.
Enable/disable the stderr console sink process-wide.
When disabled, the shared stderr sink (s_sink) is stripped from the default logger and every registered logger, and a process-global flag makes get() filter it out of any logger created afterwards. Engine output then routes to the per-handle file sink only.
TUI consumers that paint to fd 2 (stderr) MUST disable this — an engine log line on fd 2 corrupts the painted screen. Default state (console enabled) is unchanged for operator/CLI consumers.
| enabled | true to keep the console sink (default), false to remove it everywhere including future loggers. |
| enabled | false strips s_sink everywhere + flags get(). @utility |
Definition at line 243 of file logging.cpp.
| void entropic::log::setup_session | ( | const std::filesystem::path & | log_dir | ) |
Set up session logging for a project directory.
Adds a spdlog file sink for session.log and truncates session_model.log for a fresh session. Centralizes log file lifecycle that was previously inline in the facade.
| log_dir | Directory for session log files. |
Adds a file sink for session.log, removes the console sink so logs go to exactly one destination. Truncates session_model.log.
| log_dir | Directory for session log files. @utility |
Definition at line 305 of file logging.cpp.
| void entropic::log::unregister_handle_log | ( | int | handle_id | ) |
gh#59 (v2.3.1): release a handle's session.log file sink.
gh#59 public entry — see header.
Called from entropic_destroy. Closes the underlying file sink. Safe to call on unregistered ids.
| handle_id | Identifier previously passed to register_handle_log. |
@utility
Definition at line 530 of file logging.cpp.