-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to disable query logging programmatically #939
Add a way to disable query logging programmatically #939
Conversation
If you don't have logging enabled then we shouldn't be generating the logs anyway. I think the real fix is to change this check here to IMO, we should also drop the default level here to |
Technically I do have the logging enabled, since tracing supports I have it + my RA_LOG set to info, all this combined makes sqlx think that it should log some statements, I believe. I will check more later, but not sure I have to adjust that place you've pointed to. |
Changing the default logging level to |
This is an incorrect statement, here's the code in question that I want to turn off: Lines 34 to 35 in 9d71a7f
First, it gets the log level (
It could be redundant, if the query logging would have been disabled by default. |
We can take a step back and discuss the issue more, if you don't like the method so much that you're eager to call it redundant. My original issue, rephrased: I use How can I do that?
Any other thoughts? |
I think I understand where you're coming from here. fn disable_statement_logging(&mut self) -> &mut Self {
self.log_statements(LevelFilter::Off)
.log_slow_statements(LevelFilter::Off, Duration::default())
} You want this so you don't need to have I think a nice compromise for now is to re-export To be honest, I'm not super happy with the logging configuration as it stands. We only have what we have to have something.
Just checked the issue. Would a solution where we only log the query summary (avoiding sqlformat in the normal path) and execution time at |
It's not worth arguing over a 3 line addition. I prefer this new method over debating about an appropriate place to reexport |
Thank you for your time on this and sorry if I had spent too much of your time on this. Since you were curious anyway, one more big reason to turn off the query logging (besides the nasty perf issues) is the fact that they are printed multiline and HUGE:
Note that there's no metadata to the left of the So IMO the log printing feature brings lots of pain for real production with somewhat serious batch queries (1000 rows inserted at once is not that big IMO).
That might work, sure, "SQL echo off by default" is something I've expected to have with the current issues this feature has. |
@SomeoneToIgnore typed up some thoughts in #942 if you'd like to weigh in |
I'd like to disable the query logging entirely due to #633 and a few other reasons.
Currently, it looks like I can do this two ways:
RUST_LOG
env variable or add more configuration into the logger directly: a fragile indirect way, since can be spoiled too easy and not verifiable by the compilerConnectOptions
-like trait for my db and pass theLevelFilter::Off
there, which is good except for the fact that I usetracing
instead oflog
and I need to drag in another dependency just to disable the logging.This PR adds another method to
ConnectOptions
that allows disabling the logs without requiring somebody to uselog
crate for that.