Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the Logger type to log data to the terminal
cargo has some fancy ways to print out things to the terminal and show status. Eventually we'll get there as we add more things like dependencies etc. However, we have to start somewhere with outputting things in a way that's not just println!. This commit starts that process by creating a Logger type that will print out what it's compiling and when it's done!
- Loading branch information
Showing
2 changed files
with
40 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use std::io; | ||
use std::io::Write; | ||
|
||
pub struct Logger { | ||
out: io::StdoutLock<'static>, | ||
} | ||
|
||
impl Logger { | ||
pub fn new() -> Self { | ||
Self { | ||
out: io::stdout().lock(), | ||
} | ||
} | ||
pub fn compiling_crate(&mut self, crate_name: &str) { | ||
let _ = self | ||
.out | ||
.write_all(format!("Compiling crate {crate_name}...").as_bytes()); | ||
} | ||
pub fn compiling_bin(&mut self, crate_name: &str) { | ||
let _ = self | ||
.out | ||
.write_all(format!("Compiling bin {crate_name}...").as_bytes()); | ||
} | ||
pub fn done_compiling(&mut self) { | ||
let _ = self.out.write_all(b"Done\n"); | ||
} | ||
} |