diesel_logger

Crates.iodiesel_logger
lib.rsdiesel_logger
version0.4.0
sourcesrc
created_at2018-01-20 03:46:21.639311
updated_at2024-11-18 17:06:18.576323
descriptionTimes and logs queries executed by diesel
homepagehttps://github.com/shssoichiro/diesel-logger
repositoryhttps://github.com/shssoichiro/diesel-logger
max_upload_size
id47485
size13,329
Josh Holmer (shssoichiro)

documentation

README

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"]
Commit count: 14

cargo fmt