feat: Logging

Also initial progress on the upload interface
This commit is contained in:
quexeky
2026-01-19 18:54:41 +11:00
parent 320d323880
commit 6e21e40648
13 changed files with 1198 additions and 72 deletions
+70 -20
View File
@@ -1,35 +1,85 @@
use std::{env, path::PathBuf, sync::LazyLock};
use anyhow::Result;
use crate::{
cli::{Cli, Commands},
commands::{configure::interactive_configure, upload},
};
use clap::Parser;
use droplet_rs::manifest::generate_manifest_rusty;
use indicatif::{ProgressBar, ProgressStyle};
use tokio::runtime::Handle;
use crate::{cli::{Cli, Commands}, commands::configure::interactive_configure};
use fern::colors::{Color, ColoredLevelConfig};
use log::LevelFilter;
use std::env;
use std::fs;
use std::io;
mod cli;
mod commands;
pub static CLI: LazyLock<Cli> = LazyLock::new(|| Cli::parse());
mod manifest;
#[tokio::main]
async fn main() -> Result<()> {
match &CLI.command {
async fn main() -> anyhow::Result<()> {
configure_logging()?;
let cli = Cli::parse();
match &cli.command {
Commands::Configure { url, token } => {
if let Some(token) = token {
todo!()
} else {
interactive_configure(url.to_string()).await?;
}
},
Commands::Upload {
path,
game_id,
version_id,
} => todo!(),
}
Commands::Upload(info) => {
upload::interface::upload(info).await?;
}
};
Ok(())
}
pub fn configure_logging() -> anyhow::Result<()> {
let log_level = env::var("RUST_LOG")
.or_else(|_| env::var("LOG_LEVEL"))
.unwrap_or_else(|_| "info".to_string())
.parse::<LevelFilter>()?;
let log_dir = env::var("LOG_FILE_DIR").unwrap_or_else(|_| "logs".to_string());
fs::create_dir_all(&log_dir)?;
let colors = ColoredLevelConfig::new()
.error(Color::Red)
.warn(Color::Yellow)
.info(Color::Green)
.debug(Color::Blue)
.trace(Color::Magenta);
fern::Dispatch::new()
.chain(
// Console output with colors and formatting
fern::Dispatch::new()
.format(move |out, message, record| {
out.finish(format_args!(
"[{}] {} {} - {}",
chrono::Local::now().format("%Y-%m-%d %H:%M:%S%.3f"),
colors.color(record.level()),
record.target(),
message
))
})
.chain(io::stdout()),
)
.chain(
// File output without colors and with formatting
fern::Dispatch::new()
.format(|out, message, record| {
out.finish(format_args!(
"[{}] {} {} - {}",
chrono::Local::now().format("%Y-%m-%d %H:%M:%S%.3f"),
record.level(),
record.target(),
message
))
})
.chain(fern::log_file(format!("{}/app.log", log_dir))?),
)
.level(log_level)
.apply()?;
Ok(())
}