From 5b6e06928bbd5466d0c65149e8c7e44871e71a8c Mon Sep 17 00:00:00 2001 From: Sakarias Johansson Date: Tue, 21 Mar 2023 23:09:15 +0100 Subject: =?UTF-8?q?=F0=9F=93=96=20Add=20logging=20and=20term=20writes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit println works for a while. Was time to set up something better. Worth to not that there is a big difference between logging and writing to the terminal which is why both slog and console was dragged in. Might seem similar but purpose is not the same. Most of the time the log is interesting during runtime but user messages does not belong in the log. --- racer-tracer/src/terminal.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 racer-tracer/src/terminal.rs (limited to 'racer-tracer/src/terminal.rs') diff --git a/racer-tracer/src/terminal.rs b/racer-tracer/src/terminal.rs new file mode 100644 index 0000000..48eb599 --- /dev/null +++ b/racer-tracer/src/terminal.rs @@ -0,0 +1,26 @@ +use console::Term; +use slog::Logger; + +pub struct Terminal { + pub logger: Logger, + pub terminal: Term, +} + +impl Terminal { + pub fn new(logger: Logger) -> Self { + Self { + logger, + terminal: Term::stdout(), + } + } +} + +macro_rules! write_term { + ($term:expr, $text:expr) => {{ + if let Err(e) = $term.terminal.write_line($text) { + debug!($term.logger, "Failed to write to terminal: {}", e) + } + }}; +} + +pub(crate) use write_term; -- cgit v1.2.3