Use tracing for logging
This commit is contained in:
parent
f255af9f6a
commit
4d6d771ab4
36 changed files with 260 additions and 223 deletions
|
|
@ -58,7 +58,7 @@ impl imp::LpImage {
|
|||
pub async fn background_color_guess(&self) -> Option<gdk::RGBA> {
|
||||
let obj = self.obj();
|
||||
|
||||
log::debug!("Determining background color");
|
||||
tracing::debug!("Determining background color");
|
||||
|
||||
if self.fixed_background_color.borrow().is_some() {
|
||||
return None;
|
||||
|
|
@ -66,7 +66,7 @@ impl imp::LpImage {
|
|||
|
||||
// Shortcut for formats that don't support transparency
|
||||
if !obj.metadata().is_potentially_transparent() {
|
||||
log::trace!("This format does not support transparency");
|
||||
tracing::trace!("This format does not support transparency");
|
||||
return Some(Self::default_background_color());
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ impl imp::LpImage {
|
|||
}
|
||||
|
||||
if !has_transparency {
|
||||
log::trace!("This image does not have transparency");
|
||||
tracing::trace!("This image does not have transparency");
|
||||
return Some(default_color);
|
||||
}
|
||||
|
||||
|
|
@ -163,8 +163,8 @@ impl imp::LpImage {
|
|||
1.
|
||||
};
|
||||
|
||||
log::trace!("Total: {n_pixels}, transparent: {completely_transparent}, bad contrast: {bad_contrast}");
|
||||
log::trace!("Amount bad contrast: {part_bad_contrast}");
|
||||
tracing::trace!("Total: {n_pixels}, transparent: {completely_transparent}, bad contrast: {bad_contrast}");
|
||||
tracing::trace!("Amount bad contrast: {part_bad_contrast}");
|
||||
|
||||
if part_bad_contrast > BACKGROUND_GUESS_LOW_CONTRAST_TRHESHOLD {
|
||||
Some(alternate_color)
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ impl LpImage {
|
|||
if let Some(node) = tmp_snapshot.to_node() {
|
||||
imp.apply_operations(node, >k::Snapshot::new())?;
|
||||
} else {
|
||||
log::error!("Render node is empty");
|
||||
tracing::error!("Render node is empty");
|
||||
}
|
||||
|
||||
imp.configure_best_fit();
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ impl imp::LpImage {
|
|||
(f64::exp(-y * f64::ln(ZOOM_FACTOR_SCROLL_SURFACE)), false)
|
||||
}
|
||||
unknown_unit => {
|
||||
log::warn!("Ignoring unknown scroll unit: {unknown_unit:?}");
|
||||
tracing::warn!("Ignoring unknown scroll unit: {unknown_unit:?}");
|
||||
(1., false)
|
||||
}
|
||||
};
|
||||
|
|
@ -142,12 +142,12 @@ impl imp::LpImage {
|
|||
move |gesture, n_press, x, y| {
|
||||
// only handle double clicks
|
||||
if n_press != 2 {
|
||||
log::trace!("Gesture {n_press} click");
|
||||
tracing::trace!("Gesture {n_press} click");
|
||||
gesture.set_state(gtk::EventSequenceState::Denied);
|
||||
return;
|
||||
}
|
||||
|
||||
log::trace!("Gesture double click");
|
||||
tracing::trace!("Gesture double click");
|
||||
|
||||
gesture.set_state(gtk::EventSequenceState::Claimed);
|
||||
if gesture.device().map(|x| x.source()) == Some(gdk::InputSource::Touchscreen) {
|
||||
|
|
@ -175,7 +175,7 @@ impl imp::LpImage {
|
|||
#[weak]
|
||||
obj,
|
||||
move |gesture, _, _| {
|
||||
log::trace!("Drag gesture begin");
|
||||
tracing::trace!("Drag gesture begin");
|
||||
let imp = obj.imp();
|
||||
|
||||
// Allow only left and middle button
|
||||
|
|
@ -216,7 +216,7 @@ impl imp::LpImage {
|
|||
#[weak]
|
||||
obj,
|
||||
move |_, _, _| {
|
||||
log::trace!("Drag gesture end");
|
||||
tracing::trace!("Drag gesture end");
|
||||
obj.set_cursor(None);
|
||||
obj.imp().last_drag_value.set(None);
|
||||
}
|
||||
|
|
@ -230,7 +230,7 @@ impl imp::LpImage {
|
|||
#[weak]
|
||||
obj,
|
||||
move |_, _| {
|
||||
log::trace!("Rotate gesture begin");
|
||||
tracing::trace!("Rotate gesture begin");
|
||||
obj.imp().cancel_deceleration();
|
||||
}
|
||||
));
|
||||
|
|
@ -270,7 +270,7 @@ impl imp::LpImage {
|
|||
#[weak]
|
||||
obj,
|
||||
move |_, _| {
|
||||
log::debug!("Rotate gesture end");
|
||||
tracing::debug!("Rotate gesture end");
|
||||
|
||||
let angle = (obj.rotation() / 90.).round() * 90. - obj.imp().rotation_target.get();
|
||||
obj.rotate_by(angle);
|
||||
|
|
@ -286,7 +286,7 @@ impl imp::LpImage {
|
|||
#[weak]
|
||||
obj,
|
||||
move |gesture, _| {
|
||||
log::trace!("Zoom gesture begin");
|
||||
tracing::trace!("Zoom gesture begin");
|
||||
|
||||
let imp = obj.imp();
|
||||
imp.cancel_deceleration();
|
||||
|
|
@ -309,7 +309,7 @@ impl imp::LpImage {
|
|||
imp.set_hadj_value(imp.hadj_value() + x0 - x1);
|
||||
imp.set_vadj_value(imp.vadj_value() + y0 - y1);
|
||||
} else {
|
||||
log::warn!("Zoom bounding box center: No previous value");
|
||||
tracing::warn!("Zoom bounding box center: No previous value");
|
||||
}
|
||||
|
||||
imp.zoom_gesture_center.set(p1);
|
||||
|
|
@ -336,7 +336,7 @@ impl imp::LpImage {
|
|||
obj,
|
||||
move |_, _| {
|
||||
let imp = obj.imp();
|
||||
log::debug!("Zoom gesture end");
|
||||
tracing::debug!("Zoom gesture end");
|
||||
|
||||
let rotation_target = (obj.rotation() / 90.).round() * 90.;
|
||||
if obj.zoom() < imp.zoom_level_best_fit_for_rotation(rotation_target)
|
||||
|
|
@ -367,7 +367,7 @@ impl imp::LpImage {
|
|||
scrolled_window.set_kinetic_scrolling(false);
|
||||
scrolled_window.set_kinetic_scrolling(true);
|
||||
} else {
|
||||
log::error!("Could not find GtkScrolledWindow parent to cancel deceleration");
|
||||
tracing::error!("Could not find GtkScrolledWindow parent to cancel deceleration");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,9 +78,12 @@ impl imp::LpImage {
|
|||
pub fn update(&self, update: DecoderUpdate) {
|
||||
let obj = self.obj();
|
||||
|
||||
let span = tracing::debug_span!("update", image = obj.basename());
|
||||
let _guard = span.enter();
|
||||
|
||||
match update {
|
||||
DecoderUpdate::Metadata(metadata) => {
|
||||
log::debug!("Received metadata");
|
||||
tracing::debug!("Received metadata");
|
||||
self.metadata.borrow_mut().merge(*metadata);
|
||||
self.emmit_metadata_changed();
|
||||
|
||||
|
|
@ -92,7 +95,7 @@ impl imp::LpImage {
|
|||
));
|
||||
}
|
||||
DecoderUpdate::Dimensions => {
|
||||
log::debug!("Received dimensions: {:?}", self.untransformed_dimensions());
|
||||
tracing::debug!("Received dimensions: {:?}", self.untransformed_dimensions());
|
||||
obj.notify_image_size_available();
|
||||
self.configure_best_fit();
|
||||
self.request_tiles();
|
||||
|
|
@ -141,14 +144,14 @@ impl imp::LpImage {
|
|||
}
|
||||
DecoderUpdate::SpecificError(err) => {
|
||||
if self.obj().is_loaded() {
|
||||
log::warn!("Error occured while loading additional data: {err:?}");
|
||||
tracing::warn!("Error occured while loading additional data: {err:?}");
|
||||
} else {
|
||||
self.set_specific_error(err);
|
||||
}
|
||||
}
|
||||
DecoderUpdate::GenericError(err) => {
|
||||
if self.obj().is_loaded() {
|
||||
log::warn!("Error occured while loading additional data: {err:?}");
|
||||
tracing::warn!("Error occured while loading additional data: {err:?}");
|
||||
} else {
|
||||
self.set_error(Some(err));
|
||||
}
|
||||
|
|
@ -218,12 +221,12 @@ impl imp::LpImage {
|
|||
match event {
|
||||
gio::FileMonitorEvent::Renamed => {
|
||||
if let Some(file) = file_b.cloned() {
|
||||
log::debug!("Moved to {}", file.uri());
|
||||
tracing::debug!("Moved to {}", file.uri());
|
||||
|
||||
// current file got replaced with a new one
|
||||
let file_replace = obj.file().is_some_and(|x| x.equal(&file));
|
||||
if file_replace {
|
||||
log::debug!("Image got replaced {}", file.uri());
|
||||
tracing::debug!("Image got replaced {}", file.uri());
|
||||
glib::spawn_future_local(async move {
|
||||
obj.load(&file).await;
|
||||
});
|
||||
|
|
@ -243,7 +246,7 @@ impl imp::LpImage {
|
|||
}
|
||||
}
|
||||
gio::FileMonitorEvent::MovedIn => {
|
||||
log::debug!("Image got replaced by moving into dir {}", file_a.uri());
|
||||
tracing::debug!("Image got replaced by moving into dir {}", file_a.uri());
|
||||
glib::spawn_future_local(glib::clone!(
|
||||
#[strong]
|
||||
file_a,
|
||||
|
|
@ -255,7 +258,7 @@ impl imp::LpImage {
|
|||
gio::FileMonitorEvent::ChangesDoneHint => {
|
||||
let obj = self.obj().to_owned();
|
||||
let file = file_a.clone();
|
||||
log::debug!("Image was edited {}", file.uri());
|
||||
tracing::debug!("Image was edited {}", file.uri());
|
||||
glib::spawn_future_local(async move {
|
||||
obj.load(&file).await;
|
||||
});
|
||||
|
|
@ -263,7 +266,7 @@ impl imp::LpImage {
|
|||
gio::FileMonitorEvent::Deleted
|
||||
| gio::FileMonitorEvent::MovedOut
|
||||
| gio::FileMonitorEvent::Unmounted => {
|
||||
log::debug!("File no longer available: {event:?} {}", file_a.uri());
|
||||
tracing::debug!("File no longer available: {event:?} {}", file_a.uri());
|
||||
self.is_deleted.set(true);
|
||||
self.obj().notify_is_deleted();
|
||||
}
|
||||
|
|
@ -272,7 +275,7 @@ impl imp::LpImage {
|
|||
}
|
||||
|
||||
fn set_error(&self, err: Option<anyhow::Error>) {
|
||||
log::debug!("Decoding error: {err:?}");
|
||||
tracing::debug!("Decoding error: {err:?}");
|
||||
|
||||
// Keeping first error instead of replacing with new error
|
||||
if err.is_some() && self.error.borrow().is_some() {
|
||||
|
|
@ -342,16 +345,16 @@ impl LpImage {
|
|||
if let Some(file) = self.file() {
|
||||
self.load(&file).await;
|
||||
} else {
|
||||
log::error!("Trying to reload image without file");
|
||||
tracing::error!("Trying to reload image without file");
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn load(&self, file: &gio::File) {
|
||||
let imp = self.imp();
|
||||
log::debug!("Loading file {}", file.uri());
|
||||
tracing::debug!("Loading file {}", file.uri());
|
||||
|
||||
if imp.rotation_animation().state() == adw::AnimationState::Playing {
|
||||
log::debug!("Queueing image reload due to playing rotate animation.");
|
||||
tracing::debug!("Queueing image reload due to playing rotate animation.");
|
||||
self.imp().queued_reload.replace(Some(file.clone()));
|
||||
return;
|
||||
}
|
||||
|
|
@ -380,7 +383,7 @@ impl LpImage {
|
|||
obj.imp().update(update);
|
||||
}
|
||||
}
|
||||
log::debug!("Stopped listening to decoder since sender is gone");
|
||||
tracing::debug!("Stopped listening to decoder since sender is gone");
|
||||
});
|
||||
|
||||
imp.decoder.replace(Some(Arc::new(decoder)));
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ impl imp::LpImage {
|
|||
let file_info = metadata::FileInfo::new(&file).await;
|
||||
match file_info {
|
||||
Ok(file_info) => self.metadata.borrow_mut().set_file_info(file_info),
|
||||
Err(err) => log::warn!("Failed to load file information: {err}"),
|
||||
Err(err) => tracing::warn!("Failed to load file information: {err}"),
|
||||
}
|
||||
self.emmit_metadata_changed();
|
||||
}
|
||||
|
|
@ -101,6 +101,12 @@ impl LpImage {
|
|||
self.imp().file.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn basename(&self) -> Option<String> {
|
||||
self.file()
|
||||
.and_then(|x| x.basename())
|
||||
.map(|x| x.display().to_string())
|
||||
}
|
||||
|
||||
pub fn metadata(&self) -> impl Deref<Target = Metadata> + '_ {
|
||||
self.imp().metadata.borrow()
|
||||
}
|
||||
|
|
@ -136,7 +142,7 @@ impl LpImage {
|
|||
|
||||
match file_info {
|
||||
Err(err) => {
|
||||
log::error!(
|
||||
tracing::error!(
|
||||
"Failed to obtain CAN_TRASH attribute for '{}': {err}",
|
||||
file.uri()
|
||||
);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ impl LpImage {
|
|||
gtk::PanDirection::Left | gtk::PanDirection::Up => -1.,
|
||||
gtk::PanDirection::Right | gtk::PanDirection::Down => 1.,
|
||||
_ => {
|
||||
log::error!("Unknown pan direction {direction:?}");
|
||||
tracing::error!("Unknown pan direction {direction:?}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
|
@ -39,7 +39,7 @@ impl LpImage {
|
|||
(self.vadj(), imp.max_vadjustment_value())
|
||||
}
|
||||
_ => {
|
||||
log::error!("Unknown pan direction {direction:?}");
|
||||
tracing::error!("Unknown pan direction {direction:?}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ impl WidgetImpl for imp::LpImage {
|
|||
let nth_snapshot = self.nth_snapshot.get() + 1;
|
||||
if nth_snapshot < 3 {
|
||||
self.nth_snapshot.set(nth_snapshot);
|
||||
log::trace!("Creating snapshot #{nth_snapshot}");
|
||||
tracing::trace!("Creating snapshot #{nth_snapshot}");
|
||||
}
|
||||
|
||||
let scaling_filter = if obj.metadata().is_svg() {
|
||||
|
|
@ -124,10 +124,10 @@ impl WidgetImpl for imp::LpImage {
|
|||
frame_buffer.add_to_snapshot(&tmp_snapshot, applicable_zoom, &render_options);
|
||||
if let Some(node) = tmp_snapshot.to_node() {
|
||||
if let Err(err) = self.apply_operations(node, snapshot) {
|
||||
log::error!("Failed to apply operations to node: {err}");
|
||||
tracing::error!("Failed to apply operations to node: {err}");
|
||||
}
|
||||
} else {
|
||||
log::error!("Render node is empty");
|
||||
tracing::error!("Render node is empty");
|
||||
}
|
||||
} else {
|
||||
// Apply rotation and mirroring
|
||||
|
|
@ -144,12 +144,16 @@ impl WidgetImpl for imp::LpImage {
|
|||
snapshot.restore();
|
||||
|
||||
if nth_snapshot < 3 {
|
||||
log::trace!("Snapshot #{nth_snapshot} created");
|
||||
tracing::trace!("Snapshot #{nth_snapshot} created");
|
||||
}
|
||||
}
|
||||
|
||||
fn measure(&self, orientation: gtk::Orientation, _for_size: i32) -> (i32, i32, i32, i32) {
|
||||
let obj = self.obj();
|
||||
|
||||
let span = tracing::debug_span!("measure", image = obj.basename());
|
||||
let _guard = span.enter();
|
||||
|
||||
let (image_width_i32, image_height_i32) = obj.image_size();
|
||||
let image_width = image_width_i32 as f64;
|
||||
let image_height = image_height_i32 as f64;
|
||||
|
|
@ -157,7 +161,7 @@ impl WidgetImpl for imp::LpImage {
|
|||
if image_width_i32 > 0 && image_height_i32 > 0 {
|
||||
if let Some((monitor_width, monitor_height)) = self.monitor_size() {
|
||||
let hidpi_scale = self.scaling();
|
||||
log::trace!("Physical monitor dimensions: {monitor_width} x {monitor_height}");
|
||||
tracing::trace!("Physical monitor dimensions: {monitor_width} x {monitor_height}");
|
||||
|
||||
// areas
|
||||
let monitor_area = monitor_width * monitor_height;
|
||||
|
|
@ -165,10 +169,12 @@ impl WidgetImpl for imp::LpImage {
|
|||
let image_area = image_width * image_height;
|
||||
|
||||
let occupy_area_factor = if logical_monitor_area <= SMALL_SCREEN_AREA {
|
||||
log::trace!("Small monitor detected: Using {SMALL_OCCUPY_SCREEN} screen area");
|
||||
tracing::trace!(
|
||||
"Small monitor detected: Using {SMALL_OCCUPY_SCREEN} screen area"
|
||||
);
|
||||
SMALL_OCCUPY_SCREEN
|
||||
} else {
|
||||
log::trace!(
|
||||
tracing::trace!(
|
||||
"Sufficiently large monitor detected: Using {DEFAULT_OCCUPY_SCREEN} screen area"
|
||||
);
|
||||
DEFAULT_OCCUPY_SCREEN
|
||||
|
|
@ -218,7 +224,7 @@ impl WidgetImpl for imp::LpImage {
|
|||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
log::warn!("Not enough information available to calculate fitting window size");
|
||||
tracing::warn!("Not enough information available to calculate fitting window size");
|
||||
|
||||
(0, size, -1, -1)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ impl imp::LpImage {
|
|||
let imp = obj.imp();
|
||||
if let Some(new_file) = imp.queued_reload.replace(None) {
|
||||
glib::spawn_future_local(async move {
|
||||
log::debug!("Animation finished: Executing delayed reload");
|
||||
tracing::debug!("Animation finished: Executing delayed reload");
|
||||
obj.load(&new_file).await;
|
||||
});
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ impl imp::LpImage {
|
|||
impl LpImage {
|
||||
/// Set rotation and mirroring to the state would have after loading
|
||||
pub fn reset_rotation(&self) {
|
||||
log::debug!("Resetting rotation");
|
||||
tracing::debug!("Resetting rotation");
|
||||
let orientation = self.metadata().orientation();
|
||||
self.imp()
|
||||
.rotation_target
|
||||
|
|
@ -86,7 +86,7 @@ impl LpImage {
|
|||
pub fn rotate_by(&self, angle: f64) {
|
||||
let imp = self.imp();
|
||||
|
||||
log::debug!("Rotate by {} degrees", angle);
|
||||
tracing::debug!("Rotate by {} degrees", angle);
|
||||
let target = &self.imp().rotation_target;
|
||||
target.set(target.get() + angle);
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ impl LpImage {
|
|||
|
||||
if let Ok(r) = gufo_common::orientation::Rotation::try_from(angle) {
|
||||
if r != gufo_common::orientation::Rotation::_0 {
|
||||
log::debug!("Editing image to rotate by {r:?}");
|
||||
tracing::debug!("Editing image to rotate by {r:?}");
|
||||
let operation = glycin::Operation::Rotate(r);
|
||||
let editing_queue = &self.imp().editing_queue;
|
||||
editing_queue.push(operation);
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ impl imp::LpImage {
|
|||
}
|
||||
|
||||
pub fn set_ignore_scroll_policy(&self, scroll_policy: gtk::ScrollablePolicy) {
|
||||
log::error!("Ignored setting new scroll policy {scroll_policy:?}");
|
||||
tracing::error!("Ignored setting new scroll policy {scroll_policy:?}");
|
||||
}
|
||||
|
||||
pub fn scroll_policy(&self) -> gtk::ScrollablePolicy {
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ impl imp::LpImage {
|
|||
|
||||
/// Sets respective output values if best-fit is active
|
||||
pub(super) fn configure_best_fit(&self) {
|
||||
log::trace!("Configure best fit");
|
||||
tracing::trace!("Configure best fit");
|
||||
// calculate new zoom value for best fit
|
||||
if self.obj().is_best_fit() {
|
||||
// LpImage can get measured during pinch zoom gesture, when scrollbars appear
|
||||
|
|
@ -193,7 +193,7 @@ impl imp::LpImage {
|
|||
}
|
||||
|
||||
pub(super) fn set_zoom_target(&self, zoom_target: f64) {
|
||||
log::trace!("Setting zoom target {zoom_target}");
|
||||
tracing::trace!("Setting zoom target {zoom_target}");
|
||||
|
||||
self.zoom_target.set(zoom_target);
|
||||
self.obj().notify_zoom_target();
|
||||
|
|
@ -243,13 +243,13 @@ impl imp::LpImage {
|
|||
obj.set_best_fit(false);
|
||||
}
|
||||
|
||||
log::trace!("Zoom to {zoom:.3}");
|
||||
tracing::trace!("Zoom to {zoom:.3}");
|
||||
|
||||
self.set_zoom_target(zoom);
|
||||
|
||||
// abort if already at correct zoom level
|
||||
if zoom == obj.zoom() {
|
||||
log::trace!("Already at correct zoom level");
|
||||
tracing::trace!("Already at correct zoom level");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue