From 26a17d9614e804783b527577692cad03cdb5c155 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 16 Sep 2021 18:32:45 +0800 Subject: [PATCH] Debug log docs (SeaQL/sea-orm#114) --- SeaORM/docs/01-index.md | 2 ++ .../02-install-and-config/04-debug-log.md | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 SeaORM/docs/02-install-and-config/04-debug-log.md diff --git a/SeaORM/docs/01-index.md b/SeaORM/docs/01-index.md index c62a2f58ef0..8a6ca5c7c6b 100644 --- a/SeaORM/docs/01-index.md +++ b/SeaORM/docs/01-index.md @@ -18,6 +18,8 @@ 1.3 [Connection Pool](/docs/install-and-config/connection) + 1.4 [Debug Log](/docs/install-and-config/debug-log) + 2. Generating Entities 2.1 [Using `sea-orm-cli`](/docs/generate-entity/sea-orm-cli) diff --git a/SeaORM/docs/02-install-and-config/04-debug-log.md b/SeaORM/docs/02-install-and-config/04-debug-log.md new file mode 100644 index 00000000000..55177a8cc44 --- /dev/null +++ b/SeaORM/docs/02-install-and-config/04-debug-log.md @@ -0,0 +1,20 @@ +# Debug Log + +The SeaORM and the underlying database driver [`SQLx`](https://crates.io/crates/sqlx) both log debug messages via [`log`](https://crates.io/crates/log) crate. + +You need to choose one of the [logging implementations](https://docs.rs/log/0.4.14/log/#available-logging-implementations) to capture and view the debug log. We recommand using [`env_logger`](https://crates.io/crates/env_logger), you can see the snippet below and a complete example [here](https://github.com/SeaQL/sea-orm/blob/master/examples/tokio/src/main.rs). + +```rust +pub async fn main() { + env_logger::builder() + .filter_level(log::LevelFilter::Debug) + .is_test(true) + .init(); + + let db = Database::connect("mysql://sea:sea@localhost/bakery") + .await + .unwrap(); + + cake::Entity::find().one(&db).await.unwrap(); +} +```