5 releases (3 breaking)

0.4.0 Nov 18, 2024
0.3.0 Jun 1, 2023
0.2.0 Sep 21, 2022
0.1.1 Jul 1, 2020
0.1.0 Jan 20, 2018

#725 in Database interfaces

Download history 911/week @ 2025-01-05 711/week @ 2025-01-12 723/week @ 2025-01-19 729/week @ 2025-01-26 806/week @ 2025-02-02 549/week @ 2025-02-09 539/week @ 2025-02-16 750/week @ 2025-02-23 1239/week @ 2025-03-02 836/week @ 2025-03-09 678/week @ 2025-03-16 719/week @ 2025-03-23 959/week @ 2025-03-30 974/week @ 2025-04-06 729/week @ 2025-04-13 649/week @ 2025-04-20

3,381 downloads per month
Used in 2 crates

MIT license

12KB
222 lines

Diesel Logger

Let's say you use Diesel like this:

let conn = SqliteConnection::establish("example.sqlite").unwrap();
// some commands that read/write from the conn database

You can change this to

let conn = SqliteConnection::establish("example.sqlite").unwrap();
let conn = LoggingConnection::new(conn);
// some commands that read/write from the conn database

to log everything. This produces a debug log on every query, an info on queries that take longer than 1 second, and a warning on queries that take longer than 5 seconds.

Example

$ cd example
$ cargo run
2022-06-06T22:42:29.266Z DEBUG [diesel_logger] Query ran in 4.9 ms: CREATE TABLE IF NOT EXISTS posts (id INTEGER, title TEXT, body TEXT, published BOOL);
2022-06-06T22:42:29.270Z DEBUG [diesel_logger] Query ran in 3.7 ms: INSERT INTO `posts` (`title`, `body`) VALUES (?, ?) -- binds: ["mytitle", "mybody"]

Dependencies

~3–8MB
~75K SLoC