From 2d4752c83bf4737f1a4046c376d087f138becdc6 Mon Sep 17 00:00:00 2001
From: Eduardo Trujillo <ed@chromabits.com>
Date: Tue, 15 Nov 2022 13:41:56 -0800
Subject: [PATCH] refactor: Remove macro_use for log crate

---
 src/bundle/local_dir/poller.rs |  6 +++---
 src/bundle/mod.rs              | 12 ++++++------
 src/bundle/s3/poller.rs        | 10 +++++-----
 src/cli/serve.rs               |  8 ++++----
 src/config.rs                  |  2 +-
 src/files/path_context.rs      |  2 +-
 src/files/service.rs           | 12 ++++++------
 src/lib.rs                     |  3 ---
 src/main.rs                    |  3 ---
 9 files changed, 26 insertions(+), 32 deletions(-)

diff --git a/src/bundle/local_dir/poller.rs b/src/bundle/local_dir/poller.rs
index 0a10c87..ed38586 100644
--- a/src/bundle/local_dir/poller.rs
+++ b/src/bundle/local_dir/poller.rs
@@ -19,7 +19,7 @@ impl LocalBundlePoller {
 impl BundlePoller for LocalBundlePoller {
   async fn poll(&self, active_bundle: &Option<Bundle>) -> Result<PollResult> {
     if active_bundle.is_none() {
-      info!(
+      log::info!(
         "LocalBundlePoller: Updating bundle (Local dir: {}).",
         self.dir.display()
       );
@@ -30,13 +30,13 @@ impl BundlePoller for LocalBundlePoller {
       });
     }
 
-    info!("LocalBundlePoller: Local dir. No update needed.");
+    log::info!("LocalBundlePoller: Local dir. No update needed.");
 
     Ok(PollResult::Skip)
   }
 
   async fn retrieve(&self, _bundle_id: &str, _path: PathBuf) -> Result<()> {
-    warn!("LocalBundlePoller: retrieve is not supported. Ignoring.");
+    log::warn!("LocalBundlePoller: retrieve is not supported. Ignoring.");
 
     Ok(())
   }
diff --git a/src/bundle/mod.rs b/src/bundle/mod.rs
index 1ec4c56..191aa17 100644
--- a/src/bundle/mod.rs
+++ b/src/bundle/mod.rs
@@ -174,7 +174,7 @@ impl Unbundler {
           _ = interval.tick() => {
             match me.poll().await {
                 Ok(_) => {}
-                Err(err) => error!("Unbundler: Got an error while invoking poller: {:?}", err),
+                Err(err) => log::error!("Unbundler: Got an error while invoking poller: {:?}", err),
             };
           }
       }
@@ -184,7 +184,7 @@ impl Unbundler {
   }
 
   async fn init(&self) -> Result<()> {
-    info!("Unbundler: Initializing...");
+    log::info!("Unbundler: Initializing...");
 
     let mut state = self.state.write().await;
 
@@ -197,7 +197,7 @@ impl Unbundler {
   }
 
   async fn poll(&self) -> Result<()> {
-    info!("Unbundler: Checking for updates...");
+    log::info!("Unbundler: Checking for updates...");
 
     // Update state on a spearate scope to avoid holding a write lock while
     // the poller runs.
@@ -240,7 +240,7 @@ impl Unbundler {
 
         state.status = UnbundlerStatus::Ready;
 
-        info!("Unbundler: No updates from poller.");
+        log::info!("Unbundler: No updates from poller.");
 
         Ok(())
       }
@@ -262,7 +262,7 @@ impl Unbundler {
         let mut state = self.state.write().await;
 
         if state.rundir.subdir_exists(&etag).context(SubDirError)? {
-          warn!("Unbundler: Skipping update. Subdir already exists.");
+          log::warn!("Unbundler: Skipping update. Subdir already exists.");
 
           return Ok(());
         }
@@ -276,7 +276,7 @@ impl Unbundler {
         let result = self.poller.retrieve(&etag, newdir.clone()).await;
 
         if result.is_err() {
-          warn!("Unbundler: Poller failed to retrieve new bundle. Rolling back.");
+          log::warn!("Unbundler: Poller failed to retrieve new bundle. Rolling back.");
 
           state.staging_bundle = None;
           state.status = UnbundlerStatus::Ready;
diff --git a/src/bundle/s3/poller.rs b/src/bundle/s3/poller.rs
index 23aef08..8a2ef57 100644
--- a/src/bundle/s3/poller.rs
+++ b/src/bundle/s3/poller.rs
@@ -81,7 +81,7 @@ impl BundlePoller for S3BundlePoller {
           .context(S3HeadObjectError)?;
 
         if head_response.e_tag == active_bundle.etag {
-          info!(
+          log::info!(
             "S3BundlePoller: No updates found for object: {}",
             self.object_name
           );
@@ -89,13 +89,13 @@ impl BundlePoller for S3BundlePoller {
           // Skip update download
           return Ok(PollResult::Skip);
         } else {
-          info!(
+          log::info!(
             "S3BundlePoller: Object {} has changed. Starting bundle update.",
             self.object_name
           );
         }
       } else {
-        error!("S3BundlePoller: Expected the active bundle to have a valid ETag.");
+        log::error!("S3BundlePoller: Expected the active bundle to have a valid ETag.");
 
         return Err(Error::MissingBundleID);
       }
@@ -120,7 +120,7 @@ impl BundlePoller for S3BundlePoller {
   }
 
   async fn retrieve(&self, bundle_id: &str, path: PathBuf) -> Result<()> {
-    info!("S3BundlePoller: Starting bundle download...");
+    log::info!("S3BundlePoller: Starting bundle download...");
 
     let get_object_request = GetObjectRequest {
       bucket: self.bucket.clone(),
@@ -145,7 +145,7 @@ impl BundlePoller for S3BundlePoller {
       });
     }
 
-    info!("S3BundlePoller: Unpacking bundle...");
+    log::info!("S3BundlePoller: Unpacking bundle...");
 
     let stream = get_object_response
       .body
diff --git a/src/cli/serve.rs b/src/cli/serve.rs
index 641dc51..d494e6f 100644
--- a/src/cli/serve.rs
+++ b/src/cli/serve.rs
@@ -84,7 +84,7 @@ pub async fn serve(config: Arc<Config>) -> Result<()> {
       .context(Unbundle);
 
     if let Err(e) = result {
-      error!("Unbundler failed: {:?}", e);
+      log::error!("Unbundler failed: {:?}", e);
     }
   });
   let unbundler_thread_id = unbundler_thread_handle.thread().id();
@@ -99,7 +99,7 @@ pub async fn serve(config: Arc<Config>) -> Result<()> {
     }
 
     if MONITOR.watch(Some(&watched_thread_ids)).is_err() {
-      error!("Failed to watch threads for panics.");
+      log::error!("Failed to watch threads for panics.");
     }
   });
 
@@ -108,11 +108,11 @@ pub async fn serve(config: Arc<Config>) -> Result<()> {
     monitor_rx.recv().map_err(|_| Error::RecvNotify)?;
 
     if Ok(true) == monitor_thread_handle.get_end_handle().has_ended() {
-      info!("Stopping servers due to a panic.");
+      log::info!("Stopping servers due to a panic.");
 
       break;
     } else if Ok(true) == unbundler_thread_handle.get_end_handle().has_ended() {
-      info!("Stopping servers due to unbundler shutdown.");
+      log::info!("Stopping servers due to unbundler shutdown.");
 
       break;
     }
diff --git a/src/config.rs b/src/config.rs
index 8031cda..bd98938 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -279,7 +279,7 @@ impl From<IndexStrategyConfig> for IndexStrategy {
 pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Config> {
   let path = path.as_ref();
 
-  info!("Reading config file from {}", path.display());
+  log::info!("Reading config file from {}", path.display());
 
   let contents = fs::read_to_string(path).context(OpenConfig { path })?;
 
diff --git a/src/files/path_context.rs b/src/files/path_context.rs
index 36f5a81..e98f065 100644
--- a/src/files/path_context.rs
+++ b/src/files/path_context.rs
@@ -143,7 +143,7 @@ impl PathContext {
     if let Some(headers) = &self.headers {
       for (header_name, header_value) in headers.iter() {
         if header_map.contains_key(header_name) {
-          warn!(
+          log::warn!(
             "Unable to replace header '{}' since it was already set.",
             header_name
           );
diff --git a/src/files/service.rs b/src/files/service.rs
index a17f4aa..33ae2d0 100644
--- a/src/files/service.rs
+++ b/src/files/service.rs
@@ -151,7 +151,7 @@ impl FilesServiceInner {
     log::debug!("Files: Failed to handle {}: {}", req.path(), e);
 
     if let Some(ref default) = self.default {
-      info!("Using default handler");
+      log::info!("Using default handler");
 
       default.call(req).await
     } else {
@@ -194,7 +194,7 @@ impl FilesServiceInner {
     request_context: Option<RequestContext>,
   ) -> Result<ServiceResponse, ActixError> {
     if let Some(request_context) = request_context {
-      debug!(
+      log::debug!(
         "Using custom error path: {:?}",
         request_context.path_context.get_not_found_path()
       );
@@ -207,7 +207,7 @@ impl FilesServiceInner {
           not_found_path,
         ) {
           Ok(path) => {
-            debug!("Custom error page: {:?}", path);
+            log::debug!("Custom error page: {:?}", path);
 
             return self
               .handle_file(
@@ -220,7 +220,7 @@ impl FilesServiceInner {
               )
               .await;
           }
-          Err(err) => error!("Error resolving custom error page: {}", err),
+          Err(err) => log::error!("Error resolving custom error page: {}", err),
         }
       }
     }
@@ -417,7 +417,7 @@ impl FilesServiceInner {
 
     for path_context in self.path_contexts.as_ref() {
       if path_context.matches_path(path_from_request) {
-        debug!(
+        log::debug!(
           "Using matched PathContext. Matcher: {:?}, Path: {}",
           path_context,
           path_from_request.display()
@@ -426,7 +426,7 @@ impl FilesServiceInner {
       }
     }
 
-    debug!(
+    log::debug!(
       "Using root PathContext. Path: {}",
       path_from_request.display()
     );
diff --git a/src/lib.rs b/src/lib.rs
index 65b8c4b..467ae83 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,9 +3,6 @@
 #![deny(clippy::doc_markdown, clippy::match_bool, clippy::match_same_arms)]
 #![warn(future_incompatible)]
 
-#[macro_use]
-extern crate log;
-
 pub mod bundle;
 pub mod config;
 pub mod files;
diff --git a/src/main.rs b/src/main.rs
index 3ed7398..6cb2c7f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,9 +3,6 @@
 #![deny(clippy::doc_markdown, clippy::match_bool, clippy::match_same_arms)]
 #![warn(future_incompatible)]
 
-#[macro_use]
-extern crate log;
-
 use cli::{
   args::{Opts, SubCommand},
   bundle, serve,
-- 
GitLab