Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace log with tracing and use tracing::instrument where useful #316

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ rust-version = "1.76.0"
aho-corasick = "1.1.3"
anyhow = "1.0.89"
bytes = "1.7.2"
derive_setters = "0.1.6"
displaydoc = "0.2.5"
enum-map = "2.7.3"
rustic_backend = { path = "crates/backend" }
rustic_core = { path = "crates/core", version = "0" }
rustic_testing = { path = "crates/testing", version = "0" }
simplelog = "0.12.2"
thiserror = "1.0.64"
tracing = { version = "0.1.40", features = ["log"] }

# dev-dependencies
rstest = "0.23.0"
Expand Down
12 changes: 6 additions & 6 deletions crates/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ rclone = ["rest", "dep:rand", "dep:semver"]
rustic_core = { workspace = true }

# errors
anyhow = "1.0.89"
displaydoc = "0.2.5"
thiserror = "1.0.64"
anyhow = { workspace = true }
displaydoc = { workspace = true }
thiserror = { workspace = true }

# logging
log = "0.4.22"
tracing = { workspace = true }

# other dependencies
bytes = "1.7.2"
derive_setters = "0.1.6"
bytes = { workspace = true }
derive_setters = { workspace = true }
humantime = "2.1.0"
itertools = "0.13.0"
strum = "0.26"
Expand Down
2 changes: 1 addition & 1 deletion crates/backend/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
use aho_corasick::AhoCorasick;
use anyhow::Result;
use bytes::Bytes;
use log::{debug, trace, warn};
use tracing::{debug, trace, warn};
use walkdir::WalkDir;

use rustic_core::{CommandInput, FileType, Id, ReadBackend, WriteBackend, ALL_FILE_TYPES};
Expand Down
3 changes: 2 additions & 1 deletion crates/backend/src/opendal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use std::{collections::HashMap, str::FromStr, sync::OnceLock};
use anyhow::{anyhow, Error, Result};
use bytes::Bytes;
use bytesize::ByteSize;
use log::trace;
use opendal::{
layers::{BlockingLayer, ConcurrentLimitLayer, LoggingLayer, RetryLayer, ThrottleLayer},
BlockingOperator, ErrorKind, Metakey, Operator, Scheme,
};
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
use tokio::runtime::Runtime;
use tracing::trace;
use typed_path::UnixPathBuf;

