Skip to content

Commit

Permalink
Introduce tracing for log
Browse files Browse the repository at this point in the history
  • Loading branch information
riseshia committed Aug 21, 2024
1 parent 39513ab commit 0fad6b0
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
91 changes: 91 additions & 0 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 @@ -24,3 +24,5 @@ console = "0.15.8"
aws-smithy-runtime-api = "1.7.1"
aws-smithy-types = "1.2.0"
anyhow = "1.0.86"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
9 changes: 9 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub enum Commands {
/// Specify path to diff result as json
#[clap(long = "diff-as-json", short = 'o', value_name = "output path")]
json_diff_path: Option<String>,
/// Emit logs for debugging
#[clap(long = "debug")]
debug_mode: bool,
},
/// plan config
Plan {
Expand All @@ -42,6 +45,9 @@ pub enum Commands {
/// Specify path to diff result as json
#[clap(long = "diff-as-json", short = 'o', value_name = "output path")]
json_diff_path: Option<String>,
/// Emit logs for debugging
#[clap(long = "debug")]
debug_mode: bool,
},
/// import state machine to specified config file
Import {
Expand All @@ -60,6 +66,9 @@ pub enum Commands {
value_name = "group-name/schedule-name"
)]
schedule_name_with_group: Option<String>,
/// Emit logs for debugging
#[clap(long = "debug")]
debug_mode: bool,
},
}

Expand Down
22 changes: 22 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ use fubura::context::FuburaContext;
use fubura::fast_exit;
use fubura::types::Config;

fn set_log_level(debug_mode: &bool) {
let level = if *debug_mode {
tracing::Level::DEBUG
} else {
tracing::Level::INFO
};

let subscriber = tracing_subscriber::FmtSubscriber::builder()
.with_max_level(level)
.finish();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
}

#[tokio::main]
async fn main() {
let cli = Cli::parse();
Expand All @@ -21,7 +34,10 @@ async fn main() {
ext_str,
target,
json_diff_path,
debug_mode,
} => {
set_log_level(debug_mode);

let config = Config::load_from_path(config_path, ext_str);
let mut context = FuburaContext::async_default().await;
context.targets.clone_from(target);
Expand All @@ -34,7 +50,10 @@ async fn main() {
ext_str,
target,
json_diff_path,
debug_mode,
} => {
set_log_level(debug_mode);

let config = Config::load_from_path(config_path, ext_str);
let mut context = FuburaContext::async_default().await;
context.targets.clone_from(target);
Expand All @@ -47,7 +66,10 @@ async fn main() {
ext_str,
sfn_name,
schedule_name_with_group,
debug_mode,
} => {
set_log_level(debug_mode);

let config_exist = Path::new(config_path).exists();
let config = if config_exist {
Config::load_from_path(config_path, ext_str)
Expand Down

0 comments on commit 0fad6b0

Please sign in to comment.