Skip to content

Commit

Permalink
fix(frontmatter-gen): 🐛 Error: Process completed with exit code 101.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Nov 24, 2024
1 parent 5b19d84 commit 3f2b432
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
use anyhow::Result;
use log::LevelFilter;
use std::env;
use std::process;
use std::{env, process, sync::Once};

// Conditional imports based on features
#[cfg(feature = "cli")]
Expand All @@ -61,6 +60,8 @@ use frontmatter_gen::cli::Cli;
#[cfg(feature = "ssg")]
use frontmatter_gen::ssg::SsgCommand;

static INIT: Once = Once::new();

/// Main entry point for the Frontmatter Generator tool.
///
/// This function initializes the logging system, determines the enabled features,
Expand Down Expand Up @@ -122,37 +123,34 @@ async fn main() -> Result<()> {
/// cargo run
/// ```
fn setup_logging() {
// Get desired log level from RUST_LOG env var, default to "debug"
let env =
env::var("RUST_LOG").unwrap_or_else(|_| "debug".to_string());

// Define the logger level based on the environment variable
let level = match env.to_lowercase().as_str() {
"error" => LevelFilter::Error,
"warn" => LevelFilter::Warn,
"info" => LevelFilter::Info,
"debug" => LevelFilter::Debug,
"trace" => LevelFilter::Trace,
"off" => LevelFilter::Off,
_ => {
log::warn!(
"Invalid RUST_LOG value '{}', defaulting to 'debug'",
env
);
LevelFilter::Debug
}
};

// Set up the logger
log::set_logger(&LOGGER)
.map(|()| log::set_max_level(level))
.unwrap_or_else(|e| {
eprintln!("Warning: Failed to initialize logger: {}", e);
});
INIT.call_once(|| {
// Get desired log level from RUST_LOG env var, default to "debug"
let env = env::var("RUST_LOG").unwrap_or_else(|_| "debug".to_string());

// Define the logger level based on the environment variable
let level = match env.to_lowercase().as_str() {
"error" => LevelFilter::Error,
"warn" => LevelFilter::Warn,
"info" => LevelFilter::Info,
"debug" => LevelFilter::Debug,
"trace" => LevelFilter::Trace,
"off" => LevelFilter::Off,

Check warning on line 137 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L136-L137

Added lines #L136 - L137 were not covered by tests
_ => {
eprintln!(

Check warning on line 139 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L139

Added line #L139 was not covered by tests
"Invalid RUST_LOG value '{}', defaulting to 'debug'",
env
);
LevelFilter::Debug

Check warning on line 143 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L143

Added line #L143 was not covered by tests
}
};

if level != LevelFilter::Off {
log::info!("Logging initialized at level `{}`", level);
}
// Set up the logger
if log::set_logger(&LOGGER).is_ok() {
log::set_max_level(level);
} else {
eprintln!("Logger already initialized.");

Check warning on line 151 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L151

Added line #L151 was not covered by tests
}
});
}

/// Executes the appropriate command based on enabled features.
Expand Down

0 comments on commit 3f2b432

Please sign in to comment.