Improve command-line logging
This commit is contained in:
parent
97159203e1
commit
81bad3211d
9 changed files with 41 additions and 18 deletions
|
@ -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;
|
||||
|
|
|
@ -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<Value, Error> {
|
||||
// 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();
|
||||
|
|
|
@ -27,3 +27,5 @@ pub use self::channel::*;
|
|||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test;
|
||||
|
||||
pub const LOG: &str = "surrealdb::dbs";
|
||||
|
|
|
@ -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!(),
|
||||
|
|
|
@ -9,3 +9,5 @@ mod tx;
|
|||
pub use self::ds::*;
|
||||
pub use self::kv::*;
|
||||
pub use self::tx::*;
|
||||
|
||||
pub const LOG: &str = "surrealdb::kvs";
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue