logging code rust
// import `default_code` from `log_file` lib
use log_file::default_code::*;
fn main() {
// create new log
let mut log = Log::new(false, String::from(":"));
// use log to log your code
let a = 2_f64;
log.add_variable("main", "a", "2");
let b = 3_f64;
log.add_variable("main", "b", "3");
log.add_function_call("main", "pythagorean_theorem", "a, b");
let c = pythagorean_theorem(a,b);
log.add_variable("main", "c", "pythagorean_theorem(a, b)");
// save log to `log.txt`
log.save("log.txt");
}
fn pythagorean_theorem(log : &mut log, a : f64, b : f64) -> f64 {
let a_sq = a*a;
let b_sq = b*b;
let c = (a_sq + b_sq).sqrt();
let s = c.to_string();
log.add_return_statement("pythagorean_theorem", &s[..]);
return c;
}
/* Content of log.txt:
main() : a = 2
main() : b = 3
main() : call pythagorean_theorem(a, b)
pythagorean_theorem() : return 3.605551275463989
main() : c = pythagorean_theorem(a,b)
*/