Skip to content

Feature/logger #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified metta-run/release/metta-run
Binary file not shown.
4 changes: 3 additions & 1 deletion metta-run/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod formatters;
mod runners;
mod tools;


fn main() -> io::Result<()> {
#[derive(Parser)]
#[command(name = "metta-run")]
Expand All @@ -26,7 +27,8 @@ fn main() -> io::Result<()> {

let start_time = tools::logger::start_timer();
let metta_output = runners::metta::run(file);
tools::logger::stop_timer(start_time, &metta_output)?;

let _ = tools::logger::stop_timer(start_time, &metta_output);

if let Some(command) = args.commands {
match command {
Expand Down
12 changes: 10 additions & 2 deletions metta-run/src/tools/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::env;
use std::fs::OpenOptions;
use std::io::Write;
use std::time::Instant;
use std::env::current_dir;

pub fn start_timer() -> Instant {
Instant::now()
Expand All @@ -12,8 +13,15 @@ pub fn stop_timer(start_time: Instant, metta_output: &String) -> Result<(), std:
let now = Local::now();
let formatted_date = now.format("%Y-%m-%d").to_string();

let metta_bin = format!("{}/metta-bin/", env::var("HOME").unwrap());
let log_file_name = format!("{}{}.log", metta_bin, formatted_date);

let file_path: Option<String> = match current_dir() {
Ok(path) => Some(path.to_string_lossy().into_owned()),
Err(error) => None
};
let log_file_name = match file_path {
Some(path) => format!("{}/{}.log", path, formatted_date),
None => todo!()
};

let end_time = Instant::now();
let elapsed_time = end_time.duration_since(start_time);
Expand Down
Loading