File tree Expand file tree Collapse file tree 4 files changed +39
-1
lines changed Expand file tree Collapse file tree 4 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -6,4 +6,5 @@ edition = "2021"
6
6
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
7
8
8
[dependencies ]
9
+ chrono = " 0.4.38"
9
10
clap = { version = " 4.5.13" , features = [" derive" ] }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ use formatters::commands::{format, FormatterCommands};
3
3
use std:: io;
4
4
mod formatters;
5
5
mod runners;
6
+ mod tools;
6
7
7
8
fn main ( ) -> io:: Result < ( ) > {
8
9
#[ derive( Parser ) ]
@@ -22,7 +23,10 @@ fn main() -> io::Result<()> {
22
23
23
24
let args = Args :: parse ( ) ;
24
25
let file = args. file ;
26
+
27
+ let start_time = tools:: logger:: start_timer ( ) ;
25
28
let metta_output = runners:: metta:: run ( file) ;
29
+ tools:: logger:: stop_timer ( start_time, & metta_output) ?;
26
30
27
31
if let Some ( command) = args. commands {
28
32
match command {
@@ -31,6 +35,5 @@ fn main() -> io::Result<()> {
31
35
} else {
32
36
println ! ( "{}" , metta_output) ;
33
37
}
34
-
35
38
Ok ( ( ) )
36
39
}
Original file line number Diff line number Diff line change
1
+ use chrono:: Local ;
2
+ use std:: fs:: OpenOptions ;
3
+ use std:: io:: Write ;
4
+ use std:: time:: { Duration , Instant } ;
5
+
6
+ pub fn start_timer ( ) -> Instant {
7
+ Instant :: now ( )
8
+ }
9
+
10
+ pub fn stop_timer ( start_time : Instant , metta_output : & String ) -> Result < ( ) , std:: io:: Error > {
11
+ let now = Local :: now ( ) ;
12
+ let formatted_date = now. format ( "%Y-%m-%d" ) . to_string ( ) ;
13
+
14
+ let log_file_name = format ! ( "{}.log" , formatted_date) ;
15
+
16
+ let end_time = Instant :: now ( ) ;
17
+ let elapsed_time = end_time. duration_since ( start_time) ;
18
+ let final_output = format ! (
19
+ "\n Start time: {}\n Elapsed time: {:.3}\n {}\n " ,
20
+ now. format( "%Y-%m-%d %H-%m-%s" ) . to_string( ) ,
21
+ elapsed_time. as_secs_f32( ) ,
22
+ metta_output
23
+ ) ;
24
+
25
+ let mut output_file = OpenOptions :: new ( )
26
+ . append ( true )
27
+ . create ( true )
28
+ . open ( & log_file_name) ?;
29
+
30
+ output_file. write_all ( final_output. as_bytes ( ) ) ?;
31
+
32
+ Ok ( ( ) )
33
+ }
Original file line number Diff line number Diff line change
1
+ pub mod logger;
You can’t perform that action at this time.
0 commit comments