pub struct AgentLogger { /* private fields */ }Expand description
The structured logger. One instance == one run == one JSONL file.
Thread-safe: the underlying file handle is guarded by a Mutex and the
sequence counter is atomic.
Implementations§
Source§impl AgentLogger
impl AgentLogger
Sourcepub fn new(
program: &str,
command: Option<&str>,
log_dir: impl AsRef<Path>,
rid: Option<&str>,
) -> Result<Self>
pub fn new( program: &str, command: Option<&str>, log_dir: impl AsRef<Path>, rid: Option<&str>, ) -> Result<Self>
Create a new logger (and its log file).
program– program name (filename component, sanitised).command– sub-command;None→pid{PID}.log_dir– directory for log files (./logsis typical).rid– run id override;None→ random 8 hex chars.
Examples found in repository?
examples/rust_emit.rs (line 5)
3fn main() {
4 let dir = std::env::args().nth(1).unwrap_or_else(|| "/tmp/xlang_rust".into());
5 let lg = AgentLogger::new("rust_probe", Some("demo"), &dir, Some("cafebabe")).unwrap();
6 lg.info_full("Processing started", Some("parser"), Some(12), None, None, Some(json!({"file":"data.json","size":1024}))).ok();
7 lg.tool_call("bash", "npm install", 0, 1234, None, None, Some("added 50 pkgs"), None, None).ok();
8 lg.error("Build failed", Some("build"), ErrorCode::ExecNonZero, Some("tb_abcd1234")).ok();
9 lg.file_op("write", "/p/f.rs", true, Some(2048), None, None, Some(5), None).ok();
10 lg.decision("use_redis", Some(&["redis","memcached"]), Some("perf"), Some(0.85), Some("arch"), None).ok();
11 lg.code_gen("rust", "src/main.rs", Some(50), Some(&["main","helper"]), None, None, None).ok();
12 lg.context_switch("test", Some("build"), Some("done"), None, None).ok();
13 println!("{}", lg.file_path().display());
14}Sourcepub fn new_compact(
program: &str,
command: Option<&str>,
log_dir: impl AsRef<Path>,
rid: Option<&str>,
compact: bool,
) -> Result<Self>
pub fn new_compact( program: &str, command: Option<&str>, log_dir: impl AsRef<Path>, rid: Option<&str>, compact: bool, ) -> Result<Self>
Like [new], but enables compact-key mode (contract §4).
Sourcepub fn file_path(&self) -> &Path
pub fn file_path(&self) -> &Path
Absolute path of the active log file.
Examples found in repository?
examples/rust_emit.rs (line 13)
3fn main() {
4 let dir = std::env::args().nth(1).unwrap_or_else(|| "/tmp/xlang_rust".into());
5 let lg = AgentLogger::new("rust_probe", Some("demo"), &dir, Some("cafebabe")).unwrap();
6 lg.info_full("Processing started", Some("parser"), Some(12), None, None, Some(json!({"file":"data.json","size":1024}))).ok();
7 lg.tool_call("bash", "npm install", 0, 1234, None, None, Some("added 50 pkgs"), None, None).ok();
8 lg.error("Build failed", Some("build"), ErrorCode::ExecNonZero, Some("tb_abcd1234")).ok();
9 lg.file_op("write", "/p/f.rs", true, Some(2048), None, None, Some(5), None).ok();
10 lg.decision("use_redis", Some(&["redis","memcached"]), Some("perf"), Some(0.85), Some("arch"), None).ok();
11 lg.code_gen("rust", "src/main.rs", Some(50), Some(&["main","helper"]), None, None, None).ok();
12 lg.context_switch("test", Some("build"), Some("done"), None, None).ok();
13 println!("{}", lg.file_path().display());
14}pub fn rid(&self) -> &str
pub fn program(&self) -> &str
pub fn command(&self) -> &str
Sourcepub fn save_traceback(
&self,
exc_type: &str,
exc_msg: &str,
traceback: &str,
) -> Result<String>
pub fn save_traceback( &self, exc_type: &str, exc_msg: &str, traceback: &str, ) -> Result<String>
Persist a traceback to the .tracebacks sidecar; returns the generated tid.
pub fn save_traceback_text( &self, tid: &str, exc_type: &str, exc_msg: &str, traceback: &str, ) -> Result<()>
Sourcepub fn info(&self, msg: &str, module: Option<&str>) -> Result<()>
pub fn info(&self, msg: &str, module: Option<&str>) -> Result<()>
logger.info(msg, module, dur?, error_code?, tid?, ctx?)
Sourcepub fn info_full(
&self,
msg: &str,
module: Option<&str>,
dur: Option<u64>,
error_code: Option<&str>,
tid: Option<&str>,
ctx: Option<Value>,
) -> Result<()>
pub fn info_full( &self, msg: &str, module: Option<&str>, dur: Option<u64>, error_code: Option<&str>, tid: Option<&str>, ctx: Option<Value>, ) -> Result<()>
Examples found in repository?
examples/rust_emit.rs (line 6)
3fn main() {
4 let dir = std::env::args().nth(1).unwrap_or_else(|| "/tmp/xlang_rust".into());
5 let lg = AgentLogger::new("rust_probe", Some("demo"), &dir, Some("cafebabe")).unwrap();
6 lg.info_full("Processing started", Some("parser"), Some(12), None, None, Some(json!({"file":"data.json","size":1024}))).ok();
7 lg.tool_call("bash", "npm install", 0, 1234, None, None, Some("added 50 pkgs"), None, None).ok();
8 lg.error("Build failed", Some("build"), ErrorCode::ExecNonZero, Some("tb_abcd1234")).ok();
9 lg.file_op("write", "/p/f.rs", true, Some(2048), None, None, Some(5), None).ok();
10 lg.decision("use_redis", Some(&["redis","memcached"]), Some("perf"), Some(0.85), Some("arch"), None).ok();
11 lg.code_gen("rust", "src/main.rs", Some(50), Some(&["main","helper"]), None, None, None).ok();
12 lg.context_switch("test", Some("build"), Some("done"), None, None).ok();
13 println!("{}", lg.file_path().display());
14}pub fn warn(&self, msg: &str, module: Option<&str>) -> Result<()>
pub fn warn_full( &self, msg: &str, module: Option<&str>, dur: Option<u64>, error_code: Option<&str>, tid: Option<&str>, ctx: Option<Value>, ) -> Result<()>
Sourcepub fn error(
&self,
msg: &str,
module: Option<&str>,
error_code: ErrorCode,
tid: Option<&str>,
) -> Result<()>
pub fn error( &self, msg: &str, module: Option<&str>, error_code: ErrorCode, tid: Option<&str>, ) -> Result<()>
Examples found in repository?
examples/rust_emit.rs (line 8)
3fn main() {
4 let dir = std::env::args().nth(1).unwrap_or_else(|| "/tmp/xlang_rust".into());
5 let lg = AgentLogger::new("rust_probe", Some("demo"), &dir, Some("cafebabe")).unwrap();
6 lg.info_full("Processing started", Some("parser"), Some(12), None, None, Some(json!({"file":"data.json","size":1024}))).ok();
7 lg.tool_call("bash", "npm install", 0, 1234, None, None, Some("added 50 pkgs"), None, None).ok();
8 lg.error("Build failed", Some("build"), ErrorCode::ExecNonZero, Some("tb_abcd1234")).ok();
9 lg.file_op("write", "/p/f.rs", true, Some(2048), None, None, Some(5), None).ok();
10 lg.decision("use_redis", Some(&["redis","memcached"]), Some("perf"), Some(0.85), Some("arch"), None).ok();
11 lg.code_gen("rust", "src/main.rs", Some(50), Some(&["main","helper"]), None, None, None).ok();
12 lg.context_switch("test", Some("build"), Some("done"), None, None).ok();
13 println!("{}", lg.file_path().display());
14}pub fn error_full( &self, msg: &str, module: Option<&str>, error_code: &str, tid: Option<&str>, dur: Option<u64>, ctx: Option<Value>, ) -> Result<()>
Sourcepub fn tool_call(
&self,
tool: &str,
cmd: &str,
exit: i64,
dur: u64,
error_code: Option<&str>,
tid: Option<&str>,
stdout: Option<&str>,
stderr: Option<&str>,
ctx: Option<Value>,
) -> Result<()>
pub fn tool_call( &self, tool: &str, cmd: &str, exit: i64, dur: u64, error_code: Option<&str>, tid: Option<&str>, stdout: Option<&str>, stderr: Option<&str>, ctx: Option<Value>, ) -> Result<()>
tool_call(tool, cmd, exit, dur, error_code?, tid?, stdout?, stderr?, ctx?).
Like Python, requires error_code semantics for failures are the caller’s
responsibility (this SDK accepts it optionally).
Examples found in repository?
examples/rust_emit.rs (line 7)
3fn main() {
4 let dir = std::env::args().nth(1).unwrap_or_else(|| "/tmp/xlang_rust".into());
5 let lg = AgentLogger::new("rust_probe", Some("demo"), &dir, Some("cafebabe")).unwrap();
6 lg.info_full("Processing started", Some("parser"), Some(12), None, None, Some(json!({"file":"data.json","size":1024}))).ok();
7 lg.tool_call("bash", "npm install", 0, 1234, None, None, Some("added 50 pkgs"), None, None).ok();
8 lg.error("Build failed", Some("build"), ErrorCode::ExecNonZero, Some("tb_abcd1234")).ok();
9 lg.file_op("write", "/p/f.rs", true, Some(2048), None, None, Some(5), None).ok();
10 lg.decision("use_redis", Some(&["redis","memcached"]), Some("perf"), Some(0.85), Some("arch"), None).ok();
11 lg.code_gen("rust", "src/main.rs", Some(50), Some(&["main","helper"]), None, None, None).ok();
12 lg.context_switch("test", Some("build"), Some("done"), None, None).ok();
13 println!("{}", lg.file_path().display());
14}Sourcepub fn file_op(
&self,
op: &str,
path: &str,
ok: bool,
size: Option<u64>,
error_code: Option<&str>,
tid: Option<&str>,
dur: Option<u64>,
ctx: Option<Value>,
) -> Result<()>
pub fn file_op( &self, op: &str, path: &str, ok: bool, size: Option<u64>, error_code: Option<&str>, tid: Option<&str>, dur: Option<u64>, ctx: Option<Value>, ) -> Result<()>
Examples found in repository?
examples/rust_emit.rs (line 9)
3fn main() {
4 let dir = std::env::args().nth(1).unwrap_or_else(|| "/tmp/xlang_rust".into());
5 let lg = AgentLogger::new("rust_probe", Some("demo"), &dir, Some("cafebabe")).unwrap();
6 lg.info_full("Processing started", Some("parser"), Some(12), None, None, Some(json!({"file":"data.json","size":1024}))).ok();
7 lg.tool_call("bash", "npm install", 0, 1234, None, None, Some("added 50 pkgs"), None, None).ok();
8 lg.error("Build failed", Some("build"), ErrorCode::ExecNonZero, Some("tb_abcd1234")).ok();
9 lg.file_op("write", "/p/f.rs", true, Some(2048), None, None, Some(5), None).ok();
10 lg.decision("use_redis", Some(&["redis","memcached"]), Some("perf"), Some(0.85), Some("arch"), None).ok();
11 lg.code_gen("rust", "src/main.rs", Some(50), Some(&["main","helper"]), None, None, None).ok();
12 lg.context_switch("test", Some("build"), Some("done"), None, None).ok();
13 println!("{}", lg.file_path().display());
14}Sourcepub fn decision(
&self,
choice: &str,
alts: Option<&[&str]>,
reason: Option<&str>,
confidence: Option<f64>,
module: Option<&str>,
ctx: Option<Value>,
) -> Result<()>
pub fn decision( &self, choice: &str, alts: Option<&[&str]>, reason: Option<&str>, confidence: Option<f64>, module: Option<&str>, ctx: Option<Value>, ) -> Result<()>
Examples found in repository?
examples/rust_emit.rs (line 10)
3fn main() {
4 let dir = std::env::args().nth(1).unwrap_or_else(|| "/tmp/xlang_rust".into());
5 let lg = AgentLogger::new("rust_probe", Some("demo"), &dir, Some("cafebabe")).unwrap();
6 lg.info_full("Processing started", Some("parser"), Some(12), None, None, Some(json!({"file":"data.json","size":1024}))).ok();
7 lg.tool_call("bash", "npm install", 0, 1234, None, None, Some("added 50 pkgs"), None, None).ok();
8 lg.error("Build failed", Some("build"), ErrorCode::ExecNonZero, Some("tb_abcd1234")).ok();
9 lg.file_op("write", "/p/f.rs", true, Some(2048), None, None, Some(5), None).ok();
10 lg.decision("use_redis", Some(&["redis","memcached"]), Some("perf"), Some(0.85), Some("arch"), None).ok();
11 lg.code_gen("rust", "src/main.rs", Some(50), Some(&["main","helper"]), None, None, None).ok();
12 lg.context_switch("test", Some("build"), Some("done"), None, None).ok();
13 println!("{}", lg.file_path().display());
14}Sourcepub fn code_gen(
&self,
lang: &str,
path: &str,
lines: Option<u64>,
funcs: Option<&[&str]>,
imports: Option<&[&str]>,
module: Option<&str>,
ctx: Option<Value>,
) -> Result<()>
pub fn code_gen( &self, lang: &str, path: &str, lines: Option<u64>, funcs: Option<&[&str]>, imports: Option<&[&str]>, module: Option<&str>, ctx: Option<Value>, ) -> Result<()>
Examples found in repository?
examples/rust_emit.rs (line 11)
3fn main() {
4 let dir = std::env::args().nth(1).unwrap_or_else(|| "/tmp/xlang_rust".into());
5 let lg = AgentLogger::new("rust_probe", Some("demo"), &dir, Some("cafebabe")).unwrap();
6 lg.info_full("Processing started", Some("parser"), Some(12), None, None, Some(json!({"file":"data.json","size":1024}))).ok();
7 lg.tool_call("bash", "npm install", 0, 1234, None, None, Some("added 50 pkgs"), None, None).ok();
8 lg.error("Build failed", Some("build"), ErrorCode::ExecNonZero, Some("tb_abcd1234")).ok();
9 lg.file_op("write", "/p/f.rs", true, Some(2048), None, None, Some(5), None).ok();
10 lg.decision("use_redis", Some(&["redis","memcached"]), Some("perf"), Some(0.85), Some("arch"), None).ok();
11 lg.code_gen("rust", "src/main.rs", Some(50), Some(&["main","helper"]), None, None, None).ok();
12 lg.context_switch("test", Some("build"), Some("done"), None, None).ok();
13 println!("{}", lg.file_path().display());
14}Sourcepub fn context_switch(
&self,
to_task: &str,
from_task: Option<&str>,
reason: Option<&str>,
module: Option<&str>,
ctx: Option<Value>,
) -> Result<()>
pub fn context_switch( &self, to_task: &str, from_task: Option<&str>, reason: Option<&str>, module: Option<&str>, ctx: Option<Value>, ) -> Result<()>
Examples found in repository?
examples/rust_emit.rs (line 12)
3fn main() {
4 let dir = std::env::args().nth(1).unwrap_or_else(|| "/tmp/xlang_rust".into());
5 let lg = AgentLogger::new("rust_probe", Some("demo"), &dir, Some("cafebabe")).unwrap();
6 lg.info_full("Processing started", Some("parser"), Some(12), None, None, Some(json!({"file":"data.json","size":1024}))).ok();
7 lg.tool_call("bash", "npm install", 0, 1234, None, None, Some("added 50 pkgs"), None, None).ok();
8 lg.error("Build failed", Some("build"), ErrorCode::ExecNonZero, Some("tb_abcd1234")).ok();
9 lg.file_op("write", "/p/f.rs", true, Some(2048), None, None, Some(5), None).ok();
10 lg.decision("use_redis", Some(&["redis","memcached"]), Some("perf"), Some(0.85), Some("arch"), None).ok();
11 lg.code_gen("rust", "src/main.rs", Some(50), Some(&["main","helper"]), None, None, None).ok();
12 lg.context_switch("test", Some("build"), Some("done"), None, None).ok();
13 println!("{}", lg.file_path().display());
14}Auto Trait Implementations§
impl !Freeze for AgentLogger
impl RefUnwindSafe for AgentLogger
impl Send for AgentLogger
impl Sync for AgentLogger
impl Unpin for AgentLogger
impl UnsafeUnpin for AgentLogger
impl UnwindSafe for AgentLogger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more