blackbeam / mysql_async

Asyncronous Rust Mysql driver based on Tokio.
Apache License 2.0
376 stars 114 forks source link

mysql async print sql logs ? #222

Open qqliaoxin opened 1 year ago

qqliaoxin commented 1 year ago

How does mysql async print sql logs

blackbeam commented 1 year ago

Could you please elaborate more on that? What do you mean by "print sql logs"?

qqliaoxin commented 1 year ago

mysql async can output Sql from the console

cloneable commented 1 year ago

If you want to print all SQL to stdout you can now use the tracing feature and the FmtSubscriber from https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/index.html to log queries. Make sure tracing level DEBUG is enabled.

i18nsite commented 7 months ago

I add tracing , but not display sql

i use export RUST_LOG=debug

  use atty::Stream;
  use tracing_subscriber::{fmt::format::Writer, layer::SubscriberExt, EnvFilter};

  pub struct NoTime;
  impl tracing_subscriber::fmt::time::FormatTime for NoTime {
    fn format_time(&self, _writer: &mut Writer<'_>) -> std::fmt::Result {
      Ok(())
    }
  }

  pub fn init() {
    let env_filter = EnvFilter::from_default_env();

      use tracing_subscriber::util::SubscriberInitExt;
      let fmt = tracing_subscriber::fmt::layer()
        .with_timer(NoTime)
        .with_ansi(atty::is(Stream::Stdout));
      tracing_subscriber::registry()
        .with(fmt)
        .with(env_filter)
        .init();
  }
image