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 event::EventMessage;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use ropey::Rope;
|
use ropey::Rope;
|
||||||
use std::fs::File;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::{
|
use std::{
|
||||||
io::{self, Write},
|
io::{self, Write},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use tracing::instrument;
|
|
||||||
use tracing::Level;
|
|
||||||
use tracing_subscriber::Layer;
|
|
||||||
use tracing_subscriber::{filter, prelude::*};
|
|
||||||
use tui::{
|
use tui::{
|
||||||
backend::{Backend, CrosstermBackend},
|
backend::{Backend, CrosstermBackend},
|
||||||
Terminal,
|
Terminal,
|
||||||
@ -41,6 +36,16 @@ use crossterm::{
|
|||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
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
|
/// The state of options for the command
|
||||||
pub struct CommandOptions {
|
pub struct CommandOptions {
|
||||||
/// The actual command to be called
|
/// The actual command to be called
|
||||||
@ -214,6 +219,7 @@ impl Template {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
enable_tracing();
|
enable_tracing();
|
||||||
|
|
||||||
// Error if we aren't getting any stdin
|
// 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)]
|
#[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>> {
|
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
|
// 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 {
|
loop {
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
tracing::event!(Level::INFO, "Starting draw");
|
tracing::event!(Level::INFO, "Starting draw");
|
||||||
terminal.draw(|f| ui::draw(f, &app))?;
|
terminal.draw(|f| ui::draw(f, &app))?;
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
tracing::event!(Level::INFO, "Waiting for event");
|
tracing::event!(Level::INFO, "Waiting for event");
|
||||||
match app.message_rx.recv()? {
|
match app.message_rx.recv()? {
|
||||||
EventMessage::CrosstermEvent(crossterm_event) => {
|
EventMessage::CrosstermEvent(crossterm_event) => {
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
tracing::event!(Level::INFO, "Got crossterm event");
|
tracing::event!(Level::INFO, "Got crossterm event");
|
||||||
let mut command_options = app.command_options.write();
|
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) => {
|
EventMessage::CommandCompleted(command_completed) => {
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
tracing::event!(Level::INFO, "Got command completed event event");
|
tracing::event!(Level::INFO, "Got command completed event event");
|
||||||
let mut command_options = app.command_options.write();
|
let mut command_options = app.command_options.write();
|
||||||
match command_completed {
|
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() {
|
fn enable_tracing() {
|
||||||
let file = File::create("debug.log").unwrap();
|
let file = File::create("debug.log").unwrap();
|
||||||
let debug_log = tracing_subscriber::fmt::layer().with_writer(Arc::new(file));
|
let debug_log = tracing_subscriber::fmt::layer().with_writer(Arc::new(file));
|
||||||
|
Loading…
Reference in New Issue
Block a user