Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
session_logger.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
10
11static auto s_log = entropic::log::get("session");
12
13namespace entropic {
14
21SessionLogger::SessionLogger(const std::filesystem::path& log_dir) {
22 auto path = log_dir / "session_model.log";
23 fp_ = fopen(path.string().c_str(), "a");
24 if (!fp_) {
25 s_log->warn("cannot open model log: {}", path.string());
26 }
27}
28
35 if (fp_) { fclose(fp_); }
36}
37
44void SessionLogger::log_user_input(const std::string& input) {
45 if (!fp_) { return; }
46 fprintf(fp_, "--- USER ---\n%s\n--- ASSISTANT ---\n", input.c_str());
47 fflush(fp_);
48}
49
57void SessionLogger::log_raw_token(const char* token, size_t len) {
58 if (!fp_ || !token || len == 0) { return; }
59 fwrite(token, 1, len, fp_);
60 fflush(fp_);
61}
62
69 if (!fp_) { return; }
70 fprintf(fp_, "\n\n");
71 fflush(fp_);
72}
73
81 return fp_ != nullptr;
82}
83
93 const char* token, size_t len, void* user_data) {
94 static_cast<SessionLogger*>(user_data)->log_raw_token(token, len);
95}
96
97} // namespace entropic
Manages session_model.log for raw streaming content.
ENTROPIC_EXPORT ~SessionLogger()
Close the model log file.
ENTROPIC_EXPORT bool is_open() const
Check if the logger is open and writable.
ENTROPIC_EXPORT void log_user_input(const std::string &input)
Log user input at the start of a turn.
static void raw_token_callback(const char *token, size_t len, void *user_data)
Static callback for StreamThinkFilter raw output.
ENTROPIC_EXPORT void log_raw_token(const char *token, size_t len)
Log a raw token from streaming output.
ENTROPIC_EXPORT SessionLogger(const std::filesystem::path &log_dir)
Construct with log directory.
ENTROPIC_EXPORT void end_turn()
End the current assistant turn.
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Definition logging.cpp:211
Activate model on GPU (WARM → ACTIVE).
Session model log — raw streaming transcript.