From 9ad213a67676be450707c258a202dbc28da30f9b Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Thu, 22 Dec 2022 23:59:15 -0500 Subject: [PATCH] Remove tracing for release builds --- src/main.rs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index f18e764..d78bc03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,16 +19,11 @@ use crossterm::event::EnableBracketedPaste; use event::EventMessage; use parking_lot::RwLock; use ropey::Rope; -use std::fs::File; use std::str::FromStr; use std::{ io::{self, Write}, sync::Arc, }; -use tracing::instrument; -use tracing::Level; -use tracing_subscriber::Layer; -use tracing_subscriber::{filter, prelude::*}; use tui::{ backend::{Backend, CrosstermBackend}, Terminal, @@ -41,6 +36,16 @@ use crossterm::{ terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, }; +#[cfg(debug_assertions)] +use { + // Tracing + std::fs::File, + tracing::instrument, + tracing::Level, + tracing_subscriber::Layer, + tracing_subscriber::{filter, prelude::*}, +}; + /// The state of options for the command pub struct CommandOptions { /// The actual command to be called @@ -160,11 +165,11 @@ impl App { } } -/// Run a command by sending a command request to the inner channel -/// -/// # Errors -/// -/// When the channel closes and the send fails + /// Run a command by sending a command request to the inner channel + /// + /// # Errors + /// + /// When the channel closes and the send fails pub fn run_command(&self) -> Result<()> { self.command_request_tx .send((self.command_options.clone(), self.text_orig.clone()))?; @@ -214,6 +219,7 @@ impl Template { } fn main() -> Result<()> { + #[cfg(debug_assertions)] enable_tracing(); // Error if we aren't getting any stdin @@ -297,7 +303,7 @@ fn init_message_passing() -> (Receiver, Sender) { } #[allow(clippy::too_many_lines)] -#[instrument(skip(terminal, app))] +#[cfg_attr(debug_assertions, instrument(skip(terminal, app)))] fn run_app(terminal: &mut Terminal, app: App) -> Result> { // When starting the app, ensure the command runs at least once { @@ -313,12 +319,15 @@ fn run_app(terminal: &mut Terminal, app: App) -> Result { + #[cfg(debug_assertions)] tracing::event!(Level::INFO, "Got crossterm event"); let mut command_options = app.command_options.write(); @@ -404,6 +413,7 @@ fn run_app(terminal: &mut Terminal, app: App) -> Result { + #[cfg(debug_assertions)] tracing::event!(Level::INFO, "Got command completed event event"); let mut command_options = app.command_options.write(); match command_completed { @@ -435,6 +445,7 @@ fn run_app(terminal: &mut Terminal, app: App) -> Result