Improve command-line logging

This commit is contained in:
Tobie Morgan Hitchcock 2022-07-19 09:28:24 +01:00
parent 97159203e1
commit 81bad3211d
9 changed files with 41 additions and 18 deletions

View file

@ -4,6 +4,7 @@ use crate::dbs::Auth;
use crate::dbs::Level; use crate::dbs::Level;
use crate::dbs::Options; use crate::dbs::Options;
use crate::dbs::Transaction; use crate::dbs::Transaction;
use crate::dbs::LOG;
use crate::err::Error; use crate::err::Error;
use crate::kvs::Datastore; use crate::kvs::Datastore;
use crate::sql::query::Query; use crate::sql::query::Query;
@ -127,7 +128,7 @@ impl<'a> Executor<'a> {
// Process all statements in query // Process all statements in query
for stm in qry.iter() { for stm in qry.iter() {
// Log the statement // Log the statement
debug!("Executing: {}", stm); debug!(target: LOG, "Executing: {}", stm);
// Reset errors // Reset errors
if self.txn.is_none() { if self.txn.is_none() {
self.err = false; self.err = false;

View file

@ -3,6 +3,7 @@ use crate::ctx::Context;
use crate::dbs::Options; use crate::dbs::Options;
use crate::dbs::Statement; use crate::dbs::Statement;
use crate::dbs::Transaction; use crate::dbs::Transaction;
use crate::dbs::LOG;
use crate::doc::Document; use crate::doc::Document;
use crate::err::Error; use crate::err::Error;
use crate::sql::array::Array; use crate::sql::array::Array;
@ -70,7 +71,7 @@ impl Iterator {
stm: &Statement<'_>, stm: &Statement<'_>,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
// Log the statement // Log the statement
trace!("Iterating: {}", stm); trace!(target: LOG, "Iterating: {}", stm);
// Enable context override // Enable context override
let mut ctx = Context::new(ctx); let mut ctx = Context::new(ctx);
self.run = ctx.add_cancel(); self.run = ctx.add_cancel();

View file

@ -27,3 +27,5 @@ pub use self::channel::*;
#[cfg(test)] #[cfg(test)]
pub(crate) mod test; pub(crate) mod test;
pub const LOG: &str = "surrealdb::dbs";

View file

@ -7,6 +7,7 @@ use crate::dbs::Response;
use crate::dbs::Session; use crate::dbs::Session;
use crate::dbs::Variables; use crate::dbs::Variables;
use crate::err::Error; use crate::err::Error;
use crate::kvs::LOG;
use crate::sql; use crate::sql;
use crate::sql::Query; use crate::sql::Query;
use crate::sql::Value; use crate::sql::Value;
@ -73,37 +74,45 @@ impl Datastore {
match path { match path {
#[cfg(feature = "kv-echodb")] #[cfg(feature = "kv-echodb")]
"memory" => { "memory" => {
info!("Starting kvs store in {}", path); info!(target: LOG, "Starting kvs store in {}", path);
super::mem::Datastore::new().await.map(|v| Datastore { let v = super::mem::Datastore::new().await.map(|v| Datastore {
inner: Inner::Mem(v), inner: Inner::Mem(v),
}) });
info!(target: LOG, "Started kvs store in {}", path);
v
} }
// Parse and initiate an IxDB database // Parse and initiate an IxDB database
#[cfg(feature = "kv-indxdb")] #[cfg(feature = "kv-indxdb")]
s if s.starts_with("ixdb:") => { 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://"); 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), inner: Inner::IxDB(v),
}) });
info!(target: LOG, "Started kvs store at {}", path);
v
} }
// Parse and initiate an File database // Parse and initiate an File database
#[cfg(feature = "kv-yokudb")] #[cfg(feature = "kv-yokudb")]
s if s.starts_with("file:") => { 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://"); 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), inner: Inner::File(v),
}) });
info!(target: LOG, "Started kvs store at {}", path);
v
} }
// Parse and initiate an TiKV database // Parse and initiate an TiKV database
#[cfg(feature = "kv-tikv")] #[cfg(feature = "kv-tikv")]
s if s.starts_with("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://"); 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), inner: Inner::TiKV(v),
}) });
info!(target: LOG, "Connected to kvs store at {}", path);
v
} }
// The datastore path is not valid // The datastore path is not valid
_ => unreachable!(), _ => unreachable!(),

View file

@ -9,3 +9,5 @@ mod tx;
pub use self::ds::*; pub use self::ds::*;
pub use self::kv::*; pub use self::kv::*;
pub use self::tx::*; pub use self::tx::*;
pub const LOG: &str = "surrealdb::kvs";

View file

@ -1,3 +1,4 @@
use crate::cli::LOG;
use crate::err::Error; use crate::err::Error;
use reqwest::blocking::Client; use reqwest::blocking::Client;
use reqwest::header::CONTENT_TYPE; use reqwest::header::CONTENT_TYPE;
@ -54,7 +55,7 @@ pub fn init(matches: &clap::ArgMatches) -> Result<(), Error> {
// and return an Ok to signify that // and return an Ok to signify that
// this command has been successful. // this command has been successful.
info!("The SQL file was exported successfully"); info!(target: LOG, "The SQL file was exported successfully");
Ok(()) Ok(())
} }

View file

@ -1,3 +1,4 @@
use crate::cli::LOG;
use crate::err::Error; use crate::err::Error;
use reqwest::blocking::Client; use reqwest::blocking::Client;
use reqwest::header::CONTENT_TYPE; use reqwest::header::CONTENT_TYPE;
@ -57,7 +58,7 @@ pub fn init(matches: &clap::ArgMatches) -> Result<(), Error> {
// and return an Ok to signify that // and return an Ok to signify that
// this command has been successful. // this command has been successful.
info!("The SQL file was imported successfully"); info!(target: LOG, "The SQL file was imported successfully");
Ok(()) Ok(())
} }

View file

@ -14,6 +14,8 @@ use once_cell::sync::Lazy;
use rand::distributions::Alphanumeric; use rand::distributions::Alphanumeric;
use rand::Rng; use rand::Rng;
pub const LOG: &str = "surrealdb::cli";
const INFO: &str = " const INFO: &str = "
To get started using SurrealDB, and for guides on connecting to and building applications 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). 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 { if let Err(e) = output {
error!("{}", e); error!(target: LOG, "{}", e);
} }
} }

View file

@ -19,6 +19,8 @@ use crate::cli::CF;
use crate::err::Error; use crate::err::Error;
use warp::Filter; use warp::Filter;
const LOG: &str = "surrealdb::net";
pub async fn init() -> Result<(), Error> { pub async fn init() -> Result<(), Error> {
// Setup web routes // Setup web routes
let net = index::config() let net = index::config()
@ -58,7 +60,9 @@ pub async fn init() -> Result<(), Error> {
// Get local copy of options // Get local copy of options
let opt = CF.get().unwrap(); 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) { if let (Some(crt), Some(key)) = (&opt.crt, &opt.key) {
warp::serve(net).tls().cert_path(crt).key_path(key).run(opt.bind).await warp::serve(net).tls().cert_path(crt).key_path(key).run(opt.bind).await