From ffd55763b683ad3aa6b2fabb40f7039d98f98a09 Mon Sep 17 00:00:00 2001 From: appflowy Date: Wed, 3 Nov 2021 15:37:38 +0800 Subject: [PATCH] [rust]: replace log with tracing --- backend/src/middleware/auth_middleware.rs | 4 +-- backend/src/service/user/logged_user.rs | 4 +-- backend/src/service/ws/router.rs | 2 +- backend/src/service/ws/ws_client.rs | 4 +-- backend/tests/api/auth.rs | 4 +-- backend/tests/api/workspace.rs | 8 ++--- rust-lib/flowy-dispatch/src/dispatch.rs | 8 ++--- rust-lib/flowy-dispatch/src/module/module.rs | 2 +- rust-lib/flowy-dispatch/src/util/mod.rs | 4 +-- .../src/services/doc/document/document.rs | 24 +++++++------- .../src/services/doc/edit/doc_actor.rs | 4 +-- .../src/services/doc/edit/edit_doc.rs | 2 +- .../src/services/doc/revision/persistence.rs | 2 +- .../flowy-document/src/services/doc/view.rs | 6 ++-- .../src/services/file/manager.rs | 5 +-- .../src/sql_tables/doc/rev_sql.rs | 4 +-- rust-lib/flowy-document/tests/editor/mod.rs | 32 +++++++++---------- rust-lib/flowy-log/src/lib.rs | 9 ++---- rust-lib/flowy-net/Cargo.toml | 1 + rust-lib/flowy-net/src/request/request.rs | 2 +- rust-lib/flowy-ot/Cargo.toml | 1 + .../flowy-ot/src/core/attributes/attribute.rs | 1 - .../src/core/attributes/attributes_serde.rs | 1 - rust-lib/flowy-ot/src/core/delta/delta.rs | 22 ++++++------- rust-lib/flowy-ot/src/core/delta/iterator.rs | 4 +-- .../flowy-ot/src/core/operation/operation.rs | 2 +- .../flowy-user/src/services/user/database.rs | 2 +- .../src/services/user/user_session.rs | 4 +-- .../flowy-workspace/src/services/trash_can.rs | 2 +- .../src/services/workspace_controller.rs | 6 ++-- rust-lib/flowy-ws/Cargo.toml | 1 + rust-lib/flowy-ws/src/connect.rs | 4 +-- rust-lib/flowy-ws/src/ws.rs | 2 +- scripts/flowy-tool/src/util/file.rs | 2 +- 34 files changed, 91 insertions(+), 94 deletions(-) diff --git a/backend/src/middleware/auth_middleware.rs b/backend/src/middleware/auth_middleware.rs index c51731d354..6829a85b66 100644 --- a/backend/src/middleware/auth_middleware.rs +++ b/backend/src/middleware/auth_middleware.rs @@ -54,7 +54,7 @@ where fn call(&self, req: ServiceRequest) -> Self::Future { let mut authenticate_pass: bool = false; for ignore_route in IGNORE_ROUTES.iter() { - // log::info!("ignore: {}, path: {}", ignore_route, req.path()); + // tracing::info!("ignore: {}, path: {}", ignore_route, req.path()); if req.path().starts_with(ignore_route) { authenticate_pass = true; break; @@ -79,7 +79,7 @@ where Err(e) => log::error!("{:?}", e), } } else { - log::debug!("Can't find any token from request: {:?}", req); + tracing::debug!("Can't find any token from request: {:?}", req); } } diff --git a/backend/src/service/user/logged_user.rs b/backend/src/service/user/logged_user.rs index 7414e0243a..3cb65cea8d 100644 --- a/backend/src/service/user/logged_user.rs +++ b/backend/src/service/user/logged_user.rs @@ -82,7 +82,7 @@ impl AuthorizedUsers { pub fn is_authorized(&self, user: &LoggedUser) -> bool { match self.0.get(user) { None => { - log::debug!("user not login yet or server was reboot"); + tracing::debug!("user not login yet or server was reboot"); false }, Some(status) => match *status { @@ -92,7 +92,7 @@ impl AuthorizedUsers { days < EXPIRED_DURATION_DAYS }, AuthStatus::NotAuthorized => { - log::debug!("user logout already"); + tracing::debug!("user logout already"); false }, }, diff --git a/backend/src/service/ws/router.rs b/backend/src/service/ws/router.rs index 8cc651d265..5aea6d80e7 100644 --- a/backend/src/service/ws/router.rs +++ b/backend/src/service/ws/router.rs @@ -20,7 +20,7 @@ pub async fn establish_ws_connection( server: Data>, biz_handlers: Data, ) -> Result { - log::info!("establish_ws_connection"); + tracing::info!("establish_ws_connection"); match LoggedUser::from_token(token.clone()) { Ok(user) => { let ws_user = WsUser::new(user.clone()); diff --git a/backend/src/service/ws/ws_client.rs b/backend/src/service/ws/ws_client.rs index e563acba8b..1e2d6ae430 100644 --- a/backend/src/service/ws/ws_client.rs +++ b/backend/src/service/ws/ws_client.rs @@ -91,7 +91,7 @@ impl StreamHandler> for WsClient { ctx.pong(&msg); }, Ok(ws::Message::Pong(_msg)) => { - // log::debug!("Receive {} pong {:?}", &self.session_id, &msg); + // tracing::debug!("Receive {} pong {:?}", &self.session_id, &msg); self.hb = Instant::now(); }, Ok(ws::Message::Binary(bytes)) => { @@ -136,7 +136,7 @@ impl Actor for WsClient { .into_actor(self) .then(|res, _client, _ctx| { match res { - Ok(Ok(_)) => log::trace!("Send connect message to server success"), + Ok(Ok(_)) => tracing::trace!("Send connect message to server success"), Ok(Err(e)) => log::error!("Send connect message to server failed: {:?}", e), Err(e) => log::error!("Send connect message to server failed: {:?}", e), } diff --git a/backend/tests/api/auth.rs b/backend/tests/api/auth.rs index e342d98b33..7abcd67d36 100644 --- a/backend/tests/api/auth.rs +++ b/backend/tests/api/auth.rs @@ -5,7 +5,7 @@ use flowy_user::entities::{SignInParams, SignUpParams, SignUpResponse, UpdateUse async fn user_register() { let app = spawn_user_server().await; let response = register_user(&app, "annie@appflowy.io", "HelloWorld123!").await; - log::info!("{:?}", response); + tracing::info!("{:?}", response); } #[actix_rt::test] @@ -52,7 +52,7 @@ async fn user_sign_out() { #[actix_rt::test] async fn user_get_detail() { let server = TestUserServer::new().await; - log::info!("{:?}", server.get_user_profile().await); + tracing::info!("{:?}", server.get_user_profile().await); } #[actix_rt::test] diff --git a/backend/tests/api/workspace.rs b/backend/tests/api/workspace.rs index c94a42cbbd..fcbc827508 100644 --- a/backend/tests/api/workspace.rs +++ b/backend/tests/api/workspace.rs @@ -9,14 +9,14 @@ use flowy_workspace::entities::{ #[actix_rt::test] async fn workspace_create() { let test = WorkspaceTest::new().await; - log::info!("{:?}", test.workspace); + tracing::info!("{:?}", test.workspace); } #[actix_rt::test] async fn workspace_read() { let test = WorkspaceTest::new().await; let read_params = QueryWorkspaceParams::new().workspace_id(&test.workspace.id); - log::info!("{:?}", test.server.read_workspaces(read_params).await); + tracing::info!("{:?}", test.server.read_workspaces(read_params).await); } #[actix_rt::test] @@ -69,7 +69,7 @@ async fn workspace_delete() { #[actix_rt::test] async fn app_create() { let test = AppTest::new().await; - log::info!("{:?}", test.app); + tracing::info!("{:?}", test.app); } #[actix_rt::test] @@ -134,7 +134,7 @@ async fn app_delete() { #[actix_rt::test] async fn view_create() { let test = ViewTest::new().await; - log::info!("{:?}", test.view); + tracing::info!("{:?}", test.view); } #[actix_rt::test] diff --git a/rust-lib/flowy-dispatch/src/dispatch.rs b/rust-lib/flowy-dispatch/src/dispatch.rs index 3b33d0bdc8..5368943ec4 100644 --- a/rust-lib/flowy-dispatch/src/dispatch.rs +++ b/rust-lib/flowy-dispatch/src/dispatch.rs @@ -23,7 +23,7 @@ impl EventDispatch { { let runtime = tokio_default_runtime().unwrap(); let modules = module_factory(); - log::trace!("{}", module_info(&modules)); + tracing::trace!("{}", module_info(&modules)); let module_map = as_module_map(modules); let dispatch = EventDispatch { module_map, runtime }; @@ -49,7 +49,7 @@ impl EventDispatch { let request: ModuleRequest = request.into(); let module_map = dispatch.module_map.clone(); let service = Box::new(DispatchService { module_map }); - log::trace!("Async event: {:?}", &request.event); + tracing::trace!("Async event: {:?}", &request.event); let service_ctx = DispatchContext { request, callback: Some(Box::new(callback)), @@ -157,7 +157,7 @@ impl Service for DispatchService { }; let response = result.unwrap_or_else(|e| e.into()); - log::trace!("Dispatch result: {:?}", response); + tracing::trace!("Dispatch result: {:?}", response); if let Some(callback) = callback { callback(response.clone()).await; } @@ -179,6 +179,6 @@ fn module_info(modules: &Vec) -> String { #[allow(dead_code)] fn print_module_map_info(module_map: &ModuleMap) { module_map.iter().for_each(|(k, v)| { - log::info!("Event: {:?} module: {:?}", k, v.name); + tracing::info!("Event: {:?} module: {:?}", k, v.name); }) } diff --git a/rust-lib/flowy-dispatch/src/module/module.rs b/rust-lib/flowy-dispatch/src/module/module.rs index becc2f05cc..7b4638f232 100644 --- a/rust-lib/flowy-dispatch/src/module/module.rs +++ b/rust-lib/flowy-dispatch/src/module/module.rs @@ -228,7 +228,7 @@ impl Future for ModuleServiceFuture { // // match sys_rx.recv().await { // Some(cmd) => { -// log::info!("{:?}", cmd); +// tracing::info!("{:?}", cmd); // }, // None => panic!(""), // } diff --git a/rust-lib/flowy-dispatch/src/util/mod.rs b/rust-lib/flowy-dispatch/src/util/mod.rs index 0579c4d0b9..bf532f867b 100644 --- a/rust-lib/flowy-dispatch/src/util/mod.rs +++ b/rust-lib/flowy-dispatch/src/util/mod.rs @@ -10,14 +10,14 @@ pub fn tokio_default_runtime() -> io::Result { .enable_io() .enable_time() .on_thread_start(move || { - log::trace!( + tracing::trace!( "{:?} thread started: thread_id= {}", thread::current(), thread_id::get() ); }) .on_thread_stop(move || { - log::trace!( + tracing::trace!( "{:?} thread stopping: thread_id= {}", thread::current(), thread_id::get(), diff --git a/rust-lib/flowy-document/src/services/doc/document/document.rs b/rust-lib/flowy-document/src/services/doc/document/document.rs index 7910f651a3..5033d702e4 100644 --- a/rust-lib/flowy-document/src/services/doc/document/document.rs +++ b/rust-lib/flowy-document/src/services/doc/document/document.rs @@ -68,28 +68,28 @@ impl Document { } pub fn compose_delta(&mut self, delta: &Delta) -> Result<(), DocError> { - log::trace!("{} compose {}", &self.delta.to_json(), delta.to_json()); + tracing::trace!("{} compose {}", &self.delta.to_json(), delta.to_json()); let composed_delta = self.delta.compose(delta)?; let mut undo_delta = delta.invert(&self.delta); let now = chrono::Utc::now().timestamp_millis() as usize; if now - self.last_edit_time < RECORD_THRESHOLD { if let Some(last_delta) = self.history.undo() { - log::trace!("compose previous change"); - log::trace!("current = {}", undo_delta); - log::trace!("previous = {}", last_delta); + tracing::trace!("compose previous change"); + tracing::trace!("current = {}", undo_delta); + tracing::trace!("previous = {}", last_delta); undo_delta = undo_delta.compose(&last_delta)?; } } else { self.last_edit_time = now; } - log::trace!("πŸ‘‰ receive change undo: {}", undo_delta); + tracing::trace!("πŸ‘‰ receive change undo: {}", undo_delta); if !undo_delta.is_empty() { self.history.record(undo_delta); } - log::trace!("compose result: {}", composed_delta.to_json()); + tracing::trace!("compose result: {}", composed_delta.to_json()); self.set_delta(composed_delta); Ok(()) } @@ -100,7 +100,7 @@ impl Document { let text = data.to_string(); let delta = self.view.insert(&self.delta, &text, interval)?; - log::trace!("πŸ‘‰ receive change: {}", delta); + tracing::trace!("πŸ‘‰ receive change: {}", delta); self.compose_delta(&delta)?; Ok(delta) } @@ -110,7 +110,7 @@ impl Document { debug_assert_eq!(interval.is_empty(), false); let delete = self.view.delete(&self.delta, interval)?; if !delete.is_empty() { - log::trace!("πŸ‘‰ receive change: {}", delete); + tracing::trace!("πŸ‘‰ receive change: {}", delete); let _ = self.compose_delta(&delete)?; } Ok(delete) @@ -118,10 +118,10 @@ impl Document { pub fn format(&mut self, interval: Interval, attribute: Attribute) -> Result { let _ = validate_interval(&self.delta, &interval)?; - log::trace!("format with {} at {}", attribute, interval); + tracing::trace!("format with {} at {}", attribute, interval); let format_delta = self.view.format(&self.delta, attribute.clone(), interval).unwrap(); - log::trace!("πŸ‘‰ receive change: {}", format_delta); + tracing::trace!("πŸ‘‰ receive change: {}", format_delta); self.compose_delta(&format_delta)?; Ok(format_delta) } @@ -132,7 +132,7 @@ impl Document { let text = data.to_string(); if !text.is_empty() { delta = self.view.insert(&self.delta, &text, interval)?; - log::trace!("πŸ‘‰ receive change: {}", delta); + tracing::trace!("πŸ‘‰ receive change: {}", delta); self.compose_delta(&delta)?; } @@ -182,7 +182,7 @@ impl Document { // c = a.compose(b) // d = b.invert(a) // a = c.compose(d) - log::trace!("Invert {}", delta); + tracing::trace!("Invert {}", delta); let new_delta = self.delta.compose(delta)?; let inverted_delta = delta.invert(&self.delta); Ok((new_delta, inverted_delta)) diff --git a/rust-lib/flowy-document/src/services/doc/edit/doc_actor.rs b/rust-lib/flowy-document/src/services/doc/edit/doc_actor.rs index 202b8dc318..16b75cc26d 100644 --- a/rust-lib/flowy-document/src/services/doc/edit/doc_actor.rs +++ b/rust-lib/flowy-document/src/services/doc/edit/doc_actor.rs @@ -111,10 +111,10 @@ impl DocumentActor { } async fn compose_delta(&self, delta: Delta) -> DocResult<()> { - // log::debug!("{:?} thread handle_message", thread::current(),); + // tracing::debug!("{:?} thread handle_message", thread::current(),); let mut document = self.document.write().await; let result = document.compose_delta(&delta); - log::debug!( + tracing::debug!( "Compose push delta: {}. result: {}", delta.to_json(), document.to_json() diff --git a/rust-lib/flowy-document/src/services/doc/edit/edit_doc.rs b/rust-lib/flowy-document/src/services/doc/edit/edit_doc.rs index 567bb199a4..dc70a72617 100644 --- a/rust-lib/flowy-document/src/services/doc/edit/edit_doc.rs +++ b/rust-lib/flowy-document/src/services/doc/edit/edit_doc.rs @@ -304,7 +304,7 @@ fn spawn_rev_receiver(mut receiver: mpsc::UnboundedReceiver, ws: Arc {}, Err(e) => log::error!("Send revision failed: {:?}", e), diff --git a/rust-lib/flowy-document/src/services/doc/revision/persistence.rs b/rust-lib/flowy-document/src/services/doc/revision/persistence.rs index 51cc130691..b360d4d1d0 100644 --- a/rust-lib/flowy-document/src/services/doc/revision/persistence.rs +++ b/rust-lib/flowy-document/src/services/doc/revision/persistence.rs @@ -219,7 +219,7 @@ async fn fetch_from_local(doc_id: &str, persistence: Arc) -> DocRes // return; // } // -// log::debug!("Try to update {:?} state", rev_ids); +// tracing::debug!("Try to update {:?} state", rev_ids); // match self.update(&rev_ids) { // Ok(_) => { // self.revs.retain(|k, _| !rev_ids.contains(k)); diff --git a/rust-lib/flowy-document/src/services/doc/view.rs b/rust-lib/flowy-document/src/services/doc/view.rs index afe181d333..c092fc9418 100644 --- a/rust-lib/flowy-document/src/services/doc/view.rs +++ b/rust-lib/flowy-document/src/services/doc/view.rs @@ -25,7 +25,7 @@ impl View { let mut new_delta = None; for ext in &self.insert_exts { if let Some(delta) = ext.apply(delta, interval.size(), text, interval.start) { - log::trace!("[{}]: applied, delta: {}", ext.ext_name(), delta); + tracing::trace!("[{}]: applied, delta: {}", ext.ext_name(), delta); new_delta = Some(delta); break; } @@ -41,7 +41,7 @@ impl View { let mut new_delta = None; for ext in &self.delete_exts { if let Some(delta) = ext.apply(delta, interval) { - log::trace!("[{}]: applied, delta: {}", ext.ext_name(), delta); + tracing::trace!("[{}]: applied, delta: {}", ext.ext_name(), delta); new_delta = Some(delta); break; } @@ -57,7 +57,7 @@ impl View { let mut new_delta = None; for ext in &self.format_exts { if let Some(delta) = ext.apply(delta, interval, &attribute) { - log::trace!("[{}]: applied, delta: {}", ext.ext_name(), delta); + tracing::trace!("[{}]: applied, delta: {}", ext.ext_name(), delta); new_delta = Some(delta); break; } diff --git a/rust-lib/flowy-document/src/services/file/manager.rs b/rust-lib/flowy-document/src/services/file/manager.rs index 48b45082b3..69066bc69d 100644 --- a/rust-lib/flowy-document/src/services/file/manager.rs +++ b/rust-lib/flowy-document/src/services/file/manager.rs @@ -64,7 +64,7 @@ impl FileManager { pub(crate) fn create_file(&mut self, id: &str, dir: &str, text: &str) -> Result { let path = PathBuf::from(format!("{}/{}", dir, id)); let file_id: FileId = id.to_owned().into(); - log::info!("Create doc at: {:?}", path); + tracing::info!("Create doc at: {:?}", path); let _ = self.save_new(&path, text, &file_id)?; Ok(path) } @@ -89,7 +89,8 @@ impl FileManager { #[allow(dead_code)] fn save_new(&mut self, path: &Path, text: &str, id: &FileId) -> Result<(), FileError> { - try_save(path, text, CharacterEncoding::Utf8, self.get_info(id)).map_err(|e| FileError::Io(e, path.to_owned()))?; + try_save(path, text, CharacterEncoding::Utf8, self.get_info(id)) + .map_err(|e| FileError::Io(e, path.to_owned()))?; let info = FileInfo { encoding: CharacterEncoding::Utf8, path: path.to_owned(), diff --git a/rust-lib/flowy-document/src/sql_tables/doc/rev_sql.rs b/rust-lib/flowy-document/src/sql_tables/doc/rev_sql.rs index a5543203ff..874cc6e86d 100644 --- a/rust-lib/flowy-document/src/sql_tables/doc/rev_sql.rs +++ b/rust-lib/flowy-document/src/sql_tables/doc/rev_sql.rs @@ -23,7 +23,7 @@ impl RevTableSql { let records = revisions .into_iter() .map(|(revision, new_state)| { - log::debug!("Set {} to {:?}", revision.rev_id, new_state); + tracing::debug!("Set {} to {:?}", revision.rev_id, new_state); let rev_ty: RevTableType = revision.ty.into(); ( doc_id.eq(revision.doc_id), @@ -45,7 +45,7 @@ impl RevTableSql { .filter(rev_id.eq(changeset.rev_id.as_ref())) .filter(doc_id.eq(changeset.doc_id)); let _ = update(filter).set(state.eq(changeset.state)).execute(conn)?; - log::debug!("Set {} to {:?}", changeset.rev_id, changeset.state); + tracing::debug!("Set {} to {:?}", changeset.rev_id, changeset.state); Ok(()) } diff --git a/rust-lib/flowy-document/tests/editor/mod.rs b/rust-lib/flowy-document/tests/editor/mod.rs index 5f834c1010..24d37075f1 100644 --- a/rust-lib/flowy-document/tests/editor/mod.rs +++ b/rust-lib/flowy-document/tests/editor/mod.rs @@ -100,25 +100,25 @@ impl TestBuilder { } fn run_op(&mut self, op: &TestOp) { - log::trace!("***************** 😈{} *******************", &op); + tracing::trace!("***************** 😈{} *******************", &op); match op { TestOp::Insert(delta_i, s, index) => { let document = &mut self.documents[*delta_i]; let delta = document.insert(*index, s).unwrap(); - log::debug!("Insert delta: {}", delta.to_json()); + tracing::debug!("Insert delta: {}", delta.to_json()); self.deltas.insert(*delta_i, Some(delta)); }, TestOp::Delete(delta_i, iv) => { let document = &mut self.documents[*delta_i]; let delta = document.replace(*iv, "").unwrap(); - log::trace!("Delete delta: {}", delta.to_json()); + tracing::trace!("Delete delta: {}", delta.to_json()); self.deltas.insert(*delta_i, Some(delta)); }, TestOp::Replace(delta_i, iv, s) => { let document = &mut self.documents[*delta_i]; let delta = document.replace(*iv, s).unwrap(); - log::trace!("Replace delta: {}", delta.to_json()); + tracing::trace!("Replace delta: {}", delta.to_json()); self.deltas.insert(*delta_i, Some(delta)); }, TestOp::InsertBold(delta_i, s, iv) => { @@ -130,7 +130,7 @@ impl TestBuilder { let document = &mut self.documents[*delta_i]; let attribute = Attribute::Bold(*enable); let delta = document.format(*iv, attribute).unwrap(); - log::trace!("Bold delta: {}", delta.to_json()); + tracing::trace!("Bold delta: {}", delta.to_json()); self.deltas.insert(*delta_i, Some(delta)); }, TestOp::Italic(delta_i, iv, enable) => { @@ -140,28 +140,28 @@ impl TestBuilder { false => Attribute::Italic(false), }; let delta = document.format(*iv, attribute).unwrap(); - log::trace!("Italic delta: {}", delta.to_json()); + tracing::trace!("Italic delta: {}", delta.to_json()); self.deltas.insert(*delta_i, Some(delta)); }, TestOp::Header(delta_i, iv, level) => { let document = &mut self.documents[*delta_i]; let attribute = Attribute::Header(*level); let delta = document.format(*iv, attribute).unwrap(); - log::trace!("Header delta: {}", delta.to_json()); + tracing::trace!("Header delta: {}", delta.to_json()); self.deltas.insert(*delta_i, Some(delta)); }, TestOp::Link(delta_i, iv, link) => { let document = &mut self.documents[*delta_i]; let attribute = Attribute::Link(link.to_owned()); let delta = document.format(*iv, attribute).unwrap(); - log::trace!("Link delta: {}", delta.to_json()); + tracing::trace!("Link delta: {}", delta.to_json()); self.deltas.insert(*delta_i, Some(delta)); }, TestOp::Bullet(delta_i, iv, enable) => { let document = &mut self.documents[*delta_i]; let attribute = Attribute::Bullet(*enable); let delta = document.format(*iv, attribute).unwrap(); - log::debug!("Bullet delta: {}", delta.to_json()); + tracing::debug!("Bullet delta: {}", delta.to_json()); self.deltas.insert(*delta_i, Some(delta)); }, @@ -170,7 +170,7 @@ impl TestBuilder { .delta() .transform(&self.documents[*delta_b_i].delta()) .unwrap(); - log::trace!("a:{:?},b:{:?}", a_prime, b_prime); + tracing::trace!("a:{:?},b:{:?}", a_prime, b_prime); let data_left = self.documents[*delta_a_i].delta().compose(&b_prime).unwrap(); let data_right = self.documents[*delta_b_i].delta().compose(&a_prime).unwrap(); @@ -190,20 +190,20 @@ impl TestBuilder { TestOp::Invert(delta_a_i, delta_b_i) => { let delta_a = &self.documents[*delta_a_i].delta(); let delta_b = &self.documents[*delta_b_i].delta(); - log::debug!("Invert: "); - log::debug!("a: {}", delta_a.to_json()); - log::debug!("b: {}", delta_b.to_json()); + tracing::debug!("Invert: "); + tracing::debug!("a: {}", delta_a.to_json()); + tracing::debug!("b: {}", delta_b.to_json()); let (_, b_prime) = delta_a.transform(delta_b).unwrap(); let undo = b_prime.invert(&delta_a); let new_delta = delta_a.compose(&b_prime).unwrap(); - log::debug!("new delta: {}", new_delta.to_json()); - log::debug!("undo delta: {}", undo.to_json()); + tracing::debug!("new delta: {}", new_delta.to_json()); + tracing::debug!("undo delta: {}", undo.to_json()); let new_delta_after_undo = new_delta.compose(&undo).unwrap(); - log::debug!("inverted delta a: {}", new_delta_after_undo.to_string()); + tracing::debug!("inverted delta a: {}", new_delta_after_undo.to_string()); assert_eq!(delta_a, &&new_delta_after_undo); diff --git a/rust-lib/flowy-log/src/lib.rs b/rust-lib/flowy-log/src/lib.rs index feeead28f5..fd8cd3cfbe 100644 --- a/rust-lib/flowy-log/src/lib.rs +++ b/rust-lib/flowy-log/src/lib.rs @@ -10,12 +10,7 @@ use std::sync::RwLock; use tracing_appender::{non_blocking::WorkerGuard, rolling::RollingFileAppender}; use tracing_bunyan_formatter::JsonStorageLayer; use tracing_log::LogTracer; -use tracing_subscriber::{ - field::MakeExt, - fmt::{format, format::FmtSpan}, - layer::SubscriberExt, - EnvFilter, -}; +use tracing_subscriber::{field::MakeExt, fmt::format, layer::SubscriberExt, EnvFilter}; lazy_static! { static ref LOG_GUARD: RwLock> = RwLock::new(None); @@ -150,6 +145,6 @@ mod tests { #[tracing::instrument(name = "say")] fn say(s: &str) { - log::info!("{}", s); + tracing::info!("{}", s); } } diff --git a/rust-lib/flowy-net/Cargo.toml b/rust-lib/flowy-net/Cargo.toml index e895c1dffa..00f37241f1 100644 --- a/rust-lib/flowy-net/Cargo.toml +++ b/rust-lib/flowy-net/Cargo.toml @@ -15,6 +15,7 @@ serde_repr = "0.1" pin-project = "1.0.0" futures-core = { version = "0.3", default-features = false } log = "0.4" +tracing = { version = "0.1", features = ["log"] } bytes = { version = "1.0", features = ["serde"]} lazy_static = "1.4.0" tokio = { version = "1", features = ["full"] } diff --git a/rust-lib/flowy-net/src/request/request.rs b/rust-lib/flowy-net/src/request/request.rs index e8f004605e..ba25730611 100644 --- a/rust-lib/flowy-net/src/request/request.rs +++ b/rust-lib/flowy-net/src/request/request.rs @@ -148,7 +148,7 @@ impl HttpRequestBuilder { }); let response = rx.await??; - log::trace!("Http Response: {:?}", response); + tracing::trace!("Http Response: {:?}", response); let flowy_response = flowy_response_from(response).await?; let token = self.token(); self.middleware.iter().for_each(|middleware| { diff --git a/rust-lib/flowy-ot/Cargo.toml b/rust-lib/flowy-ot/Cargo.toml index ef5ac88ed9..b90e876ab5 100644 --- a/rust-lib/flowy-ot/Cargo.toml +++ b/rust-lib/flowy-ot/Cargo.toml @@ -11,6 +11,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = {version = "1.0"} derive_more = {version = "0.99", features = ["display"]} log = "0.4" +tracing = { version = "0.1", features = ["log"] } lazy_static = "1.4.0" strum = "0.21" strum_macros = "0.21" diff --git a/rust-lib/flowy-ot/src/core/attributes/attribute.rs b/rust-lib/flowy-ot/src/core/attributes/attribute.rs index 4674cb0b8f..651532b058 100644 --- a/rust-lib/flowy-ot/src/core/attributes/attribute.rs +++ b/rust-lib/flowy-ot/src/core/attributes/attribute.rs @@ -3,7 +3,6 @@ use crate::{block_attribute, core::Attributes, ignore_attribute, inline_attribute, list_attribute}; use lazy_static::lazy_static; -use serde_json::Error; use std::{collections::HashSet, fmt, fmt::Formatter, iter::FromIterator}; use strum_macros::Display; diff --git a/rust-lib/flowy-ot/src/core/attributes/attributes_serde.rs b/rust-lib/flowy-ot/src/core/attributes/attributes_serde.rs index 34f19da47b..2493be0918 100644 --- a/rust-lib/flowy-ot/src/core/attributes/attributes_serde.rs +++ b/rust-lib/flowy-ot/src/core/attributes/attributes_serde.rs @@ -4,7 +4,6 @@ use crate::core::{Attribute, AttributeKey, Attributes}; use serde::{ de, de::{MapAccess, Visitor}, - ser, ser::SerializeMap, Deserialize, Deserializer, diff --git a/rust-lib/flowy-ot/src/core/delta/delta.rs b/rust-lib/flowy-ot/src/core/delta/delta.rs index 4f9b15d2c1..c837848af0 100644 --- a/rust-lib/flowy-ot/src/core/delta/delta.rs +++ b/rust-lib/flowy-ot/src/core/delta/delta.rs @@ -78,8 +78,8 @@ impl Delta { pub fn from_json(json: &str) -> Result { let delta: Delta = serde_json::from_str(json).map_err(|e| { - log::trace!("Deserialize failed: {:?}", e); - log::trace!("{:?}", json); + tracing::trace!("Deserialize failed: {:?}", e); + tracing::trace!("{:?}", json); e })?; Ok(delta) @@ -426,9 +426,9 @@ impl OperationTransformable for Delta { if other.is_empty() { return inverted; } - log::trace!("🌜Calculate invert delta"); - log::trace!("current: {}", self); - log::trace!("other: {}", other); + tracing::trace!("🌜Calculate invert delta"); + tracing::trace!("current: {}", self); + tracing::trace!("other: {}", other); let mut index = 0; for op in &self.ops { let len: usize = op.len() as usize; @@ -441,34 +441,34 @@ impl OperationTransformable for Delta { match op.has_attribute() { true => invert_from_other(&mut inverted, other, op, index, index + len), false => { - log::trace!("invert retain: {} by retain {} {}", op, len, op.get_attributes()); + tracing::trace!("invert retain: {} by retain {} {}", op, len, op.get_attributes()); inverted.retain(len as usize, op.get_attributes()) }, } index += len; }, Operation::Insert(_) => { - log::trace!("invert insert: {} by delete {}", op, len); + tracing::trace!("invert insert: {} by delete {}", op, len); inverted.delete(len as usize); }, } } - log::trace!("πŸŒ›invert result: {}", inverted); + tracing::trace!("πŸŒ›invert result: {}", inverted); inverted } } fn invert_from_other(base: &mut Delta, other: &Delta, operation: &Operation, start: usize, end: usize) { - log::trace!("invert op: {} [{}:{}]", operation, start, end); + tracing::trace!("invert op: {} [{}:{}]", operation, start, end); let other_ops = DeltaIter::from_interval(other, Interval::new(start, end)).ops(); other_ops.into_iter().for_each(|other_op| match operation { Operation::Delete(n) => { - log::trace!("invert delete: {} by add {}", n, other_op); + tracing::trace!("invert delete: {} by add {}", n, other_op); base.add(other_op); }, Operation::Retain(_retain) => { - log::trace!( + tracing::trace!( "invert attributes: {:?}, {:?}", operation.get_attributes(), other_op.get_attributes() diff --git a/rust-lib/flowy-ot/src/core/delta/iterator.rs b/rust-lib/flowy-ot/src/core/delta/iterator.rs index 3cec694437..6cd56cab43 100644 --- a/rust-lib/flowy-ot/src/core/delta/iterator.rs +++ b/rust-lib/flowy-ot/src/core/delta/iterator.rs @@ -154,13 +154,13 @@ impl<'a> Iterator for AttributesIter<'a> { match next_op.unwrap() { Operation::Delete(_n) => {}, Operation::Retain(retain) => { - log::trace!("extend retain attributes with {} ", &retain.attributes); + tracing::trace!("extend retain attributes with {} ", &retain.attributes); attributes.extend(retain.attributes.clone()); length = retain.n; }, Operation::Insert(insert) => { - log::trace!("extend insert attributes with {} ", &insert.attributes); + tracing::trace!("extend insert attributes with {} ", &insert.attributes); attributes.extend(insert.attributes.clone()); length = insert.num_chars(); }, diff --git a/rust-lib/flowy-ot/src/core/operation/operation.rs b/rust-lib/flowy-ot/src/core/operation/operation.rs index df1a0b4d8a..3ad32c8f3f 100644 --- a/rust-lib/flowy-ot/src/core/operation/operation.rs +++ b/rust-lib/flowy-ot/src/core/operation/operation.rs @@ -173,7 +173,7 @@ impl fmt::Display for Retain { impl Retain { pub fn merge_or_new(&mut self, n: usize, attributes: Attributes) -> Option { - log::trace!( + tracing::trace!( "merge_retain_or_new_op: len: {:?}, l: {} - r: {}", n, self.attributes, diff --git a/rust-lib/flowy-user/src/services/user/database.rs b/rust-lib/flowy-user/src/services/user/database.rs index b9aa2823e4..354b5afe13 100644 --- a/rust-lib/flowy-user/src/services/user/database.rs +++ b/rust-lib/flowy-user/src/services/user/database.rs @@ -25,7 +25,7 @@ impl UserDB { return Err(UserError::internal().context("user id is empty")); } - log::info!("open user db {}", user_id); + tracing::info!("open user db {}", user_id); let dir = format!("{}/{}", self.db_dir, user_id); let db = flowy_database::init(&dir).map_err(|e| { log::error!("init user db failed, {:?}, user_id: {}", e, user_id); diff --git a/rust-lib/flowy-user/src/services/user/user_session.rs b/rust-lib/flowy-user/src/services/user/user_session.rs index 39d640c87a..a9a35dc6e4 100644 --- a/rust-lib/flowy-user/src/services/user/user_session.rs +++ b/rust-lib/flowy-user/src/services/user/user_session.rs @@ -246,7 +246,7 @@ impl UserSession { } fn set_session(&self, session: Option) -> Result<(), UserError> { - log::debug!("Set user session: {:?}", session); + tracing::debug!("Set user session: {:?}", session); match &session { None => KV::remove(SESSION_CACHE_KEY).map_err(|e| UserError::new(ErrorCode::InternalError, &e))?, Some(session) => KV::set_str(SESSION_CACHE_KEY, session.clone().into()), @@ -297,7 +297,7 @@ impl UserSession { loop { match notify.recv().await { Ok(state) => { - log::info!("Websocket state changed: {}", state); + tracing::info!("Websocket state changed: {}", state); match state { WsState::Init => {}, WsState::Connected(_) => {}, diff --git a/rust-lib/flowy-workspace/src/services/trash_can.rs b/rust-lib/flowy-workspace/src/services/trash_can.rs index 191bcfa09d..c25330b1c0 100644 --- a/rust-lib/flowy-workspace/src/services/trash_can.rs +++ b/rust-lib/flowy-workspace/src/services/trash_can.rs @@ -223,7 +223,7 @@ impl TrashCan { spawn(async move { match server.read_trash(&token).await { Ok(repeated_trash) => { - log::debug!("Remote trash count: {}", repeated_trash.items.len()); + tracing::debug!("Remote trash count: {}", repeated_trash.items.len()); match pool.get() { Ok(conn) => { let result = conn.immediate_transaction::<_, WorkspaceError, _>(|| { diff --git a/rust-lib/flowy-workspace/src/services/workspace_controller.rs b/rust-lib/flowy-workspace/src/services/workspace_controller.rs index 0a9a95f996..552be0211d 100644 --- a/rust-lib/flowy-workspace/src/services/workspace_controller.rs +++ b/rust-lib/flowy-workspace/src/services/workspace_controller.rs @@ -263,14 +263,14 @@ impl WorkspaceController { // Opti: handle the error and retry? let workspaces = server.read_workspace(&token, params).await?; let _ = (&*conn).immediate_transaction::<_, WorkspaceError, _>(|| { - log::debug!("Save {} workspace", workspaces.len()); + tracing::debug!("Save {} workspace", workspaces.len()); for workspace in &workspaces.items { let mut m_workspace = workspace.clone(); let apps = m_workspace.apps.into_inner(); let workspace_table = WorkspaceTable::new(m_workspace, &user_id); let _ = workspace_sql.create_workspace(workspace_table, &*conn)?; - log::debug!("Save {} apps", apps.len()); + tracing::debug!("Save {} apps", apps.len()); for mut app in apps { let views = app.belongings.into_inner(); match app_ctrl.save_app(app, &*conn) { @@ -278,7 +278,7 @@ impl WorkspaceController { Err(e) => log::error!("create app failed: {:?}", e), } - log::debug!("Save {} views", views.len()); + tracing::debug!("Save {} views", views.len()); for view in views { match view_ctrl.save_view(view, &*conn) { Ok(_) => {}, diff --git a/rust-lib/flowy-ws/Cargo.toml b/rust-lib/flowy-ws/Cargo.toml index 4c0b60d78b..74e89f66df 100644 --- a/rust-lib/flowy-ws/Cargo.toml +++ b/rust-lib/flowy-ws/Cargo.toml @@ -21,6 +21,7 @@ futures-core = { version = "0.3", default-features = false } paste = "1" url = "2.2.2" log = "0.4" +tracing = { version = "0.1", features = ["log"] } protobuf = {version = "2.18.0"} strum = "0.21" strum_macros = "0.21" diff --git a/rust-lib/flowy-ws/src/connect.rs b/rust-lib/flowy-ws/src/connect.rs index 918d6fa99a..c15947930f 100644 --- a/rust-lib/flowy-ws/src/connect.rs +++ b/rust-lib/flowy-ws/src/connect.rs @@ -60,7 +60,7 @@ impl Future for WsConnectionFuture { loop { return match ready!(self.as_mut().project().fut.poll(cx)) { Ok((stream, _)) => { - log::debug!("🐴 ws connect success"); + tracing::debug!("🐴 ws connect success"); let (msg_tx, ws_rx) = ( self.msg_tx.take().expect("WsConnection should be call once "), self.ws_rx.take().expect("WsConnection should be call once "), @@ -68,7 +68,7 @@ impl Future for WsConnectionFuture { Poll::Ready(Ok(WsStream::new(msg_tx, ws_rx, stream))) }, Err(error) => { - log::debug!("🐴 ws connect failed: {:?}", error); + tracing::debug!("🐴 ws connect failed: {:?}", error); Poll::Ready(Err(error.into())) }, }; diff --git a/rust-lib/flowy-ws/src/ws.rs b/rust-lib/flowy-ws/src/ws.rs index 1020186281..ae92aa2001 100644 --- a/rust-lib/flowy-ws/src/ws.rs +++ b/rust-lib/flowy-ws/src/ws.rs @@ -171,7 +171,7 @@ async fn spawn_stream_and_handlers( } } }, - result = handlers => log::debug!("handlers completed {:?}", result), + result = handlers => tracing::debug!("handlers completed {:?}", result), }; } diff --git a/scripts/flowy-tool/src/util/file.rs b/scripts/flowy-tool/src/util/file.rs index b752866200..5b6a30d75c 100644 --- a/scripts/flowy-tool/src/util/file.rs +++ b/scripts/flowy-tool/src/util/file.rs @@ -48,7 +48,7 @@ pub fn save_content_to_file_with_diff_prompt(content: &str, output_file: &str, _ // if Confirm::new().with_prompt("Override?").interact().unwrap() { // write_to_file() // } else { - // log::info!("never mind then :("); + // tracing::info!("never mind then :("); // } // } }