Skip to content

Commit 4a5226d

Browse files
committed
Logging
1 parent f0f2566 commit 4a5226d

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
extern crate napi_derive;
77

88
use napi::bindgen_prelude::{Array, FromNapiValue, JsFunction};
9-
use napi::{Env, JsUnknown, Result, ValueType};
9+
use napi::{Env, JsObject, JsUnknown, Result, ValueType};
1010
use once_cell::sync::OnceCell;
11+
use tracing_subscriber::{EnvFilter, filter::LevelFilter};
1112
use std::sync::atomic::{AtomicBool, Ordering};
1213
use std::sync::Arc;
1314
use std::time::Duration;
@@ -182,6 +183,7 @@ impl Drop for Database {
182183
impl Database {
183184
#[napi(constructor)]
184185
pub fn new(path: String, opts: Option<Options>) -> Result<Self> {
186+
ensure_logger();
185187
let rt = runtime()?;
186188
let remote = is_remote_path(&path);
187189
let db = if remote {
@@ -852,3 +854,16 @@ fn map_row_raw(
852854
}
853855
}
854856

857+
static LOGGER_INIT: OnceCell<()> = OnceCell::new();
858+
859+
fn ensure_logger() {
860+
LOGGER_INIT.get_or_init(|| {
861+
let _ = tracing_subscriber::fmt::fmt()
862+
.with_env_filter(
863+
EnvFilter::builder()
864+
.with_default_directive(LevelFilter::ERROR.into())
865+
.from_env_lossy(),
866+
)
867+
.try_init();
868+
});
869+
}

0 commit comments

Comments
 (0)