Skip to content

Commit

Permalink
feat: beauty the log (#32)
Browse files Browse the repository at this point in the history
* feat: beauty the log

* docs: resolve the log
  • Loading branch information
0xRichardH authored Oct 10, 2023
1 parent 9906651 commit 2d6cfe0
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 27 deletions.
136 changes: 120 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ aws-config = "0.56.1"
aws-sdk-s3 = "0.33.0"
clap = { version = "4.4.6", features = ["derive"] }
dotenvy = "0.15.7"
log = "0.4.20"
pgp = "0.10.2"
rand = "0.8.5"
rusqlite = { version = "0.29.0", features = ["backup"] }
simple_logger = "4.2.0"
tempfile = "3.8.0"
time = { version = "0.3.29", features = ["formatting"] }
tokio = { version = "1.33.0", features = ["full"] }
Expand Down
3 changes: 1 addition & 2 deletions docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
- [x] Add GPG encryption support
- encrypt: `add env variable GPG_PASSPHRASE`
- decrypt: `gpg -o backup.tar.gz -d backup.tar.gz.gpg`
- [ ] Beauty the output log
- [ ] Restore SQLite backup (low priority, because we could run `sqlite_backup` backward to restore the data)
- [x] Beauty the output log
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dotenvy::{dotenv, from_filename_override};
use std::{env, ffi::OsString, fmt::Display};

use anyhow::Result;
use anyhow::{Context, Result};

#[derive(PartialEq, Debug)]
pub enum AppEnv {
Expand Down Expand Up @@ -44,16 +44,16 @@ impl Config {
_ => AppEnv::Dev,
};

println!("Running in {app_env} mode");
log::info!("Running in {app_env} mode");

match app_env {
AppEnv::Dev => {
// load environment variables from .env file
dotenv().expect(".env file not found");
dotenv().context(".env file not found")?;
}

AppEnv::Test => {
from_filename_override(".env.test").expect(".env.test file not found");
from_filename_override(".env.test").context(".env.test file not found")?;
}

_ => {
Expand Down
21 changes: 17 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ use sqlite_backup::{
};

#[tokio::main]
async fn main() -> Result<()> {
async fn main() {
simple_logger::init_with_level(log::Level::Info).unwrap();

log::info!("================================================================================");
if let Err(err) = execute().await {
log::error!("{:?}", err)
}
log::info!("================================================================================");
}

async fn execute() -> Result<()> {
log::info!("Starting backup...");

let cfg = Config::load().context("load env vars")?;
let args = Argument::parse();
run(&args, &cfg).await?;

println!("Done");
log::info!("Ending backup...");

Ok(())
}
Expand All @@ -30,9 +42,10 @@ async fn run(arg: &argument::Argument, cfg: &Config) -> Result<()> {
src_file.path.display().to_string(),
dest.clone(),
|p| {
println!(
log::info!(
"---Progress---- pagecount: {}, remaining: {}",
p.pagecount, p.remaining
p.pagecount,
p.remaining
)
},
)
Expand Down
Loading

0 comments on commit 2d6cfe0

Please sign in to comment.