4 releases (2 breaking)

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

#1284 in Database interfaces

Download history 538/week @ 2024-01-02 585/week @ 2024-01-09 278/week @ 2024-01-16 365/week @ 2024-01-23 404/week @ 2024-01-30 443/week @ 2024-02-06 973/week @ 2024-02-13 404/week @ 2024-02-20 589/week @ 2024-02-27 1118/week @ 2024-03-05 351/week @ 2024-03-12 346/week @ 2024-03-19 463/week @ 2024-03-26 393/week @ 2024-04-02 418/week @ 2024-04-09 398/week @ 2024-04-16

1,744 downloads per month
Used in 2 crates

MIT license

9KB
199 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

~2.5–8MB
~64K SLoC