mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
add logger
This commit is contained in:
parent
d867093bf5
commit
6fe196e97f
@ -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" />
|
||||
|
@ -3,6 +3,7 @@ members = [
|
||||
"flowy-sys",
|
||||
"flowy-sdk",
|
||||
"dart-ffi",
|
||||
"flowy-log",
|
||||
]
|
||||
|
||||
[profile.dev]
|
||||
|
14
rust-lib/flowy-log/Cargo.toml
Normal file
14
rust-lib/flowy-log/Cargo.toml
Normal file
@ -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"
|
35
rust-lib/flowy-log/src/lib.rs
Normal file
35
rust-lib/flowy-log/src/lib.rs
Normal file
@ -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'");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user