Skip to content

How can I disable logging? #1056

Answered by Xide
jlkiri asked this question in Q&A
Feb 15, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hey !

Here is the implementation i am using to do this (with MySQL, but the same should be usable with other backends):

use sqlx::mysql::{MySqlPool, MySqlPoolOptions, MySqlConnectOptions};
use std::str::FromStr;
use std::time::Duration;
use sqlx::ConnectOptions;

pub async fn connect(url: &str) -> Result<(), sqlx::Error> {
        let mut connection_options = MySqlConnectOptions::from_str(url)?;
        connection_options
            .log_statements(log::LevelFilter::Debug)
            .log_slow_statements(log::LevelFilter::Warn, Duration::from_secs(1));
        let pool = MySqlPoolOptions::new()
            .connect_with(connection_options)
            .await?;
        Ok(())
}

Here is t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jlkiri
Comment options

Answer selected by jlkiri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants