Skip to content

Commit e37256c

Browse files
authored
refactor: hide tracing logs behind 'logging' feature (#728)
* refactor: hide tracing logs behind 'logging' feature * fix: grammar err
1 parent 93fb2fd commit e37256c

29 files changed

Lines changed: 72 additions & 119 deletions

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ release = false
1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

1212
[dependencies]
13-
loro = { path = "../loro", features = ["counter"], package = "loro" }
13+
loro = { path = "../loro", features = ["counter", "logging"], package = "loro" }
1414
loro-without-counter = { git = "https://github.com/loro-dev/loro.git", rev = "90470658435ec4c62b5af59ebb82fe9e1f5aa761", package = "loro", default-features = false }
1515
loro-016 = { git = "https://github.com/loro-dev/loro.git", tag = "loro-crdt@0.16.7", package = "loro" }
1616
fxhash = { workspace = true }

crates/fuzz/src/actor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use loro::{
1414
};
1515
use pretty_assertions::assert_eq;
1616
use rand::{rngs::StdRng, Rng, SeedableRng};
17-
use tracing::info_span;
17+
use tracing::{info, info_span};
1818

1919
use crate::{
2020
container::{CounterActor, ListActor, MovableListActor, TextActor, TreeActor},
@@ -373,7 +373,7 @@ impl Actor {
373373
.loro
374374
.export_json_updates(&Default::default(), &self.loro.oplog_vv());
375375
let string = serde_json::to_string_pretty(&json).unwrap();
376-
tracing::info!("vv={:?} json = {}", self.loro.oplog_vv(), string);
376+
info!("vv={:?} json = {}", self.loro.oplog_vv(), string);
377377
}
378378
}
379379

crates/fuzz/src/container/tree.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use loro::{
99
event::Diff, Container, ContainerID, ContainerType, LoroDoc, LoroError, LoroTree, LoroValue,
1010
TreeExternalDiff, TreeID,
1111
};
12-
use tracing::trace;
1312

1413
use crate::{
1514
actions::{Actionable, FromGenericAction, GenericAction},
@@ -399,7 +398,6 @@ impl TreeTracker {
399398
) {
400399
let node = TreeNode::new(target, *parent, position);
401400
if let Some(parent) = parent {
402-
trace!("Parent {:?} target {:?}", parent, target);
403401
let parent = self.find_node_by_id_mut(*parent).unwrap();
404402
parent.children.insert(*index, node);
405403
} else {
@@ -440,7 +438,6 @@ impl ApplyDiff for TreeTracker {
440438
self.create_node(target, &parent.tree_id(), position.to_string(), index);
441439
}
442440
TreeExternalDiff::Delete { .. } => {
443-
trace!("To delete {:?}", &target);
444441
let node = self.find_node_by_id(target).unwrap();
445442
if let Some(parent) = node.parent {
446443
let parent = self.find_node_by_id_mut(parent).unwrap();

crates/fuzz/src/crdt_fuzzer.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use arbitrary::Arbitrary;
1010
use fxhash::FxHashSet;
1111
use loro::{ContainerType, Frontiers, ImportStatus, LoroError, LoroResult};
1212
use tabled::TableIteratorExt;
13-
use tracing::{info, info_span, trace};
13+
use tracing::{info, info_span};
1414

1515
use crate::{actions::ActionWrapper, array_mut_ref};
1616

@@ -409,11 +409,9 @@ pub fn test_multi_sites_with_gc(
409409
match (i + j) % 4 {
410410
0 => {
411411
info_span!("Updates", from = j, to = i).in_scope(|| {
412-
trace!("a.vv = {:?}", a_doc.oplog_vv());
413412
a_doc.import(&b_doc.export_from(&a_doc.oplog_vv())).unwrap();
414413
});
415414
info_span!("Updates", from = i, to = j).in_scope(|| {
416-
trace!("b.vv = {:?}", b_doc.oplog_vv());
417415
b_doc.import(&a_doc.export_from(&b_doc.oplog_vv())).unwrap();
418416
});
419417
}
@@ -456,11 +454,9 @@ pub fn test_multi_sites_with_gc(
456454
let a_doc = &mut a.loro;
457455
let b_doc = &mut b.loro;
458456
info_span!("Updates", from = j, to = i).in_scope(|| {
459-
trace!("a.vv = {:?}", a_doc.oplog_vv());
460457
a_doc.import(&b_doc.export_from(&a_doc.oplog_vv())).unwrap();
461458
});
462459
info_span!("Updates", from = i, to = j).in_scope(|| {
463-
trace!("b.vv = {:?}", b_doc.oplog_vv());
464460
b_doc.import(&a_doc.export_from(&b_doc.oplog_vv())).unwrap();
465461
});
466462
}
@@ -480,10 +476,6 @@ pub fn test_multi_sites_with_gc(
480476
.import(&a.loro.export_from(&b.loro.oplog_vv()))
481477
.unwrap();
482478
});
483-
let json = b
484-
.loro
485-
.export_json_updates(&Default::default(), &b.loro.oplog_vv());
486-
trace!("Changes on 1 = {:#?}", json);
487479
let result = info_span!("1 => 0")
488480
.in_scope(|| a.loro.import(&b.loro.export_from(&a.loro.oplog_vv())));
489481
match result {

crates/fuzz/src/one_doc_fuzzer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use loro::{ContainerType, Frontiers, LoroDoc, LoroError, TreeID};
22
use tabled::TableIteratorExt;
3-
use tracing::{info, info_span, trace};
3+
use tracing::{info, info_span};
44

55
use crate::{actions::ActionWrapper, crdt_fuzzer::FuzzValue, Action};
66

@@ -365,7 +365,6 @@ impl OneDocFuzzer {
365365
}
366366
}
367367
Action::Sync { from, to } => {
368-
trace!("vv={:?}", self.doc.oplog_vv());
369368
let mut f = self.branches[*from as usize].frontiers.clone();
370369
f.merge_with_greater(&self.branches[*to as usize].frontiers);
371370
self.branches[*to as usize].frontiers = self.doc.minimize_frontiers(&f).unwrap();

crates/loro-common/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ keywords = ["crdt", "local-first"]
1616
[dependencies]
1717
rle = { path = "../rle", version = "1.2.7", package = "loro-rle" }
1818
serde = { workspace = true }
19-
serde_json = { workspace = true, optional=true }
19+
serde_json = { workspace = true, optional = true }
2020
thiserror = "1.0.43"
2121
wasm-bindgen = { version = "=0.2.100", optional = true }
2222
fxhash = "0.2.1"
@@ -26,7 +26,9 @@ js-sys = { version = "0.3.60", optional = true }
2626
serde_columnar = { workspace = true }
2727
nonmax = "0.5.5"
2828
leb128 = "0.2.5"
29+
tracing = { workspace = true, optional = true}
2930

3031
[features]
3132
wasm = ["wasm-bindgen", "js-sys"]
33+
logging = ["tracing"]
3234
counter = []

crates/loro-common/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
99
mod error;
1010
mod id;
1111
mod internal_string;
12+
mod logging;
1213
mod macros;
1314
mod span;
1415
mod value;
@@ -17,6 +18,7 @@ pub use error::{LoroEncodeError, LoroError, LoroResult, LoroTreeError};
1718
#[doc(hidden)]
1819
pub use fxhash::FxHashMap;
1920
pub use internal_string::InternalString;
21+
pub use logging::log::*;
2022
pub use span::*;
2123
pub use value::{
2224
to_value, LoroBinaryValue, LoroListValue, LoroMapValue, LoroStringValue, LoroValue,

crates/loro-common/src/logging.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#[cfg(not(feature = "logging"))]
2+
pub mod log {
3+
#[macro_export]
4+
macro_rules! info {
5+
($($t:tt)*) => {};
6+
}
7+
#[macro_export]
8+
macro_rules! trace {
9+
($($t:tt)*) => {};
10+
}
11+
#[macro_export]
12+
macro_rules! debug {
13+
($($t:tt)*) => {};
14+
}
15+
#[macro_export]
16+
macro_rules! error {
17+
($($t:tt)*) => {};
18+
}
19+
#[macro_export]
20+
macro_rules! warn {
21+
($($t:tt)*) => {};
22+
}
23+
}
24+
25+
#[cfg(feature = "logging")]
26+
pub mod log {
27+
pub use tracing::{debug, error, info, trace, warn};
28+
}

crates/loro-internal/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ wasm = ["wasm-bindgen", "js-sys", "loro-common/wasm"]
9797
test_utils = ["arbitrary", "tabled"]
9898
# whether enable the counter container
9999
counter = ["loro-common/counter"]
100+
logging = ["loro-common/logging"]
100101
jsonpath = []
101102

102103
[[bench]]

0 commit comments

Comments
 (0)