Skip to content

feat/refactor: Replace Logger module with tracing_subscriber + tracing libs #135

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

Open
wants to merge 7 commits into
base: unstable
Choose a base branch
from
Open
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
210 changes: 183 additions & 27 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ regex = "1.11.1"
serde = { version = "1.0.219", features = ["derive"] }
serde-xml-rs = "0.6.0"
serde_json = "1.0.140"
tracing = "0.1"
tracing-appender = "0.2.3"
tracing-subscriber = { version = "0.3.19", features = ["fmt", "std", "json"] }
thiserror = "2.0.12"
clap = { version = "4.5.35", features = ["derive"] }
chrono = "0.4.40"
Expand Down
39 changes: 24 additions & 15 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{
log_on_error,
monitoring::logging::garbage_collector::collect_garbage,
ui::popup::{info_popup::InfoPopUp, PopUp},
};
use ansi_to_tui::IntoText;
use color_eyre::eyre::bail;
use config::Config;
use cover_renderer::render_cover;
use logging::Logger;
use patch_hub::lore::{
lore_api_client::BlockingLoreAPIClient,
lore_session,
Expand All @@ -23,12 +23,12 @@ use screens::{
CurrentScreen,
};
use std::collections::{HashMap, HashSet};
use tracing::{event, Level};

use crate::utils;

pub mod config;
pub mod cover_renderer;
pub mod logging;
pub mod patch_renderer;
pub mod screens;

Expand Down Expand Up @@ -59,8 +59,7 @@ pub struct App {
impl App {
/// Creates a new instance of `App`. It dynamically loads configurations
/// based on precedence (see [crate::app::Config::build]), app data
/// (available mailing lists, bookmarked patchsets, reviewed patchsets), and
/// initializes the Logger (see [crate::app::logging::Logger])
/// (available mailing lists, bookmarked patchsets, reviewed patchsets)
///
/// # Returns
///
Expand All @@ -79,10 +78,8 @@ impl App {

let lore_api_client = BlockingLoreAPIClient::default();

// Initialize the logger before the app starts
Logger::init_log_file(&config)?;
Logger::info("patch-hub started");
logging::garbage_collector::collect_garbage(&config);
event!(Level::INFO, "patch-hub started");
collect_garbage(&config);

Ok(App {
current_screen: CurrentScreen::MailingListSelection,
Expand Down Expand Up @@ -207,7 +204,10 @@ impl App {
{
Ok(render) => render,
Err(_) => {
Logger::error("Failed to render cover preview with external program");
event!(
Level::ERROR,
"Failed to render cover preview with external program"
);
raw_cover.to_string()
}
};
Expand All @@ -216,7 +216,8 @@ impl App {
match render_patch_preview(raw_patch, self.config.patch_renderer()) {
Ok(render) => render,
Err(_) => {
Logger::error(
event!(
Level::ERROR,
"Failed to render patch preview with external program",
);
raw_patch.to_string()
Expand Down Expand Up @@ -392,30 +393,38 @@ impl App {
let mut app_can_run = true;

if !utils::binary_exists("b4") {
Logger::error("b4 is not installed, patchsets cannot be downloaded");
event!(
Level::ERROR,
"b4 is not installed, patchsets cannot be downloaded"
);
app_can_run = false;
}

if !utils::binary_exists("git") {
Logger::warn("git is not installed, send-email won't work");
event!(Level::WARN, "git is not installed, send-email won't work");
}

match self.config.patch_renderer() {
PatchRenderer::Bat => {
if !utils::binary_exists("bat") {
Logger::warn("bat is not installed, patch rendering will fallback to default");
event!(
Level::WARN,
"bat is not installed, patch rendering will fallback to default"
);
}
}
PatchRenderer::Delta => {
if !utils::binary_exists("delta") {
Logger::warn(
event!(
Level::WARN,
"delta is not installed, patch rendering will fallback to default",
);
}
}
PatchRenderer::DiffSoFancy => {
if !utils::binary_exists("diff-so-fancy") {
Logger::warn(
event!(
Level::WARN,
"diff-so-fancy is not installed, patch rendering will fallback to default",
);
}
Expand Down
5 changes: 2 additions & 3 deletions src/app/cover_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::{
};

use serde::{Deserialize, Serialize};

use super::logging::Logger;
use tracing::{event, Level};

#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
pub enum CoverRenderer {
Expand Down Expand Up @@ -68,7 +67,7 @@ fn bat_cover_renderer(patch: &str) -> color_eyre::Result<String> {
.stdout(Stdio::piped())
.spawn()
.map_err(|e| {
Logger::error(format!("Failed to spawn bat for cover preview: {}", e));
event!(Level::ERROR, "Failed to spawn bat for cover preview: {}", e);
e
})?;

Expand Down
Loading
Loading