chore: pass platform info to rust side (#5079)

* chore: pass platform info to rust side

* chore: pass platform info to rust side

* chore: fix test

* chore: fix test

* chore: fix test

* chore: enable ios log
This commit is contained in:
Nathan.fooo
2024-04-07 21:36:55 +08:00
committed by GitHub
parent 81594fa796
commit 3e32fac876
35 changed files with 465 additions and 200 deletions

View File

@ -68,4 +68,9 @@ ts = [
]
rev-sqlite = ["flowy-user/rev-sqlite"]
openssl_vendored = ["flowy-sqlite/openssl_vendored"]
verbose_log = ["flowy-document/verbose_log", "client-api/sync_verbose_log"]
# Enable/Disable AppFlowy Verbose Log Configuration
verbose_log = [
# "flowy-document/verbose_log",
"client-api/sync_verbose_log"
]

View File

@ -8,6 +8,7 @@ use flowy_server_pub::af_cloud_config::AFCloudConfiguration;
use flowy_server_pub::supabase_config::SupabaseConfiguration;
use flowy_user::services::entities::URL_SAFE_ENGINE;
use lib_infra::file_util::copy_dir_recursive;
use lib_infra::util::Platform;
use crate::integrate::log::create_log_filter;
@ -17,6 +18,7 @@ pub struct AppFlowyCoreConfig {
pub(crate) app_version: String,
pub(crate) name: String,
pub(crate) device_id: String,
pub platform: String,
/// Used to store the user data
pub storage_path: String,
/// Origin application path is the path of the application binary. By default, the
@ -77,6 +79,7 @@ impl AppFlowyCoreConfig {
custom_application_path: String,
application_path: String,
device_id: String,
platform: String,
name: String,
) -> Self {
let cloud_config = AFCloudConfiguration::from_env().ok();
@ -90,6 +93,7 @@ impl AppFlowyCoreConfig {
},
Some(config) => make_user_data_folder(&custom_application_path, &config.base_url),
};
let log_filter = create_log_filter("info".to_owned(), vec![], Platform::from(&platform));
AppFlowyCoreConfig {
app_version,
@ -97,13 +101,18 @@ impl AppFlowyCoreConfig {
storage_path,
application_path,
device_id,
log_filter: create_log_filter("info".to_owned(), vec![]),
platform,
log_filter,
cloud_config,
}
}
pub fn log_filter(mut self, level: &str, with_crates: Vec<String>) -> Self {
self.log_filter = create_log_filter(level.to_owned(), with_crates);
self.log_filter = create_log_filter(
level.to_owned(),
with_crates,
Platform::from(&self.platform),
);
self
}
}

View File

@ -1,9 +1,16 @@
use lib_infra::util::Platform;
use lib_log::stream_log::StreamLogSender;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use crate::AppFlowyCoreConfig;
static INIT_LOG: AtomicBool = AtomicBool::new(false);
pub(crate) fn init_log(config: &AppFlowyCoreConfig) {
pub(crate) fn init_log(
config: &AppFlowyCoreConfig,
platform: &Platform,
stream_log_sender: Option<Arc<dyn StreamLogSender>>,
) {
#[cfg(debug_assertions)]
if get_bool_from_env_var("DISABLE_CI_TEST_LOG") {
return;
@ -12,14 +19,24 @@ pub(crate) fn init_log(config: &AppFlowyCoreConfig) {
if !INIT_LOG.load(Ordering::SeqCst) {
INIT_LOG.store(true, Ordering::SeqCst);
let _ = lib_log::Builder::new("log", &config.storage_path)
let _ = lib_log::Builder::new("log", &config.storage_path, platform, stream_log_sender)
.env_filter(&config.log_filter)
.build();
}
}
pub(crate) fn create_log_filter(level: String, with_crates: Vec<String>) -> String {
let level = std::env::var("RUST_LOG").unwrap_or(level);
pub(crate) fn create_log_filter(
level: String,
with_crates: Vec<String>,
platform: Platform,
) -> String {
let mut level = std::env::var("RUST_LOG").unwrap_or(level);
#[cfg(debug_assertions)]
if matches!(platform, Platform::IOS) {
level = "trace".to_string();
}
let mut filters = with_crates
.into_iter()
.map(|crate_name| format!("{}={}", crate_name, level))

View File

@ -20,6 +20,8 @@ use flowy_user::user_manager::UserManager;
use lib_dispatch::prelude::*;
use lib_dispatch::runtime::AFPluginRuntime;
use lib_infra::priority_task::{TaskDispatcher, TaskRunner};
use lib_infra::util::Platform;
use lib_log::stream_log::StreamLogSender;
use module::make_plugins;
use crate::config::AppFlowyCoreConfig;
@ -53,16 +55,13 @@ pub struct AppFlowyCore {
}
impl AppFlowyCore {
pub async fn new(config: AppFlowyCoreConfig, runtime: Arc<AFPluginRuntime>) -> Self {
Self::init(config, runtime).await
}
pub async fn new(
config: AppFlowyCoreConfig,
runtime: Arc<AFPluginRuntime>,
stream_log_sender: Option<Arc<dyn StreamLogSender>>,
) -> Self {
let platform = Platform::from(&config.platform);
pub fn close_db(&self) {
self.user_manager.close_db();
}
#[instrument(skip(config, runtime))]
async fn init(config: AppFlowyCoreConfig, runtime: Arc<AFPluginRuntime>) -> Self {
#[allow(clippy::if_same_then_else)]
if cfg!(debug_assertions) {
/// The profiling can be used to tracing the performance of the application.
@ -73,15 +72,29 @@ impl AppFlowyCore {
// Init the logger before anything else
#[cfg(not(feature = "profiling"))]
init_log(&config);
init_log(&config, &platform, stream_log_sender);
} else {
init_log(&config);
init_log(&config, &platform, stream_log_sender);
}
info!(
"💡{:?}, platform: {:?}",
System::long_os_version(),
platform
);
Self::init(config, runtime).await
}
pub fn close_db(&self) {
self.user_manager.close_db();
}
#[instrument(skip(config, runtime))]
async fn init(config: AppFlowyCoreConfig, runtime: Arc<AFPluginRuntime>) -> Self {
// Init the key value database
let store_preference = Arc::new(StorePreferences::new(&config.storage_path).unwrap());
info!("🔥{:?}", &config);
info!("💡System info: {:?}", System::long_os_version());
let task_scheduler = TaskDispatcher::new(Duration::from_secs(2));
let task_dispatcher = Arc::new(RwLock::new(task_scheduler));