mirror of
https://github.com/kristoferssolo/traxor.git
synced 2025-10-21 20:10:35 +00:00
fix(log): decrease log size
This commit is contained in:
parent
b988880c41
commit
b563c7ea24
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -342,6 +342,7 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn",
|
||||||
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2045,6 +2046,7 @@ dependencies = [
|
|||||||
"color-eyre",
|
"color-eyre",
|
||||||
"crossterm 0.29.0",
|
"crossterm 0.29.0",
|
||||||
"derive_macro",
|
"derive_macro",
|
||||||
|
"derive_more",
|
||||||
"dirs",
|
"dirs",
|
||||||
"merge",
|
"merge",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
@ -2102,6 +2104,12 @@ version = "0.2.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
|
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-xid"
|
||||||
|
version = "0.2.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "untrusted"
|
name = "untrusted"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
|||||||
@ -6,9 +6,10 @@ license = "GPLv3"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
derive_macro = { path = "derive_macro" }
|
|
||||||
color-eyre = "0.6"
|
color-eyre = "0.6"
|
||||||
crossterm = "0.29"
|
crossterm = "0.29"
|
||||||
|
derive_macro = { path = "derive_macro" }
|
||||||
|
derive_more = { version = "2.0", features = ["display"] }
|
||||||
dirs = "6.0"
|
dirs = "6.0"
|
||||||
merge = "0.2"
|
merge = "0.2"
|
||||||
ratatui = { version = "0.29" }
|
ratatui = { version = "0.29" }
|
||||||
|
|||||||
@ -1,20 +1,39 @@
|
|||||||
#[derive(Debug, Clone, PartialEq)]
|
use derive_more::Display;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Display)]
|
||||||
pub enum Action {
|
pub enum Action {
|
||||||
|
#[display("Quit")]
|
||||||
Quit,
|
Quit,
|
||||||
|
#[display("Next Tab")]
|
||||||
NextTab,
|
NextTab,
|
||||||
|
#[display("Previous Tab")]
|
||||||
PrevTab,
|
PrevTab,
|
||||||
|
#[display("Next Torrent")]
|
||||||
NextTorrent,
|
NextTorrent,
|
||||||
|
#[display("Previous Torrent")]
|
||||||
PrevTorrent,
|
PrevTorrent,
|
||||||
|
#[display("Switch to Tab {}", _0)]
|
||||||
SwitchTab(u8),
|
SwitchTab(u8),
|
||||||
|
#[display("Toggle Help")]
|
||||||
ToggleHelp,
|
ToggleHelp,
|
||||||
|
#[display("Toggle Torrent")]
|
||||||
ToggleTorrent,
|
ToggleTorrent,
|
||||||
|
#[display("Toggle All Torrents")]
|
||||||
ToggleAll,
|
ToggleAll,
|
||||||
|
#[display("Pause All Torrents")]
|
||||||
PauseAll,
|
PauseAll,
|
||||||
|
#[display("Start All Torrents")]
|
||||||
StartAll,
|
StartAll,
|
||||||
|
#[display("Move Torrent(-s)")]
|
||||||
Move,
|
Move,
|
||||||
|
#[display("Delete Torrent(-s) (force: {})", _0)]
|
||||||
Delete(bool),
|
Delete(bool),
|
||||||
|
#[display("Rename Torrent")]
|
||||||
Rename,
|
Rename,
|
||||||
|
#[display("Select")]
|
||||||
Select,
|
Select,
|
||||||
|
#[display("Submit")]
|
||||||
Submit,
|
Submit,
|
||||||
|
#[display("Cancel")]
|
||||||
Cancel,
|
Cancel,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use derive_macro::FromFile;
|
use derive_macro::FromFile;
|
||||||
use merge::{option::overwrite_none, Merge};
|
use merge::{Merge, option::overwrite_none};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, Merge)]
|
#[derive(Debug, Clone, Deserialize, Serialize, Merge)]
|
||||||
|
|||||||
@ -9,6 +9,7 @@ use log::{LogConfig, LogConfigFile};
|
|||||||
use merge::{Merge, option::overwrite_none};
|
use merge::{Merge, option::overwrite_none};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use tracing::{debug, info, warn};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Deserialize, Serialize, Merge)]
|
#[derive(Debug, Clone, Default, Deserialize, Serialize, Merge)]
|
||||||
pub struct ConfigFile {
|
pub struct ConfigFile {
|
||||||
@ -28,28 +29,39 @@ pub struct Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
#[tracing::instrument(name = "Loading configuration")]
|
||||||
pub fn load() -> Result<Self> {
|
pub fn load() -> Result<Self> {
|
||||||
let mut config = ConfigFile::default();
|
let mut config = ConfigFile::default();
|
||||||
|
|
||||||
// Load system-wide config
|
// Load system-wide config
|
||||||
let system_config_path = PathBuf::from("/etc/xdg/traxor/config.toml");
|
let system_config_path = PathBuf::from("/etc/xdg/traxor/config.toml");
|
||||||
if system_config_path.exists() {
|
if system_config_path.exists() {
|
||||||
|
info!("Loading system-wide config from: {:?}", system_config_path);
|
||||||
let config_str = std::fs::read_to_string(&system_config_path)?;
|
let config_str = std::fs::read_to_string(&system_config_path)?;
|
||||||
let system_config = toml::from_str::<ConfigFile>(&config_str)?;
|
let system_config = toml::from_str::<ConfigFile>(&config_str)?;
|
||||||
config.merge(system_config);
|
config.merge(system_config);
|
||||||
|
info!("Successfully loaded system-wide config.");
|
||||||
|
} else {
|
||||||
|
warn!("System-wide config not found at: {:?}", system_config_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load user-specific config
|
// Load user-specific config
|
||||||
let user_config_path = Self::get_config_path()?;
|
let user_config_path = Self::get_config_path()?;
|
||||||
if user_config_path.exists() {
|
if user_config_path.exists() {
|
||||||
|
info!("Loading user-specific config from: {:?}", user_config_path);
|
||||||
let config_str = std::fs::read_to_string(&user_config_path)?;
|
let config_str = std::fs::read_to_string(&user_config_path)?;
|
||||||
let user_config = toml::from_str::<ConfigFile>(&config_str)?;
|
let user_config = toml::from_str::<ConfigFile>(&config_str)?;
|
||||||
config.merge(user_config);
|
config.merge(user_config);
|
||||||
|
info!("Successfully loaded user-specific config.");
|
||||||
|
} else {
|
||||||
|
warn!("User-specific config not found at: {:?}", user_config_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug!("Configuration loaded successfully.");
|
||||||
Ok(config.into())
|
Ok(config.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(name = "Getting config path")]
|
||||||
fn get_config_path() -> Result<PathBuf> {
|
fn get_config_path() -> Result<PathBuf> {
|
||||||
let config_dir = std::env::var("XDG_CONFIG_HOME")
|
let config_dir = std::env::var("XDG_CONFIG_HOME")
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
use crate::app::{App, action::Action};
|
use crate::app::{App, action::Action};
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||||
use tracing::{Level, event, info_span};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
|
#[tracing::instrument(name = "Handling input", skip(app))]
|
||||||
async fn handle_input(key_event: KeyEvent, app: &mut App<'_>) -> Result<Option<Action>> {
|
async fn handle_input(key_event: KeyEvent, app: &mut App<'_>) -> Result<Option<Action>> {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
KeyCode::Enter => Ok(Some(Action::Submit)),
|
KeyCode::Enter => Ok(Some(Action::Submit)),
|
||||||
@ -26,15 +27,13 @@ async fn handle_input(key_event: KeyEvent, app: &mut App<'_>) -> Result<Option<A
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the key events of [`App`].
|
/// Handles the key events of [`App`].
|
||||||
#[tracing::instrument]
|
#[tracing::instrument(name = "Getting action", skip(app))]
|
||||||
pub async fn get_action(key_event: KeyEvent, app: &mut App<'_>) -> Result<Option<Action>> {
|
pub async fn get_action(key_event: KeyEvent, app: &mut App<'_>) -> Result<Option<Action>> {
|
||||||
if app.input_mode {
|
if app.input_mode {
|
||||||
return handle_input(key_event, app).await;
|
return handle_input(key_event, app).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let span = info_span!("get_action");
|
debug!("handling key event: {:?}", key_event);
|
||||||
let _enter = span.enter();
|
|
||||||
event!(Level::INFO, "handling key event: {:?}", key_event);
|
|
||||||
|
|
||||||
let keybinds = &app.config.keybinds;
|
let keybinds = &app.config.keybinds;
|
||||||
|
|
||||||
@ -65,11 +64,9 @@ pub async fn get_action(key_event: KeyEvent, app: &mut App<'_>) -> Result<Option
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the updates of [`App`].
|
/// Handles the updates of [`App`].
|
||||||
#[tracing::instrument]
|
#[tracing::instrument(name = "Update", skip(app))]
|
||||||
pub async fn update(app: &mut App<'_>, action: Action) -> Result<()> {
|
pub async fn update(app: &mut App<'_>, action: Action) -> Result<()> {
|
||||||
let span = info_span!("update");
|
info!("updating app with action: {}", action);
|
||||||
let _enter = span.enter();
|
|
||||||
event!(Level::INFO, "updating app with action: {:?}", action);
|
|
||||||
match action {
|
match action {
|
||||||
Action::Quit => app.quit(),
|
Action::Quit => app.quit(),
|
||||||
Action::NextTab => app.next_tab(),
|
Action::NextTab => app.next_tab(),
|
||||||
|
|||||||
19
src/main.rs
19
src/main.rs
@ -1,6 +1,7 @@
|
|||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use ratatui::{Terminal, backend::CrosstermBackend};
|
use ratatui::{Terminal, backend::CrosstermBackend};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use tracing::{debug, trace};
|
||||||
use traxor::{
|
use traxor::{
|
||||||
app::App,
|
app::App,
|
||||||
config::Config,
|
config::Config,
|
||||||
@ -14,8 +15,9 @@ use traxor::{
|
|||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
|
|
||||||
// Load configuration.
|
debug!("Loading configuration...");
|
||||||
let config = Config::load()?;
|
let config = Config::load()?;
|
||||||
|
debug!("Configuration loaded.");
|
||||||
|
|
||||||
// Setup the logger.
|
// Setup the logger.
|
||||||
setup_logger(&config)?;
|
setup_logger(&config)?;
|
||||||
@ -36,14 +38,23 @@ async fn main() -> Result<()> {
|
|||||||
tui.draw(&mut app)?;
|
tui.draw(&mut app)?;
|
||||||
// Handle events.
|
// Handle events.
|
||||||
match tui.events.next()? {
|
match tui.events.next()? {
|
||||||
Event::Tick => app.tick().await?,
|
Event::Tick => {
|
||||||
|
trace!(target: "app", "Event::Tick");
|
||||||
|
app.tick().await?;
|
||||||
|
}
|
||||||
Event::Key(key_event) => {
|
Event::Key(key_event) => {
|
||||||
|
trace!(target: "app", "Event::Key: {:?}", key_event);
|
||||||
if let Some(action) = get_action(key_event, &mut app).await? {
|
if let Some(action) = get_action(key_event, &mut app).await? {
|
||||||
|
trace!(target: "app", "Action: {:?}", action);
|
||||||
update(&mut app, action).await?;
|
update(&mut app, action).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Mouse(_) => {}
|
Event::Mouse(mouse_event) => {
|
||||||
Event::Resize(_, _) => {}
|
trace!(target: "app", "Event::Mouse: {:?}", mouse_event);
|
||||||
|
}
|
||||||
|
Event::Resize(x, y) => {
|
||||||
|
trace!(target: "app", "Event::Resize: ({}, {})", x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user