From cbd3dd987dccd10f9e7286af436a8edbb85d2082 Mon Sep 17 00:00:00 2001 From: Till Wegmueller Date: Sat, 26 Jul 2025 21:48:07 +0200 Subject: [PATCH] Replace all `println!` statements with structured logging using `tracing` crate for enhanced diagnostics and consistency across `pkg6repo` and `pkg6dev`. --- pkg6dev/src/main.rs | 55 ++++++++++++++++++++++---------------------- pkg6repo/src/main.rs | 48 +++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/pkg6dev/src/main.rs b/pkg6dev/src/main.rs index a849ad6..2692ab4 100644 --- a/pkg6dev/src/main.rs +++ b/pkg6dev/src/main.rs @@ -9,6 +9,7 @@ use std::collections::HashMap; use std::fs::{read_dir, OpenOptions}; use std::io::Write; use std::path::{Path, PathBuf}; +use tracing::{debug, error, info, warn, trace}; use tracing_subscriber::fmt; use userland::repology::find_newest_version; use userland::{Component, Makefile}; @@ -170,7 +171,7 @@ fn diff_component( // Print missing files for f in missing_files.clone() { - println!("file {} is missing in the manifests", f.path); + debug!("file {} is missing in the manifests", f.path); } // Find removed files @@ -179,7 +180,7 @@ fn diff_component( // Print removed files for f in removed_files { - println!( + debug!( "file path={} has been removed from the sample-manifest", f.path ); @@ -239,7 +240,7 @@ fn show_component_info>(component_path: P) -> Result<()> { // Display component information if let Some(var) = makefile.get("COMPONENT_NAME") { - println!("Name: {}", var.replace('\n', "\n\t")); + info!("Name: {}", var.replace('\n', "\n\t")); if let Some(component_name) = makefile.get_first_value_of_variable_by_name("COMPONENT_NAME") { name = component_name; @@ -247,49 +248,49 @@ fn show_component_info>(component_path: P) -> Result<()> { } if let Some(var) = makefile.get("COMPONENT_VERSION") { - println!("Version: {}", var.replace('\n', "\n\t")); + info!("Version: {}", var.replace('\n', "\n\t")); let latest_version = find_newest_version(&name); if latest_version.is_ok() { - println!("Latest Version: {}", latest_version.map_err(|e| Pkg6DevError::ComponentInfoError { + info!("Latest Version: {}", latest_version.map_err(|e| Pkg6DevError::ComponentInfoError { message: format!("Failed to get latest version: {}", e), })?); } else { - println!( - "Error: Could not get latest version info: {}", + warn!( + "Could not get latest version info: {}", latest_version.unwrap_err() ) } } if let Some(var) = makefile.get("BUILD_BITS") { - println!("Build bits: {}", var.replace('\n', "\n\t")); + info!("Build bits: {}", var.replace('\n', "\n\t")); } if let Some(var) = makefile.get("COMPONENT_BUILD_ACTION") { - println!("Build action: {}", var.replace('\n', "\n\t")); + info!("Build action: {}", var.replace('\n', "\n\t")); } if let Some(var) = makefile.get("COMPONENT_PROJECT_URL") { - println!("Project URl: {}", var.replace('\n', "\n\t")); + info!("Project URl: {}", var.replace('\n', "\n\t")); } if let Some(var) = makefile.get("COMPONENT_ARCHIVE_URL") { - println!("Source URl: {}", var.replace('\n', "\n\t")); + info!("Source URl: {}", var.replace('\n', "\n\t")); } if let Some(var) = makefile.get("COMPONENT_ARCHIVE_HASH") { - println!("Source Archive File Hash: {}", var.replace('\n', "\n\t")); + info!("Source Archive File Hash: {}", var.replace('\n', "\n\t")); } if let Some(var) = makefile.get("REQUIRED_PACKAGES") { - println!("Dependencies:\n\t{}", var.replace('\n', "\n\t")); + info!("Dependencies:\n\t{}", var.replace('\n', "\n\t")); } if let Some(var) = makefile.get("COMPONENT_INSTALL_ACTION") { - println!("Install Action:\n\t{}", var); + info!("Install Action:\n\t{}", var); } - println!("Component: {:?}", component); + info!("Component: {:?}", component); Ok(()) } @@ -412,15 +413,15 @@ fn publish_package( } // Parse the manifest file - println!("Parsing manifest file: {}", manifest_path.display()); + info!("Parsing manifest file: {}", manifest_path.display()); let manifest = Manifest::parse_file(manifest_path)?; // Open the repository - println!("Opening repository at: {}", repo_path.display()); + info!("Opening repository at: {}", repo_path.display()); let repo = match FileBackend::open(repo_path) { Ok(repo) => repo, Err(_) => { - println!("Repository does not exist, creating a new one..."); + info!("Repository does not exist, creating a new one..."); // Create a new repository with version 4 FileBackend::create(repo_path, libips::repository::RepositoryVersion::V4)? } @@ -444,14 +445,14 @@ fn publish_package( }; // Begin a transaction - println!("Beginning transaction for publisher: {}", publisher_name); + info!("Beginning transaction for publisher: {}", publisher_name); let mut transaction = repo.begin_transaction()?; // Set the publisher for the transaction transaction.set_publisher(&publisher_name); // Add files from the prototype directory to the transaction - println!( + info!( "Adding files from prototype directory: {}", prototype_dir.display() ); @@ -463,8 +464,8 @@ fn publish_package( if !file_path.exists() { // Instead of just a warning, we could return an error here, but that might be too strict // For now, we'll keep the warning but use a more structured approach - println!( - "Warning: File does not exist in prototype directory: {}", + warn!( + "File does not exist in prototype directory: {}", file_path.display() ); // We continue here instead of returning an error to allow the operation to proceed @@ -473,22 +474,22 @@ fn publish_package( } // Add the file to the transaction - println!("Adding file: {}", file_action.path); + debug!("Adding file: {}", file_action.path); transaction.add_file(file_action.clone(), &file_path)?; } // Update the manifest in the transaction - println!("Updating manifest in the transaction..."); + info!("Updating manifest in the transaction..."); transaction.update_manifest(manifest); // Commit the transaction - println!("Committing transaction..."); + info!("Committing transaction..."); transaction.commit()?; // Regenerate catalog and search index - println!("Regenerating catalog and search index..."); + info!("Regenerating catalog and search index..."); repo.rebuild(Some(&publisher_name), false, false)?; - println!("Package published successfully!"); + info!("Package published successfully!"); Ok(()) } diff --git a/pkg6repo/src/main.rs b/pkg6repo/src/main.rs index 657a611..b05431e 100644 --- a/pkg6repo/src/main.rs +++ b/pkg6repo/src/main.rs @@ -324,7 +324,7 @@ fn main() -> Result<()> { repo_version, uri_or_path, } => { - println!( + info!( "Creating repository version {} at {}", repo_version, uri_or_path ); @@ -335,14 +335,14 @@ fn main() -> Result<()> { // Create the repository let repo = FileBackend::create(uri_or_path, repo_version_enum)?; - println!("Repository created successfully at {}", repo.path.display()); + info!("Repository created successfully at {}", repo.path.display()); Ok(()) } Commands::AddPublisher { repo_uri_or_path, publisher, } => { - println!( + info!( "Adding publishers {:?} to repository {}", publisher, repo_uri_or_path ); @@ -352,11 +352,11 @@ fn main() -> Result<()> { // Add each publisher for p in publisher { - println!("Adding publisher: {}", p); + info!("Adding publisher: {}", p); repo.add_publisher(p)?; } - println!("Publishers added successfully"); + info!("Publishers added successfully"); Ok(()) } Commands::RemovePublisher { @@ -365,18 +365,18 @@ fn main() -> Result<()> { synchronous, publisher, } => { - println!( + info!( "Removing publishers {:?} from repository {}", publisher, repo_uri_or_path ); - println!("Dry run: {}, Synchronous: {}", dry_run, synchronous); + debug!("Dry run: {}, Synchronous: {}", dry_run, synchronous); // Open the repository let mut repo = FileBackend::open(repo_uri_or_path)?; // Remove each publisher for p in publisher { - println!("Removing publisher: {}", p); + info!("Removing publisher: {}", p); repo.remove_publisher(p, *dry_run)?; } @@ -384,13 +384,13 @@ fn main() -> Result<()> { // For FileBackend, operations are already synchronous, so this parameter doesn't have any effect // For RestBackend, this would wait for the server to complete the operation before returning if *synchronous { - println!("Operation completed synchronously"); + debug!("Operation completed synchronously"); } if *dry_run { - println!("Dry run completed. No changes were made."); + info!("Dry run completed. No changes were made."); } else { - println!("Publishers removed successfully"); + info!("Publishers removed successfully"); } Ok(()) @@ -403,7 +403,7 @@ fn main() -> Result<()> { section_property, .. } => { - println!("Getting properties from repository {}", repo_uri_or_path); + info!("Getting properties from repository {}", repo_uri_or_path); // Open the repository // In a real implementation with RestBackend, the key and cert parameters would be used for SSL authentication @@ -526,7 +526,7 @@ fn main() -> Result<()> { publisher, .. } => { - println!("Displaying info for repository {}", repo_uri_or_path); + info!("Displaying info for repository {}", repo_uri_or_path); // Open the repository // In a real implementation with RestBackend, the key and cert parameters would be used for SSL authentication @@ -620,7 +620,7 @@ fn main() -> Result<()> { pkg_fmri_pattern, .. } => { - println!("Listing packages in repository {}", repo_uri_or_path); + info!("Listing packages in repository {}", repo_uri_or_path); // Open the repository // In a real implementation with RestBackend, the key and cert parameters would be used for SSL authentication @@ -729,7 +729,7 @@ fn main() -> Result<()> { pkg_fmri_pattern, .. } => { - println!("Showing contents in repository {}", repo_uri_or_path); + info!("Showing contents in repository {}", repo_uri_or_path); // Open the repository // In a real implementation with RestBackend, the key and cert parameters would be used for SSL authentication @@ -851,7 +851,7 @@ fn main() -> Result<()> { no_index, .. } => { - println!("Rebuilding repository {}", repo_uri_or_path); + info!("Rebuilding repository {}", repo_uri_or_path); // Open the repository // In a real implementation with RestBackend, the key and cert parameters would be used for SSL authentication @@ -872,7 +872,7 @@ fn main() -> Result<()> { // Rebuild repository metadata repo.rebuild(pub_option, *no_catalog, *no_index)?; - println!("Repository rebuilt successfully"); + info!("Repository rebuilt successfully"); Ok(()) } Commands::Refresh { @@ -882,7 +882,7 @@ fn main() -> Result<()> { no_index, .. } => { - println!("Refreshing repository {}", repo_uri_or_path); + info!("Refreshing repository {}", repo_uri_or_path); // Open the repository // In a real implementation with RestBackend, the key and cert parameters would be used for SSL authentication @@ -903,7 +903,7 @@ fn main() -> Result<()> { // Refresh repository metadata repo.refresh(pub_option, *no_catalog, *no_index)?; - println!("Repository refreshed successfully"); + info!("Repository refreshed successfully"); Ok(()) } Commands::Set { @@ -911,7 +911,7 @@ fn main() -> Result<()> { publisher, property_value, } => { - println!("Setting properties for repository {}", repo_uri_or_path); + info!("Setting properties for repository {}", repo_uri_or_path); // Open the repository let mut repo = FileBackend::open(repo_uri_or_path)?; @@ -929,19 +929,19 @@ fn main() -> Result<()> { // If a publisher is specified, set the publisher property if let Some(pub_name) = publisher { - println!( + info!( "Setting publisher property {}/{} = {}", pub_name, property, value ); repo.set_publisher_property(pub_name, property, value)?; } else { // Otherwise, set the repository property - println!("Setting repository property {} = {}", property, value); + info!("Setting repository property {} = {}", property, value); repo.set_property(property, value)?; } } - println!("Properties set successfully"); + info!("Properties set successfully"); Ok(()) } Commands::Search { @@ -953,7 +953,7 @@ fn main() -> Result<()> { query, .. } => { - println!("Searching for packages in repository {}", repo_uri_or_path); + info!("Searching for packages in repository {}", repo_uri_or_path); // Open the repository // In a real implementation with RestBackend, the key and cert parameters would be used for SSL authentication