diff --git a/Cargo.lock b/Cargo.lock index bf9b22ac..ff275bc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,7 +41,7 @@ dependencies = [ "cexpr", "clang-sys", "clap", - "env_logger", + "env_logger 0.8.3", "lazy_static", "lazycell", "log", @@ -209,6 +209,19 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime 1.3.0", + "log", + "regex", + "termcolor", +] + [[package]] name = "env_logger" version = "0.8.3" @@ -216,7 +229,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f" dependencies = [ "atty", - "humantime", + "humantime 2.1.0", "log", "regex", "termcolor", @@ -301,6 +314,15 @@ dependencies = [ "syn 1.0.67", ] +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + [[package]] name = "humantime" version = "2.1.0" @@ -500,6 +522,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +[[package]] +name = "pretty_env_logger" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" +dependencies = [ + "env_logger 0.7.1", + "log", +] + [[package]] name = "proc-macro-hack" version = "0.5.19" @@ -524,6 +556,12 @@ dependencies = [ "unicode-xid 0.2.1", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "0.6.13" @@ -659,6 +697,8 @@ dependencies = [ "kuchiki", "lazy_static", "libc", + "log", + "pretty_env_logger", "render", "shellexpand", "speculate", diff --git a/Cargo.toml b/Cargo.toml index 54398ceb..9ba23998 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,8 @@ bindgen = "0.58.1" count_tts = "*" lazy_static = "*" libc = "*" +log = "0.4.14" +pretty_env_logger = "0.4.0" render = "*" string-error = "0.1.0" strum_macros = "0.20.1" diff --git a/src/bin.rs b/src/bin.rs index 89d808ca..a77a786d 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -16,6 +16,7 @@ use crate::types::{ duckdb_blob, duckdb_date, duckdb_hugeint, duckdb_interval, duckdb_time, duckdb_timestamp, duckdb_type as DuckDBType, DuckDBColumn, DuckDBResult, }; +use log::info; use render::html; use render::{rsx, SimpleElement}; use std::cell::RefCell; @@ -190,7 +191,7 @@ impl<'a> Clone for ResolvedResult<'a> { } impl<'a> Drop for ResolvedResult<'a> { fn drop(&mut self) { - println!("Dropping {:?}", self); + info!("Dropping {:?}", self); unsafe { duckdb_destroy_result(self.result) }; } } @@ -295,10 +296,10 @@ unsafe fn run_async() -> Result<(), Box> { set_page_title("DuckDB Test".to_string()); let db = Some(DB::new(Some("db.db"))?); - println!("DB: {:?}", db); + info!("DB: {:?}", db); database.with(|f| f.replace(db)); - println!("DB open"); + info!("DB open"); let string = html! { <>{form()} }; set_body_html(string); @@ -309,7 +310,7 @@ unsafe fn run_async() -> Result<(), Box> { fn hook(info: &std::panic::PanicInfo) { let mut msg = info.to_string(); - println!("{:?}", msg); + info!("{:?}", msg); // Add the error stack to our message. // @@ -325,10 +326,10 @@ fn hook(info: &std::panic::PanicInfo) { // #[cfg(not(test))] // { // let error = js_sys::Error::new("test1"); - // println!("{:?}", error); + // info!("{:?}", error); // } // let stack = error.stack(); - // println!("{:?}", stack); + // info!("{:?}", stack); // msg.push_str(stack.as_str().unwrap_or_default()); // Safari's devtools, on the other hand, _do_ mess with logged @@ -338,7 +339,7 @@ fn hook(info: &std::panic::PanicInfo) { msg.push_str("\n\n"); // Finally, log the panic with `console.error`! - println!("{}", msg); + info!("{}", msg); } #[no_mangle] @@ -346,18 +347,18 @@ extern "C" fn callback(query_: *const c_char) { let org = unsafe { CStr::from_ptr(query_) }; let query = org.to_string_lossy(); - println!("you called?: {} {:?} {:?}", query, org, query_); + info!("you called?: {} {:?} {:?}", query, org, query_); database.with(|borrowed| { - println!("borrowed: {:?}", borrowed); + info!("borrowed: {:?}", borrowed); let yo = borrowed.borrow(); - println!("yo: {:?}", yo); + info!("yo: {:?}", yo); let conn = yo.as_ref().expect("no db?").connection().unwrap(); let string = match conn.query(&query) { Ok(resolved) => { - println!("columns: {:?}", resolved.columns); + info!("columns: {:?}", resolved.columns); let table = Table { resolved: &resolved, @@ -380,13 +381,15 @@ extern "C" fn callback(query_: *const c_char) { } }; - println!("{}", string); + info!("{}", string); set_body_html(string); }); } pub fn main() -> Result<(), Box> { + pretty_env_logger::init(); + std::panic::set_hook(Box::new(hook)); unsafe { diff --git a/src/db.rs b/src/db.rs index cc99e665..a61d33ee 100644 --- a/src/db.rs +++ b/src/db.rs @@ -2,6 +2,7 @@ use crate::{ duckdb_connect, duckdb_disconnect, duckdb_open, duckdb_query, ext_duckdb_close, malloc, Database, DuckDBState, ResolvedResult, PTR, }; +use log::info; use std::ffi::{CStr, CString}; extern "C" { @@ -31,13 +32,13 @@ impl DB { pub fn connection(&self) -> Result> { let connection: *const crate::Connection = unsafe { create_connection(self.db) }; - println!("conn: {:?}", &connection); + info!("conn: {:?}", &connection); Ok(Connection { connection }) } } impl Drop for DB { fn drop(&mut self) { - println!("Dropping {:?}", self); + info!("Dropping {:?}", self); unsafe { ext_duckdb_close(self.db) }; } } @@ -66,7 +67,7 @@ impl Connection { } impl Drop for Connection { fn drop(&mut self) { - println!("Dropping {:?}", self); + info!("Dropping {:?}", self); unsafe { duckdb_disconnect(self.connection) }; } } diff --git a/src/tests.rs b/src/tests.rs index ffb3fec0..1ffc170b 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -4,6 +4,7 @@ use crate::{ c_char, callback, duckdb_date, duckdb_time, duckdb_timestamp, emscripten_asm_const_int, hook, main, }; +use log::info; use speculate::speculate; use std::ffi::{CStr, CString}; @@ -30,6 +31,7 @@ fn get_document_html() -> String { speculate! { before { + pretty_env_logger::init(); std::panic::set_hook(Box::new(hook)); jse!(b"global.document = {body: {}};\x00"); @@ -130,10 +132,10 @@ speculate! { let db = DB::new( None ).expect("db"); - println!("db: {:?}", &db); + info!("db: {:?}", &db); let conn = db.connection().expect("connection"); - println!("conn: {:?}", &conn); + info!("conn: {:?}", &conn); conn.query("select 1").expect("query"); }