Skip to content

Commit

Permalink
refactor: migrate from log to tracing (Inlyne-Project#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin271 committed Jan 7, 2024
1 parent fd07b8c commit 96db134
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 69 deletions.
131 changes: 98 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ dirs = "5.0.1"
serde = { version = "1.0.190", features = ["derive"] }
toml = "0.7.6"
reqwest = { version = "0.11.22", default-features = false, features = ["blocking", "json", "rustls-tls", "stream"] }
log = "0.4.20"
env_logger = "0.10.0"
notify = "6.1.1"
dark-light = "1.0.0"
# We only decompress our own compressed data, so disable `safe-decode` and
Expand All @@ -63,11 +61,12 @@ taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "d338f3731da519d182
syntect = "5.1.0"
smart-debug = "0.0.3"
two-face = "0.3.0"

# Required for WGPU to work properly with Vulkan
fontdb = { version = "0.13.1", features = ["fontconfig"] }
human-panic = "1.2.2"
notify-debouncer-full = { version = "0.3.1", default-features = false }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

[dependencies.glyphon]
version = "0.2"
Expand Down
16 changes: 8 additions & 8 deletions src/file_watcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct MsgHandler(mpsc::Sender<WatcherMsg>);

impl DebounceEventHandler for MsgHandler {
fn handle_event(&mut self, debounced_event: DebounceEventResult) {
log::debug!("Received debounced file events: {:#?}", debounced_event);
tracing::debug!("Received debounced file events: {:#?}", debounced_event);

match debounced_event {
Ok(events) => {
Expand All @@ -80,12 +80,12 @@ impl DebounceEventHandler for MsgHandler {
let msg = WatcherMsg::Action(action);
let _ = self.0.send(msg);
} else {
log::trace!("Ignoring events")
tracing::trace!("Ignoring events")
}
}
Err(errs) => {
for err in errs {
log::warn!("File watcher error: {err}");
tracing::warn!("File watcher error: {err}");
}
}
}
Expand Down Expand Up @@ -145,17 +145,17 @@ fn endlessly_handle_messages<C: Callback>(
while let Ok(msg) = msg_rx.recv() {
match msg {
WatcherMsg::Action(DebouncerAction::ReregisterWatcher) => {
log::debug!("File may have been renamed/removed. Falling back to polling");
tracing::debug!("File may have been renamed/removed. Falling back to polling");
poll_registering_watcher(watcher, &file_path);
log::debug!("Successfully re-registered file watcher");
tracing::debug!("Successfully re-registered file watcher");
reload_callback.file_reload();
}
WatcherMsg::Action(DebouncerAction::FileReload) => {
log::debug!("Reloading file");
tracing::debug!("Reloading file");
reload_callback.file_reload();
}
WatcherMsg::FileChange(FileChange { new_path, contents }) => {
log::info!("Updating file watcher path: {}", new_path.display());
tracing::info!("Updating file watcher path: {}", new_path.display());
let _ = watcher.unwatch(&file_path);
poll_registering_watcher(watcher, &new_path);
file_path = new_path;
Expand All @@ -164,5 +164,5 @@ fn endlessly_handle_messages<C: Callback>(
}
}

log::warn!("File watcher channel dropped unexpectedly");
tracing::warn!("File watcher channel dropped unexpectedly");
}
4 changes: 2 additions & 2 deletions src/image/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
};

let maybe_image_parts = lz4_compress(&mut adapter).ok().map(|lz4_blob| {
log::debug!(
tracing::debug!(
"Streaming image decode & compression:\n\
- Full {:.2} MiB\n\
- Compressed {:.2} MiB\n\
Expand Down Expand Up @@ -183,7 +183,7 @@ fn fallback_decode_and_compress(contents: &[u8]) -> anyhow::Result<(Vec<u8>, (u3
let image = image::load_from_memory(contents)?;
let dimensions = image.dimensions();
let image_data = image.into_rgba8().into_raw();
log::debug!(
tracing::debug!(
"Decoded full image in memory {:.3} MiB",
usize_in_mib(image_data.len()),
);
Expand Down
10 changes: 5 additions & 5 deletions src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl ImageData {
let start = Instant::now();
let lz4_blob =
decode::lz4_compress(&mut io::Cursor::new(image.as_raw())).expect("I/O is in memory");
log::debug!(
tracing::debug!(
"Compressing SVG image:\n- Full {:.2} MiB\n- Compressed {:.2} MiB\n- Time {:.2?}",
usize_in_mib(image.as_raw().len()),
usize_in_mib(lz4_blob.len()),
Expand Down Expand Up @@ -110,7 +110,7 @@ impl Image {
) -> Option<Arc<BindGroup>> {
let dimensions = self.buffer_dimensions()?;
if dimensions.0 == 0 || dimensions.1 == 0 {
log::warn!("Invalid buffer dimensions");
tracing::warn!("Invalid buffer dimensions");
return None;
}

Expand All @@ -122,7 +122,7 @@ impl Image {
.as_ref()
.map(|image| image.to_bytes())?;

log::debug!("Decompressing image: Time {:.2?}", start.elapsed());
tracing::debug!("Decompressing image: Time {:.2?}", start.elapsed());

let texture_size = wgpu::Extent3d {
width: dimensions.0,
Expand Down Expand Up @@ -200,7 +200,7 @@ impl Image {
} else if let Ok(bytes) = reqwest::blocking::get(&src).and_then(|resp| resp.bytes()) {
bytes.to_vec()
} else {
log::warn!("Request for image from {} failed", src_path.display());
tracing::warn!("Request for image from {} failed", src_path.display());
return;
};

Expand All @@ -212,7 +212,7 @@ impl Image {
fontdb.load_system_fonts();
// TODO: yes all of this image loading is very messy and could use a refactor
let Ok(mut tree) = usvg::Tree::from_data(&image_data, &opt) else {
log::warn!(
tracing::warn!(
"Failed loading image:\n- src: {}\n- src_path: {}",
src,
src_path.display()
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl HtmlInterpreter {
let mut tok = Tokenizer::new(self, TokenizerOpts::default());

for md_string in receiver {
log::debug!(
tracing::debug!(
"Recieved markdown for interpretation: {} bytes",
md_string.len()
);
Expand Down
Loading

0 comments on commit 96db134

Please sign in to comment.