Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

add logger

appflowy6fe196e97f0e
diff --git a/.idea/appflowy_client.iml b/.idea/appflowy_client.iml
index 12b5c938f9..94f61ad366 100644
--- a/.idea/appflowy_client.iml
+++ b/.idea/appflowy_client.iml
@@ -8,6 +8,7 @@
<sourceFolder url="file://$MODULE_DIR$/rust-lib/flowy-sys/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/rust-lib/flowy-sys/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/rust-lib/dart-ffi/src" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/rust-lib/flowy-log/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/rust-lib/flowy-sdk/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/af_protobuf/.pub" />
<excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/af_protobuf/.dart_tool" />
diff --git a/rust-lib/Cargo.toml b/rust-lib/Cargo.toml
index 5d0ec862f2..3424af727f 100644
--- a/rust-lib/Cargo.toml
+++ b/rust-lib/Cargo.toml
@@ -3,6 +3,7 @@ members = [
"flowy-sys",
"flowy-sdk",
"dart-ffi",
+ "flowy-log",
]
[profile.dev]
diff --git a/rust-lib/flowy-log/Cargo.toml b/rust-lib/flowy-log/Cargo.toml
new file mode 100644
index 0000000000..957bde80c1
--- /dev/null
+++ b/rust-lib/flowy-log/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+name = "flowy-log"
+version = "0.1.0"
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+tracing = { version = "0.1", features = ["log"] }
+tracing-log = "0.1.1"
+tracing-futures = "0.2.4"
+tracing-subscriber = { version = "0.2.12", features = ["registry", "env-filter"] }
+tracing-bunyan-formatter = "0.2.2"
+log = "0.4.14"
\ No newline at end of file
diff --git a/rust-lib/flowy-log/src/lib.rs b/rust-lib/flowy-log/src/lib.rs
new file mode 100644
index 0000000000..d402821c00
--- /dev/null
+++ b/rust-lib/flowy-log/src/lib.rs
@@ -0,0 +1,35 @@
+use log::SetLoggerError;
+use tracing::subscriber::set_global_default;
+use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
+use tracing_log::LogTracer;
+use tracing_subscriber::{layer::SubscriberExt, EnvFilter};
+
+pub fn init_log(name: &str, env_filter: &str) -> std::Result<(), SetLoggerError> {
+ let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(env_filter.to_owned()));
+ let formatting_layer = BunyanFormattingLayer::new(name.to_owned(), std::io::stdout);
+ let subscriber = tracing_subscriber::fmt()
+ .with_target(false)
+ .with_thread_ids(false)
+ .with_target(false)
+ .compact()
+ .finish()
+ .with(env_filter)
+ .with(JsonStorageLayer)
+ .with(formatting_layer);
+
+ let _ = LogTracer::init()?;
+ let _ = set_global_default(subscriber)?;
+ Ok(())
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_log() {
+ init_log("flowy-log", "info");
+ tracing::info!("😁 Tracing info log");
+ log::info!("😁 bridge 'log' to 'tracing'");
+ }
+}