Remove tracing for release builds
This commit is contained in:
parent
65eeb32d37
commit
9ad213a676
23
src/main.rs
23
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
|
||||
@ -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<EventMessage>, Sender<CommandRequest>) {
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
#[instrument(skip(terminal, app))]
|
||||
#[cfg_attr(debug_assertions, instrument(skip(terminal, app)))]
|
||||
fn run_app<B: Backend>(terminal: &mut Terminal<B>, app: App) -> Result<Option<String>> {
|
||||
// When starting the app, ensure the command runs at least once
|
||||
{
|
||||
@ -313,12 +319,15 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, app: App) -> Result<Option<St
|
||||
}
|
||||
|
||||
loop {
|
||||
#[cfg(debug_assertions)]
|
||||
tracing::event!(Level::INFO, "Starting draw");
|
||||
terminal.draw(|f| ui::draw(f, &app))?;
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
tracing::event!(Level::INFO, "Waiting for event");
|
||||
match app.message_rx.recv()? {
|
||||
EventMessage::CrosstermEvent(crossterm_event) => {
|
||||
#[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<B: Backend>(terminal: &mut Terminal<B>, app: App) -> Result<Option<St
|
||||
}
|
||||
|
||||
EventMessage::CommandCompleted(command_completed) => {
|
||||
#[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<B: Backend>(terminal: &mut Terminal<B>, app: App) -> Result<Option<St
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
fn enable_tracing() {
|
||||
let file = File::create("debug.log").unwrap();
|
||||
let debug_log = tracing_subscriber::fmt::layer().with_writer(Arc::new(file));
|
||||
|
Loading…
Reference in New Issue
Block a user