diff --git a/lib/src/dbs/executor.rs b/lib/src/dbs/executor.rs index c171a4ee..89fdf75f 100644 --- a/lib/src/dbs/executor.rs +++ b/lib/src/dbs/executor.rs @@ -4,6 +4,7 @@ use crate::dbs::Auth; use crate::dbs::Level; use crate::dbs::Options; use crate::dbs::Transaction; +use crate::dbs::LOG; use crate::err::Error; use crate::kvs::Datastore; use crate::sql::query::Query; @@ -127,7 +128,7 @@ impl<'a> Executor<'a> { // Process all statements in query for stm in qry.iter() { // Log the statement - debug!("Executing: {}", stm); + debug!(target: LOG, "Executing: {}", stm); // Reset errors if self.txn.is_none() { self.err = false; diff --git a/lib/src/dbs/iterator.rs b/lib/src/dbs/iterator.rs index c35b5b30..75c7f94b 100644 --- a/lib/src/dbs/iterator.rs +++ b/lib/src/dbs/iterator.rs @@ -3,6 +3,7 @@ use crate::ctx::Context; use crate::dbs::Options; use crate::dbs::Statement; use crate::dbs::Transaction; +use crate::dbs::LOG; use crate::doc::Document; use crate::err::Error; use crate::sql::array::Array; @@ -70,7 +71,7 @@ impl Iterator { stm: &Statement<'_>, ) -> Result { // Log the statement - trace!("Iterating: {}", stm); + trace!(target: LOG, "Iterating: {}", stm); // Enable context override let mut ctx = Context::new(ctx); self.run = ctx.add_cancel(); diff --git a/lib/src/dbs/mod.rs b/lib/src/dbs/mod.rs index 8f94231c..8e789745 100644 --- a/lib/src/dbs/mod.rs +++ b/lib/src/dbs/mod.rs @@ -27,3 +27,5 @@ pub use self::channel::*; #[cfg(test)] pub(crate) mod test; + +pub const LOG: &str = "surrealdb::dbs"; diff --git a/lib/src/kvs/ds.rs b/lib/src/kvs/ds.rs index 04a59a72..9cea3d62 100644 --- a/lib/src/kvs/ds.rs +++ b/lib/src/kvs/ds.rs @@ -7,6 +7,7 @@ use crate::dbs::Response; use crate::dbs::Session; use crate::dbs::Variables; use crate::err::Error; +use crate::kvs::LOG; use crate::sql; use crate::sql::Query; use crate::sql::Value; @@ -73,37 +74,45 @@ impl Datastore { match path { #[cfg(feature = "kv-echodb")] "memory" => { - info!("Starting kvs store in {}", path); - super::mem::Datastore::new().await.map(|v| Datastore { + info!(target: LOG, "Starting kvs store in {}", path); + let v = super::mem::Datastore::new().await.map(|v| Datastore { inner: Inner::Mem(v), - }) + }); + info!(target: LOG, "Started kvs store in {}", path); + v } // Parse and initiate an IxDB database #[cfg(feature = "kv-indxdb")] s if s.starts_with("ixdb:") => { - info!("Starting kvs store at {}", path); + info!(target: LOG, "Starting kvs store at {}", path); let s = s.trim_start_matches("ixdb://"); - super::ixdb::Datastore::new(s).await.map(|v| Datastore { + let v = super::ixdb::Datastore::new(s).await.map(|v| Datastore { inner: Inner::IxDB(v), - }) + }); + info!(target: LOG, "Started kvs store at {}", path); + v } // Parse and initiate an File database #[cfg(feature = "kv-yokudb")] s if s.starts_with("file:") => { - info!("Starting kvs store at {}", path); + info!(target: LOG, "Starting kvs store at {}", path); let s = s.trim_start_matches("file://"); - super::file::Datastore::new(s).await.map(|v| Datastore { + let v = super::file::Datastore::new(s).await.map(|v| Datastore { inner: Inner::File(v), - }) + }); + info!(target: LOG, "Started kvs store at {}", path); + v } // Parse and initiate an TiKV database #[cfg(feature = "kv-tikv")] s if s.starts_with("tikv:") => { - info!("Starting kvs store at {}", path); + info!(target: LOG, "Connecting to kvs store at {}", path); let s = s.trim_start_matches("tikv://"); - super::tikv::Datastore::new(s).await.map(|v| Datastore { + let v = super::tikv::Datastore::new(s).await.map(|v| Datastore { inner: Inner::TiKV(v), - }) + }); + info!(target: LOG, "Connected to kvs store at {}", path); + v } // The datastore path is not valid _ => unreachable!(), diff --git a/lib/src/kvs/mod.rs b/lib/src/kvs/mod.rs index 77e2957d..dfaca316 100644 --- a/lib/src/kvs/mod.rs +++ b/lib/src/kvs/mod.rs @@ -9,3 +9,5 @@ mod tx; pub use self::ds::*; pub use self::kv::*; pub use self::tx::*; + +pub const LOG: &str = "surrealdb::kvs"; diff --git a/src/cli/export.rs b/src/cli/export.rs index 0823e3db..73142a85 100644 --- a/src/cli/export.rs +++ b/src/cli/export.rs @@ -1,3 +1,4 @@ +use crate::cli::LOG; use crate::err::Error; use reqwest::blocking::Client; use reqwest::header::CONTENT_TYPE; @@ -54,7 +55,7 @@ pub fn init(matches: &clap::ArgMatches) -> Result<(), Error> { // and return an Ok to signify that // this command has been successful. - info!("The SQL file was exported successfully"); + info!(target: LOG, "The SQL file was exported successfully"); Ok(()) } diff --git a/src/cli/import.rs b/src/cli/import.rs index 22a1b2db..c17f39dd 100644 --- a/src/cli/import.rs +++ b/src/cli/import.rs @@ -1,3 +1,4 @@ +use crate::cli::LOG; use crate::err::Error; use reqwest::blocking::Client; use reqwest::header::CONTENT_TYPE; @@ -57,7 +58,7 @@ pub fn init(matches: &clap::ArgMatches) -> Result<(), Error> { // and return an Ok to signify that // this command has been successful. - info!("The SQL file was imported successfully"); + info!(target: LOG, "The SQL file was imported successfully"); Ok(()) } diff --git a/src/cli/mod.rs b/src/cli/mod.rs index bd00a43f..d7e70d2b 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -14,6 +14,8 @@ use once_cell::sync::Lazy; use rand::distributions::Alphanumeric; use rand::Rng; +pub const LOG: &str = "surrealdb::cli"; + const INFO: &str = " To get started using SurrealDB, and for guides on connecting to and building applications on top of SurrealDB, check out the SurrealDB documentation (https://surrealdb.com/docs). @@ -396,6 +398,6 @@ pub fn init() { }; if let Err(e) = output { - error!("{}", e); + error!(target: LOG, "{}", e); } } diff --git a/src/net/mod.rs b/src/net/mod.rs index 67524b2e..95c3477a 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -19,6 +19,8 @@ use crate::cli::CF; use crate::err::Error; use warp::Filter; +const LOG: &str = "surrealdb::net"; + pub async fn init() -> Result<(), Error> { // Setup web routes let net = index::config() @@ -58,7 +60,9 @@ pub async fn init() -> Result<(), Error> { // Get local copy of options let opt = CF.get().unwrap(); - info!("Starting web server on {}", &opt.bind); + info!(target: LOG, "Starting web server on {}", &opt.bind); + + info!(target: LOG, "Started web server on {}", &opt.bind); if let (Some(crt), Some(key)) = (&opt.crt, &opt.key) { warp::serve(net).tls().cert_path(crt).key_path(key).run(opt.bind).await