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

#1329 in Database interfaces

Download history 589/week @ 2024-02-26 1074/week @ 2024-03-04 445/week @ 2024-03-11 305/week @ 2024-03-18 452/week @ 2024-03-25 393/week @ 2024-04-01 430/week @ 2024-04-08 434/week @ 2024-04-15 628/week @ 2024-04-22 730/week @ 2024-04-29 731/week @ 2024-05-06 546/week @ 2024-05-13 475/week @ 2024-05-20 663/week @ 2024-05-27 764/week @ 2024-06-03 626/week @ 2024-06-10

2,578 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

~3–8.5MB
~78K SLoC