mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-26 04:24:21 +01:00
feat(javascript): add tracing_subscriber
This commit is contained in:
@@ -4,13 +4,27 @@ use std::cell::{RefCell, RefMut};
|
||||
use std::num::{NonZero, NonZeroUsize};
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, OnceLock};
|
||||
|
||||
use napi::bindgen_prelude::{JsObjectValue, Null, Object, ToNapiValue};
|
||||
use napi::{bindgen_prelude::ObjectFinalize, Env, JsValue, Unknown};
|
||||
use napi_derive::napi;
|
||||
use tracing_subscriber::fmt::format::FmtSpan;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use turso_core::{LimboError, StepResult};
|
||||
|
||||
static TRACING_INIT: OnceLock<()> = OnceLock::new();
|
||||
|
||||
fn init_tracing() {
|
||||
TRACING_INIT.get_or_init(|| {
|
||||
tracing_subscriber::fmt()
|
||||
.with_thread_ids(true)
|
||||
.with_span_events(FmtSpan::ACTIVE)
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.init();
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[napi(object)]
|
||||
pub struct OpenDatabaseOptions {
|
||||
@@ -68,6 +82,8 @@ impl ObjectFinalize for Database {
|
||||
impl Database {
|
||||
#[napi(constructor)]
|
||||
pub fn new(path: String, options: Option<OpenDatabaseOptions>) -> napi::Result<Self, String> {
|
||||
init_tracing();
|
||||
|
||||
let memory = path == ":memory:";
|
||||
let io: Arc<dyn turso_core::IO> = if memory {
|
||||
Arc::new(turso_core::MemoryIO::new())
|
||||
|
||||
Reference in New Issue
Block a user