use rustic_core::{FileType, Id, ReadBackend, WriteBackend, ALL_FILE_TYPES};
Expand Down Expand Up @@ -235,6 +235,7 @@ impl ReadBackend for OpenDALBackend {

impl WriteBackend for OpenDALBackend {
/// Create a repository on the backend.
#[tracing::instrument(skip(self))]
fn create(&self) -> Result<()> {
trace!("creating repo at {:?}", self.location());

Expand Down
3 changes: 2 additions & 1 deletion crates/backend/src/rclone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use std::{
use anyhow::Result;
use bytes::Bytes;
use constants::DEFAULT_COMMAND;
use log::{debug, info};
use rand::{
distributions::{Alphanumeric, DistString},
thread_rng,
};
use semver::{BuildMetadata, Prerelease, Version, VersionReq};
use tracing::{debug, info};

use crate::{error::RcloneErrorKind, rest::RestBackend};

Expand Down Expand Up @@ -127,6 +127,7 @@ impl RcloneBackend {
///
/// If the rclone command is not found.
// TODO: This should be an error, not a panic.
#[tracing::instrument(skip(url))]
pub fn new(url: impl AsRef<str>, options: HashMap<String, String>) -> Result<Self> {
let rclone_command = options.get("rclone-command");
let use_password = options
Expand Down
8 changes: 7 additions & 1 deletion crates/backend/src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use std::time::Duration;
use anyhow::Result;
use backoff::{backoff::Backoff, ExponentialBackoff, ExponentialBackoffBuilder};
use bytes::Bytes;
use log::{trace, warn};
use reqwest::{
blocking::{Client, ClientBuilder, Response},
header::{HeaderMap, HeaderValue},
Url,
};
use serde::Deserialize;
use tracing::{trace, warn};

use crate::error::RestErrorKind;

Expand Down Expand Up @@ -245,6 +245,7 @@ impl ReadBackend for RestBackend {
/// A vector of tuples containing the id and size of the files.
///
/// [`RestErrorKind::JoiningUrlFailed`]: RestErrorKind::JoiningUrlFailed
#[tracing::instrument(skip(self))]
fn list_with_size(&self, tpe: FileType) -> Result<Vec<(Id, u32)>> {
// format which is delivered by the REST-service
#[derive(Deserialize)]
Expand Down Expand Up @@ -313,6 +314,7 @@ impl ReadBackend for RestBackend {
/// * [`RestErrorKind::BackoffError`] - If the backoff failed.
///
/// [`RestErrorKind::BackoffError`]: RestErrorKind::BackoffError
#[tracing::instrument(skip(self))]
fn read_full(&self, tpe: FileType, id: &Id) -> Result<Bytes> {
trace!("reading tpe: {tpe:?}, id: {id}");
let url = self.url(tpe, id)?;
Expand Down Expand Up @@ -346,6 +348,7 @@ impl ReadBackend for RestBackend {
/// * [`RestErrorKind::BackoffError`] - If the backoff failed.
///
/// [`RestErrorKind::BackoffError`]: RestErrorKind::BackoffError
#[tracing::instrument(skip(self, _cacheable))]
fn read_partial(
&self,
tpe: FileType,
Expand Down Expand Up @@ -383,6 +386,7 @@ impl WriteBackend for RestBackend {
/// * [`RestErrorKind::BackoffError`] - If the backoff failed.
///
/// [`RestErrorKind::BackoffError`]: RestErrorKind::BackoffError
#[tracing::instrument(skip(self))]
fn create(&self) -> Result<()> {
let url = self
.url
Expand Down Expand Up @@ -413,6 +417,7 @@ impl WriteBackend for RestBackend {
/// * [`RestErrorKind::BackoffError`] - If the backoff failed.
///
/// [`RestErrorKind::BackoffError`]: RestErrorKind::BackoffError
#[tracing::instrument(skip(self, _cacheable))]
fn write_bytes(&self, tpe: FileType, id: &Id, _cacheable: bool, buf: Bytes) -> Result<()> {
trace!("writing tpe: {:?}, id: {}", &tpe, &id);
let req_builder = self.client.post(self.url(tpe, id)?).body(buf);
Expand Down Expand Up @@ -441,6 +446,7 @@ impl WriteBackend for RestBackend {
/// * [`RestErrorKind::BackoffError`] - If the backoff failed.
///
/// [`RestErrorKind::BackoffError`]: RestErrorKind::BackoffError
#[tracing::instrument(skip(self, _cacheable))]
fn remove(&self, tpe: FileType, id: &Id, _cacheable: bool) -> Result<()> {
trace!("removing tpe: {:?}, id: {}", &tpe, &id);
let url = self.url(tpe, id)?;
Expand Down
8 changes: 4 additions & 4 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ rustdoc-args = ["--document-private-items", "--generate-link-to-definition"]

[dependencies]
# errors
displaydoc = "0.2.5"
thiserror = "1.0.64"
displaydoc = { workspace = true }
thiserror = { workspace = true }

# macros
derivative = "2.2.0"
derive_more = { version = "1.0.0", features = ["add", "constructor", "display", "from", "deref", "from_str"] }
derive_setters = "0.1.6"
derive_setters = { workspace = true }

# logging
log = "0.4.22"
tracing = { workspace = true }

# parallelize
crossbeam-channel = "0.5.13"
Expand Down
3 changes: 2 additions & 1 deletion crates/core/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ pub(crate) mod tree_archiver;
use std::path::{Path, PathBuf};

use chrono::Local;
use log::warn;
use pariter::{scope, IteratorExt};
use tracing::warn;

use crate::{
archiver::{
Expand Down Expand Up @@ -121,6 +121,7 @@ impl<'a, BE: DecryptFullBackend, I: ReadGlobalIndex> Archiver<'a, BE, I> {
/// [`PackerErrorKind::SendingCrossbeamMessageFailed`]: crate::error::PackerErrorKind::SendingCrossbeamMessageFailed
/// [`CryptBackendErrorKind::SerializingToJsonByteVectorFailed`]: crate::error::CryptBackendErrorKind::SerializingToJsonByteVectorFailed
/// [`SnapshotFileErrorKind::OutOfRange`]: crate::error::SnapshotFileErrorKind::OutOfRange
#[tracing::instrument(skip(self, src, p))]
pub fn archive<R>(
mut self,
src: &R,
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/archiver/parent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
ffi::{OsStr, OsString},
};

use log::warn;
use tracing::warn;

use crate::{
archiver::tree::TreeType,
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/archiver/tree_archiver.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::{Path, PathBuf};

use bytesize::ByteSize;
use log::{debug, trace};
use tracing::{debug, trace};

use crate::{
archiver::{parent::ParentResult, tree::TreeType},
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{io::Read, ops::Deref, path::PathBuf, sync::Arc};
use anyhow::Result;
use bytes::Bytes;
use enum_map::Enum;
use log::trace;
use tracing::trace;

#[cfg(test)]
use mockall::mock;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/backend/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
use anyhow::Result;
use bytes::Bytes;
use dirs::cache_dir;
use log::{trace, warn};
use tracing::{trace, warn};
use walkdir::WalkDir;

use crate::{
Expand Down
3 changes: 3 additions & 0 deletions crates/core/src/backend/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pub trait DecryptReadBackend: ReadBackend + Clone + 'static {
/// # Errors
///
/// If the files could not be read.
#[tracing::instrument(skip(self, p))]
fn stream_list<F: RepoFile>(&self, list: &[Id], p: &impl Progress) -> StreamResult<F::Id, F> {
p.set_length(list.len() as u64);
let (tx, rx) = unbounded();
Expand Down Expand Up @@ -279,6 +280,7 @@ pub trait DecryptWriteBackend: WriteBackend + Clone + 'static {
/// # Errors
///
/// * [`CryptBackendErrorKind::SerializingToJsonByteVectorFailed`] - If the file could not be serialized to json.
#[tracing::instrument(skip(self, list, p))]
fn save_list<'a, F: RepoFile, I: ExactSizeIterator<Item = &'a F> + Send>(
&self,
list: I,
Expand Down Expand Up @@ -306,6 +308,7 @@ pub trait DecryptWriteBackend: WriteBackend + Clone + 'static {
/// # Panics
///
/// If the files could not be deleted.
#[tracing::instrument(skip(self, list, p))]
fn delete_list<'a, ID: RepoId, I: ExactSizeIterator<Item = &'a ID> + Send>(
&self,
cacheable: bool,
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/backend/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use chrono::TimeZone;
use chrono::{DateTime, Local, Utc};
use derive_setters::Setters;
use ignore::{overrides::OverrideBuilder, DirEntry, Walk, WalkBuilder};
use log::warn;
#[cfg(not(windows))]
use nix::unistd::{Gid, Group, Uid, User};
use tracing::warn;

#[cfg(not(windows))]
use crate::backend::node::ExtendedAttribute;
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/backend/local_destination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use bytes::Bytes;
use cached::proc_macro::cached;
use filetime::{set_symlink_file_times, FileTime};
#[cfg(not(windows))]
use log::warn;
#[cfg(not(windows))]
use nix::sys::stat::{mknod, Mode, SFlag};
#[cfg(not(windows))]
use nix::{
fcntl::AtFlags,
unistd::{fchownat, Gid, Group, Uid, User},
};
#[cfg(not(windows))]
use tracing::warn;

#[cfg(not(windows))]
use crate::backend::ignore::mapper::map_mode_from_go;
Expand Down
7 changes: 6 additions & 1 deletion crates/core/src/blob/packer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use integer_sqrt::IntegerSquareRoot;
use log::warn;
use tracing::warn;

use std::{
num::NonZeroU32,
Expand Down Expand Up @@ -194,6 +194,7 @@ impl<BE: DecryptWriteBackend> Packer<BE> {
/// [`PackerErrorKind::SendingCrossbeamMessageFailed`]: crate::error::PackerErrorKind::SendingCrossbeamMessageFailed
/// [`PackerErrorKind::IntConversionFailed`]: crate::error::PackerErrorKind::IntConversionFailed
#[allow(clippy::unnecessary_wraps)]
#[tracing::instrument(skip(be, indexer))]
pub fn new(
be: BE,
blob_type: BlobType,
Expand Down Expand Up @@ -295,6 +296,7 @@ impl<BE: DecryptWriteBackend> Packer<BE> {
/// * [`PackerErrorKind::SendingCrossbeamMessageFailed`] - If sending the message to the raw packer fails.
///
/// [`PackerErrorKind::SendingCrossbeamMessageFailed`]: crate::error::PackerErrorKind::SendingCrossbeamMessageFailed
#[tracing::instrument(skip(self))]
fn add_with_sizelimit(
&self,
data: Bytes,
Expand Down Expand Up @@ -602,6 +604,7 @@ impl<BE: DecryptWriteBackend> RawPacker<BE> {
///
/// [`PackerErrorKind::IntConversionFailed`]: crate::error::PackerErrorKind::IntConversionFailed
/// [`PackFileErrorKind::WritingBinaryRepresentationFailed`]: crate::error::PackFileErrorKind::WritingBinaryRepresentationFailed
#[tracing::instrument(skip(self))]
fn save(&mut self) -> RusticResult<()> {
if self.size == 0 {
return Ok(());
Expand Down Expand Up @@ -677,6 +680,7 @@ impl Actor {
/// * `fwh` - The file writer handle.
/// * `queue_len` - The length of the queue.
/// * `par` - The number of parallel threads.
#[tracing::instrument(skip(fwh, _par))]
fn new<BE: DecryptWriteBackend>(
fwh: FileWriterHandle<BE>,
queue_len: usize,
Expand Down Expand Up @@ -718,6 +722,7 @@ impl Actor {
/// # Errors
///
/// If sending the message to the actor fails.
#[tracing::instrument(skip(self))]
fn send(&self, load: (Bytes, IndexPack)) -> RusticResult<()> {
self.sender
.send(load)
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/blob/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ impl<P: Progress> TreeStreamerOnce<P> {
/// * [`TreeErrorKind::SendingCrossbeamMessageFailed`] - If sending the message fails.
///
/// [`TreeErrorKind::SendingCrossbeamMessageFailed`]: crate::error::TreeErrorKind::SendingCrossbeamMessageFailed
#[tracing::instrument(skip(be, index, p))]
pub fn new<BE: DecryptReadBackend, I: ReadGlobalIndex>(
be: &BE,
index: &I,
Expand Down Expand Up @@ -733,6 +734,7 @@ impl<P: Progress> TreeStreamerOnce<P> {
/// * [`TreeErrorKind::SendingCrossbeamMessageFailed`] - If sending the message fails.
///
/// [`TreeErrorKind::SendingCrossbeamMessageFailed`]: crate::error::TreeErrorKind::SendingCrossbeamMessageFailed
#[tracing::instrument(skip(self))]
fn add_pending(&mut self, path: PathBuf, id: TreeId, count: usize) -> RusticResult<bool> {
if self.visited.insert(id) {
self.queue_in
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/commands/backup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `backup` subcommand
use derive_setters::Setters;
use log::info;
use tracing::info;

use std::path::PathBuf;

Expand Down
Loading
Loading