config af log filter

This commit is contained in:
appflowy 2022-01-09 15:13:45 +08:00
parent 7e7254b306
commit 08a43c03d4
26 changed files with 74 additions and 46 deletions

View File

@ -10,6 +10,7 @@ extend = [
]
[env]
RUST_LOG = "info"
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
CARGO_MAKE_CRATE_FS_NAME = "dart_ffi"
CARGO_MAKE_CRATE_NAME = "dart-ffi"
@ -22,6 +23,7 @@ SDK_EXT = "a"
APP_ENVIRONMENT = "local"
[env.development-mac]
RUST_LOG = "trace"
TARGET_OS = "macos"
RUST_COMPILE_TARGET = "x86_64-apple-darwin"
BUILD_FLAG = "debug"

View File

@ -10,6 +10,20 @@
"program": "${workspaceRoot}/lib/main.dart",
"type": "dart",
"preLaunchTask": "build_flowy_sdk",
"env":{
"RUST_LOG":"info",
},
"cwd": "${workspaceRoot}"
},
{
"name": "app_flowy(trace)",
"request": "launch",
"program": "${workspaceRoot}/lib/main.dart",
"type": "dart",
"preLaunchTask": "build_flowy_sdk",
"env":{
"RUST_LOG":"trace",
},
"cwd": "${workspaceRoot}"
},
{

View File

@ -130,13 +130,11 @@ impl CoreContext {
return Ok(());
}
}
tracing::debug!("Start initializing flowy core");
INIT_WORKSPACE.write().insert(token.to_owned(), true);
let _ = self.workspace_controller.init()?;
let _ = self.app_controller.init()?;
let _ = self.view_controller.init()?;
let _ = self.trash_controller.init()?;
tracing::debug!("Finish initializing core");
Ok(())
}

View File

@ -18,6 +18,7 @@ use tokio::sync::{mpsc, mpsc::UnboundedSender, oneshot};
pub struct ClientDocumentEditor {
pub doc_id: String,
#[allow(dead_code)]
rev_manager: Arc<DocumentRevisionManager>,
ws_manager: Arc<dyn DocumentWebSocketManager>,
edit_queue: UnboundedSender<EditorCommand>,

View File

@ -58,7 +58,7 @@ impl EditorCommandQueue {
.await;
}
#[tracing::instrument(level = "debug", skip(self), err)]
#[tracing::instrument(level = "trace", skip(self), err)]
async fn handle_command(&self, command: EditorCommand) -> Result<(), FlowyError> {
match command {
EditorCommand::ComposeLocalDelta { delta, ret } => {
@ -289,6 +289,7 @@ pub(crate) enum EditorCommand {
ReadDoc {
ret: Ret<String>,
},
#[allow(dead_code)]
ReadDocDelta {
ret: Ret<RichTextDelta>,
},

View File

@ -109,7 +109,7 @@ impl DocumentRevisionCache {
}
#[tracing::instrument(level = "debug", skip(self, doc_id, revisions))]
pub async fn reset_document(&self, doc_id: &str, revisions: Vec<Revision>) -> FlowyResult<()> {
pub async fn reset_with_revisions(&self, doc_id: &str, revisions: Vec<Revision>) -> FlowyResult<()> {
let revision_records = revisions
.to_vec()
.into_iter()

View File

@ -120,7 +120,11 @@ impl RevisionTableSql {
.filter(dsl::rev_id.eq(changeset.rev_id.as_ref()))
.filter(dsl::doc_id.eq(changeset.doc_id));
let _ = update(filter).set(dsl::state.eq(changeset.state)).execute(conn)?;
tracing::debug!("Save revision:{} state to {:?}", changeset.rev_id, changeset.state);
tracing::debug!(
"[[RevisionTable]] Save:{} state to {:?}",
changeset.rev_id,
changeset.state
);
Ok(())
}
@ -170,7 +174,7 @@ impl RevisionTableSql {
}
let affected_row = sql.execute(conn)?;
tracing::debug!("Delete {} revision rows", affected_row);
tracing::trace!("[RevisionTable] Delete {} rows", affected_row);
Ok(())
}
}

View File

@ -60,7 +60,10 @@ impl DocumentRevisionManager {
#[tracing::instrument(level = "debug", skip(self, revisions), err)]
pub async fn reset_document(&self, revisions: RepeatedRevision) -> FlowyResult<()> {
let rev_id = pair_rev_id_from_revisions(&revisions).1;
let _ = self.cache.reset_document(&self.doc_id, revisions.into_inner()).await?;
let _ = self
.cache
.reset_with_revisions(&self.doc_id, revisions.into_inner())
.await?;
self.rev_id_counter.set(rev_id);
Ok(())
}

View File

@ -181,7 +181,7 @@ impl DocumentWSStream {
.await
.map_err(internal_error)?;
tracing::debug!("[DocumentStream]: new message: {:?}", ty);
tracing::trace!("[DocumentStream]: new message: {:?}", ty);
match ty {
DocumentServerWSDataType::ServerPushRev => {
let _ = self.consumer.receive_push_revision(bytes).await?;
@ -272,7 +272,7 @@ impl DocumentWSSink {
Ok(())
},
Some(data) => {
tracing::debug!("[DocumentSink]: send: {}:{}-{:?}", data.doc_id, data.id(), data.ty);
tracing::trace!("[DocumentSink]: send: {}:{}-{:?}", data.doc_id, data.id(), data.ty);
self.ws_sender.send(data)
// let _ = tokio::time::timeout(Duration::from_millis(2000),
},

View File

@ -55,6 +55,18 @@ async fn document_sync_insert_in_chinese() {
EditorTest::new().await.run_scripts(scripts).await;
}
#[tokio::test]
async fn document_sync_insert_with_emoji() {
let s = "😁".to_owned();
let offset = count_utf16_code_units(&s);
let scripts = vec![
InsertText("😁", 0),
InsertText("☺️", offset),
AssertJson(r#"[{"insert":"😁☺️\n"}]"#),
];
EditorTest::new().await.run_scripts(scripts).await;
}
#[tokio::test]
async fn document_sync_delete_in_english() {
let scripts = vec![

View File

@ -40,7 +40,7 @@ impl LocalDocumentServer {
client_data: DocumentClientWSData,
user_id: String,
) -> Result<(), CollaborateError> {
tracing::debug!(
tracing::trace!(
"[LocalDocumentServer] receive: {}:{}-{:?} ",
client_data.doc_id,
client_data.id(),
@ -72,7 +72,7 @@ struct LocalDocServerPersistence {
}
impl Debug for LocalDocServerPersistence {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { f.write_str("MockDocServerPersistence") }
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { f.write_str("LocalDocServerPersistence") }
}
impl std::default::Default for LocalDocServerPersistence {
@ -89,10 +89,7 @@ impl DocumentPersistence for LocalDocServerPersistence {
let doc_id = doc_id.to_owned();
Box::pin(async move {
match inner.get(&doc_id) {
None => {
//
Err(CollaborateError::record_not_found())
},
None => Err(CollaborateError::record_not_found()),
Some(val) => {
//
Ok(val.value().clone())

View File

@ -53,19 +53,19 @@ impl FlowySDKConfig {
FlowySDKConfig {
name: name.to_owned(),
root: root.to_owned(),
log_filter: crate_log_filter(None),
log_filter: crate_log_filter("info".to_owned()),
server_config,
}
}
pub fn log_filter(mut self, filter: &str) -> Self {
self.log_filter = crate_log_filter(Some(filter.to_owned()));
self.log_filter = crate_log_filter(filter.to_owned());
self
}
}
fn crate_log_filter(level: Option<String>) -> String {
let level = level.unwrap_or_else(|| std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_owned()));
fn crate_log_filter(level: String) -> String {
let level = std::env::var("RUST_LOG").unwrap_or(level);
let mut filters = vec![];
filters.push(format!("flowy_sdk={}", level));
filters.push(format!("flowy_core={}", level));
@ -73,6 +73,8 @@ fn crate_log_filter(level: Option<String>) -> String {
filters.push(format!("flowy_document={}", level));
filters.push(format!("flowy_collaboration={}", level));
filters.push(format!("flowy_net={}", level));
filters.push(format!("dart_ffi={}", "info"));
filters.push(format!("dart_database={}", "info"));
filters.push(format!("dart_notify={}", level));
filters.push(format!("lib_ot={}", level));
filters.push(format!("lib_ws={}", level));

View File

@ -34,7 +34,7 @@ impl std::default::Default for FlowySDKTest {
impl FlowySDKTest {
pub fn new(server_config: ClientServerConfiguration) -> Self {
let config = FlowySDKConfig::new(&root_dir(), server_config, &uuid_string()).log_filter("debug");
let config = FlowySDKConfig::new(&root_dir(), server_config, &uuid_string()).log_filter("trace");
let sdk = FlowySDK::new(config);
std::mem::forget(sdk.dispatcher());
Self { inner: sdk }

View File

@ -69,6 +69,7 @@ impl Document {
pub fn set_notify(&mut self, notify: mpsc::UnboundedSender<()>) { self.notify = Some(notify); }
pub fn set_delta(&mut self, data: RichTextDelta) {
tracing::trace!("document: {}", data.to_json());
self.delta = data;
match &self.notify {
@ -80,7 +81,6 @@ impl Document {
}
pub fn compose_delta(&mut self, delta: RichTextDelta) -> Result<(), CollaborateError> {
tracing::trace!("👉 receive change: {}", delta);
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);
@ -97,13 +97,11 @@ impl Document {
self.last_edit_time = now;
}
tracing::trace!("👉 receive change undo: {}", undo_delta);
if !undo_delta.is_empty() {
tracing::trace!("add history delta: {}", undo_delta);
self.history.record(undo_delta);
}
tracing::trace!("compose result: {}", composed_delta.to_json());
self.set_delta(composed_delta);
Ok(())
}
@ -133,7 +131,7 @@ impl Document {
attribute: RichTextAttribute,
) -> Result<RichTextDelta, CollaborateError> {
let _ = validate_interval(&self.delta, &interval)?;
tracing::trace!("format with {} at {}", attribute, interval);
tracing::trace!("format {} with {}", interval, attribute);
let format_delta = self.view.format(&self.delta, attribute, interval).unwrap();
self.compose_delta(format_delta.clone())?;
Ok(format_delta)
@ -192,7 +190,6 @@ impl Document {
// c = a.compose(b)
// d = b.invert(a)
// a = c.compose(d)
tracing::trace!("Invert {}", delta);
let new_delta = self.delta.compose(delta)?;
let inverted_delta = delta.invert(&self.delta);
Ok((new_delta, inverted_delta))

View File

@ -10,7 +10,7 @@ use crate::{
pub struct ResolveBlockFormat {}
impl FormatExt for ResolveBlockFormat {
fn ext_name(&self) -> &str { std::any::type_name::<ResolveBlockFormat>() }
fn ext_name(&self) -> &str { "ResolveBlockFormat" }
fn apply(&self, delta: &RichTextDelta, interval: Interval, attribute: &RichTextAttribute) -> Option<RichTextDelta> {
if attribute.scope != AttributeScope::Block {

View File

@ -10,7 +10,7 @@ use crate::{
pub struct ResolveInlineFormat {}
impl FormatExt for ResolveInlineFormat {
fn ext_name(&self) -> &str { std::any::type_name::<ResolveInlineFormat>() }
fn ext_name(&self) -> &str { "ResolveInlineFormat" }
fn apply(&self, delta: &RichTextDelta, interval: Interval, attribute: &RichTextAttribute) -> Option<RichTextDelta> {
if attribute.scope != AttributeScope::Inline {

View File

@ -7,7 +7,7 @@ use lib_ot::{
pub struct AutoExitBlock {}
impl InsertExt for AutoExitBlock {
fn ext_name(&self) -> &str { std::any::type_name::<AutoExitBlock>() }
fn ext_name(&self) -> &str { "AutoExitBlock" }
fn apply(&self, delta: &RichTextDelta, replace_len: usize, text: &str, index: usize) -> Option<RichTextDelta> {
// Auto exit block will be triggered by enter two new lines

View File

@ -8,7 +8,7 @@ use url::Url;
pub struct AutoFormatExt {}
impl InsertExt for AutoFormatExt {
fn ext_name(&self) -> &str { std::any::type_name::<AutoFormatExt>() }
fn ext_name(&self) -> &str { "AutoFormatExt" }
fn apply(&self, delta: &RichTextDelta, replace_len: usize, text: &str, index: usize) -> Option<RichTextDelta> {
// enter whitespace to trigger auto format

View File

@ -6,7 +6,7 @@ use lib_ot::{
pub struct DefaultInsertAttribute {}
impl InsertExt for DefaultInsertAttribute {
fn ext_name(&self) -> &str { std::any::type_name::<DefaultInsertAttribute>() }
fn ext_name(&self) -> &str { "DefaultInsertAttribute" }
fn apply(&self, delta: &RichTextDelta, replace_len: usize, text: &str, index: usize) -> Option<RichTextDelta> {
let iter = DeltaIter::new(delta);

View File

@ -13,7 +13,7 @@ use lib_ot::{
pub struct PreserveBlockFormatOnInsert {}
impl InsertExt for PreserveBlockFormatOnInsert {
fn ext_name(&self) -> &str { std::any::type_name::<PreserveBlockFormatOnInsert>() }
fn ext_name(&self) -> &str { "PreserveBlockFormatOnInsert" }
fn apply(&self, delta: &RichTextDelta, replace_len: usize, text: &str, index: usize) -> Option<RichTextDelta> {
if !is_newline(text) {

View File

@ -9,7 +9,7 @@ use lib_ot::{
pub struct PreserveInlineFormat {}
impl InsertExt for PreserveInlineFormat {
fn ext_name(&self) -> &str { std::any::type_name::<PreserveInlineFormat>() }
fn ext_name(&self) -> &str { "PreserveInlineFormat" }
fn apply(&self, delta: &RichTextDelta, replace_len: usize, text: &str, index: usize) -> Option<RichTextDelta> {
if contain_newline(text) {
@ -53,7 +53,7 @@ impl InsertExt for PreserveInlineFormat {
pub struct PreserveLineFormatOnSplit {}
impl InsertExt for PreserveLineFormatOnSplit {
fn ext_name(&self) -> &str { std::any::type_name::<PreserveLineFormatOnSplit>() }
fn ext_name(&self) -> &str { "PreserveLineFormatOnSplit" }
fn apply(&self, delta: &RichTextDelta, replace_len: usize, text: &str, index: usize) -> Option<RichTextDelta> {
if !is_newline(text) {

View File

@ -6,7 +6,7 @@ use lib_ot::{
pub struct ResetLineFormatOnNewLine {}
impl InsertExt for ResetLineFormatOnNewLine {
fn ext_name(&self) -> &str { std::any::type_name::<ResetLineFormatOnNewLine>() }
fn ext_name(&self) -> &str { "ResetLineFormatOnNewLine" }
fn apply(&self, delta: &RichTextDelta, replace_len: usize, text: &str, index: usize) -> Option<RichTextDelta> {
if !is_newline(text) {

View File

@ -32,7 +32,7 @@ impl View {
for ext in &self.insert_exts {
if let Some(mut delta) = ext.apply(delta, interval.size(), text, interval.start) {
trim(&mut delta);
tracing::debug!("[{}]: process delta: {}", ext.ext_name(), delta);
tracing::debug!("[{} extension]: process: {}", ext.ext_name(), delta);
new_delta = Some(delta);
break;
}

View File

@ -89,7 +89,7 @@ impl ServerDocumentManager {
let doc_id = client_data.doc_id.clone();
match self.get_document_handler(&doc_id).await {
None => {
tracing::warn!("Document:{} doesn't exist, ignore pinging", doc_id);
tracing::trace!("Document:{} doesn't exist, ignore pinging", doc_id);
Ok(())
},
Some(handler) => {

View File

@ -111,7 +111,7 @@ impl RevisionSynchronizer {
Ok(())
}
#[tracing::instrument(level = "debug", skip(self, user, persistence), fields(server_rev_id), err)]
#[tracing::instrument(level = "trace", skip(self, user, persistence), fields(server_rev_id), err)]
pub async fn pong(
&self,
user: Arc<dyn RevisionUser>,
@ -125,7 +125,7 @@ impl RevisionSynchronizer {
Ordering::Less => {
tracing::error!("Client should not send ping and the server should pull the revisions from the client")
},
Ordering::Equal => tracing::debug!("{} is up to date.", doc_id),
Ordering::Equal => tracing::trace!("{} is up to date.", doc_id),
Ordering::Greater => {
// The client document is outdated. Transform the client revision delta and then
// send the prime delta to the client. Client should compose the this prime

View File

@ -394,9 +394,7 @@ where
if other.is_empty() {
return inverted;
}
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;
@ -409,20 +407,19 @@ where
match op.has_attribute() {
true => invert_from_other(&mut inverted, other, op, index, index + len),
false => {
tracing::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(_) => {
tracing::trace!("invert insert: {} by delete {}", op, len);
// tracing::trace!("invert insert: {} by delete {}", op, len);
inverted.delete(len as usize);
},
}
}
tracing::trace!("🌛invert result: {}", inverted);
inverted
}
}