Replies: 4 comments 10 replies
-
First of all I want to clearly state that while I'm interested in having such a discussion that won't be something that will be implemented in the near future (so at least not before the 2.0 release). As an intermediate solution: There are existing, crates that provide wrapping connection implementation for various logging solutions. That out of the way: I would be interested in hearing use cases. What exactly would you like to achieve with logging? What information would you like to see in your log? And how would you like to be able to configure that? Another important point while talking about potential designs is how this should interact with prepared statement caching and query building? For example logging the query itself every time it's executed would require us to rerun the query builder every time the query is logged. Currently we sometimes skip the query builder completely for cases where we already have a prepared statement and the mapping between query and statement could be known at compile time. |
Beta Was this translation helpful? Give feedback.
-
It likely won't work with the master branch as it is, as the master branch is a moving target and breaks stuff from time to time. If you need that kind of integration with other crates you should not use the master branch.
As at least I have currently quite limited maintenance capacity I do not want to upstream whole crates into diesel. I'm fine with adding stuff that cannot be done outside of diesel, but everything else needs to stay outside so that's maintained by someone else. Sorry for being that hard here, but I cannot maintain everything for everyone for free. |
Beta Was this translation helpful? Give feedback.
-
I had thoughts on how to provide a better solution for this problem, than having extern crates wrapping existing connection implementations. This post is a call for feedback. A potential implementation will not start before the finial 2.0 release, which means I mostly write this down now to remember it later on. First of all let me write down some basic assumptions of my idea:
Requiring to implement all of this as custom connection implementation, has a few potential problems:
Because of this it might be useful to expose a general interface from I believe something like the following interface might work: trait Connection {
fn instrument(&mut self, i: Box<dyn ConnectionInstrumentation<Self::Backend>>);
}
trait ConnectionInstrumentation<DB: Backend> {
fn on_action(&mut self, action: Action<'_>);
}
#[non_exhaustive]
enum Action<'a, DB: Backend> {
#[non_exhaustive]
QueryStart{
query: &'a dyn QueryFragment<DB>,
// other relevant information
},
#[non_exhaustive]
FetchedRow {
row: &'a dyn Row<DB>, // This might require some work on row to expose this information
// other relevant information
},
#[non_exhaustive]
QueryEnd {
query: &'a dyn QueryFragment<DB>,
result: Result<(), &Error>,
// other relevant information
},
#[non_exhaustive]
TransactionStart{},
#[non_exhaustive]
RollbackTransaction{reason: Result<&(), &Error>},
#[non_exhaustive]
CommitTransaction{},
} (Names up for discussion) Such an interface would allow us to add more information later on, while users could use the already exposed information. In additional I'm quite confident that such a interface could be implemented without imposing additional overhead on use cases that don't use this interface at all. |
Beta Was this translation helpful? Give feedback.
-
@weiznich Now that v2 has been released, will this be on your radar? Logging just the executed queries would be helpful for development 😄 Something along these lines would even be great to have without any additional logging features: let results = posts
.filter(published.eq(true))
.limit(5)
.output_raw_sql::<Post>(connection);
// select * from posts where published = 'true' limit 5; |
Beta Was this translation helpful? Give feedback.
-
Just wanted to restart the discussion on logging for development.
This is linked to issue #150
I think a few key points are:
Beta Was this translation helpful? Give feedback.
All reactions