d291dcdc74
agent_api (HTTP server), agent_log (structured logging), agent_events (event bus), agent_console (GameConsole), agent_replay (snapshots), agent_vision (depth/segmentation), agent_fbx (bone remapping), agent_auth (multi-agent), agent_analytics (feature flags + tracking) All modules compile clean with mono. Binary uploaded to S3 v1.0.0. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
92 lines
2.9 KiB
C++
92 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include "core/object/class_db.h"
|
|
#include "core/object/object.h"
|
|
#include "core/os/mutex.h"
|
|
#include "core/string/ustring.h"
|
|
#include "core/variant/dictionary.h"
|
|
#include "core/variant/array.h"
|
|
#include "core/io/file_access.h"
|
|
|
|
class AgentLog : public Object {
|
|
GDCLASS(AgentLog, Object);
|
|
|
|
static AgentLog *singleton;
|
|
|
|
public:
|
|
static AgentLog *get_singleton() { return singleton; }
|
|
|
|
enum Level {
|
|
LEVEL_TRACE = 0,
|
|
LEVEL_DEBUG = 1,
|
|
LEVEL_INFO = 2,
|
|
LEVEL_WARN = 3,
|
|
LEVEL_ERROR = 4,
|
|
LEVEL_FATAL = 5,
|
|
};
|
|
|
|
struct LogEntry {
|
|
uint64_t timestamp_msec = 0;
|
|
Level level = LEVEL_INFO;
|
|
String category;
|
|
String message;
|
|
Dictionary data;
|
|
uint64_t id = 0;
|
|
};
|
|
|
|
private:
|
|
static constexpr int RING_BUFFER_SIZE = 10000;
|
|
LogEntry ring_buffer[RING_BUFFER_SIZE];
|
|
int write_pos = 0;
|
|
int entry_count = 0;
|
|
uint64_t next_id = 1;
|
|
Mutex buffer_mutex;
|
|
|
|
Level min_level = LEVEL_INFO;
|
|
bool file_sink_enabled = false;
|
|
String file_sink_path;
|
|
Ref<FileAccess> file_sink;
|
|
|
|
// Hook into Godot's error/print system.
|
|
static void _error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, bool p_editor_notify, ErrorHandlerType p_type);
|
|
static void _print_handler(void *p_self, const String &p_string, bool p_error, bool p_rich);
|
|
|
|
ErrorHandlerList error_handler;
|
|
PrintHandlerList print_handler;
|
|
|
|
void _write_entry(const LogEntry &p_entry);
|
|
void _write_to_file(const LogEntry &p_entry);
|
|
static String _level_string(Level p_level);
|
|
static Dictionary _entry_to_dict(const LogEntry &p_entry);
|
|
|
|
protected:
|
|
static void _bind_methods();
|
|
|
|
public:
|
|
AgentLog();
|
|
~AgentLog();
|
|
|
|
// Logging API — callable from GDScript/C#.
|
|
void log_trace(const String &p_category, const String &p_message, const Dictionary &p_data = Dictionary());
|
|
void log_debug(const String &p_category, const String &p_message, const Dictionary &p_data = Dictionary());
|
|
void log_info(const String &p_category, const String &p_message, const Dictionary &p_data = Dictionary());
|
|
void log_warn(const String &p_category, const String &p_message, const Dictionary &p_data = Dictionary());
|
|
void log_error(const String &p_category, const String &p_message, const Dictionary &p_data = Dictionary());
|
|
void log_fatal(const String &p_category, const String &p_message, const Dictionary &p_data = Dictionary());
|
|
void log_message(Level p_level, const String &p_category, const String &p_message, const Dictionary &p_data = Dictionary());
|
|
|
|
// Query API.
|
|
Array get_entries(int p_count = 100, Level p_min_level = LEVEL_TRACE, const String &p_category = "", uint64_t p_since_msec = 0);
|
|
int get_entry_count() const { return entry_count; }
|
|
|
|
// Configuration.
|
|
void set_min_level(Level p_level) { min_level = p_level; }
|
|
Level get_min_level() const { return min_level; }
|
|
void enable_file_sink(const String &p_path);
|
|
void disable_file_sink();
|
|
|
|
void clear();
|
|
};
|
|
|
|
VARIANT_ENUM_CAST(AgentLog::Level);
|