diff --git a/bin/core/imag/Cargo.toml b/bin/core/imag/Cargo.toml index 77472b8c..d40da6c3 100644 --- a/bin/core/imag/Cargo.toml +++ b/bin/core/imag/Cargo.toml @@ -33,7 +33,6 @@ log = "0.4.0" toml = "0.4" toml-query = "0.7" -libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" } libimagerror = { version = "0.9.0", path = "../../../lib/core/libimagerror" } [dependencies.clap] @@ -41,3 +40,8 @@ version = "^2.29" default-features = false features = ["suggestions", "color", "wrap_help"] +[dependencies.libimagrt] +version = "0.9.0" +path = "../../../lib/core/libimagrt" +features = ["pub_logging_initialization"] + diff --git a/bin/core/imag/src/main.rs b/bin/core/imag/src/main.rs index 37279dd0..1c469ec1 100644 --- a/bin/core/imag/src/main.rs +++ b/bin/core/imag/src/main.rs @@ -60,6 +60,7 @@ use libimagrt::spec::CliSpec; use libimagerror::io::ToExitCode; use libimagerror::exit::ExitUnwrap; use libimagerror::trace::trace_error; +use libimagrt::configuration::InternalConfiguration; /// Returns the helptext, putting the Strings in cmds as possible /// subcommands into it @@ -182,7 +183,9 @@ fn main() { } } + let enable_logging = app.enable_logging(); let matches = app.matches(); + let rtp = ::libimagrt::runtime::get_rtp_match(&matches); let configpath = matches .value_of(Runtime::arg_config_name()) @@ -194,6 +197,10 @@ fn main() { exit(1) }); + if enable_logging { + Runtime::init_logger(&matches, config.as_ref()) + } + debug!("matches: {:?}", matches); // Begin checking for arguments @@ -261,6 +268,7 @@ fn main() { None => Vec::new() }; + debug!("Processing forwarding of commandline arguments"); forward_commandline_arguments(&matches, &mut subcommand_args); let subcommand = String::from(subcommand); @@ -366,6 +374,9 @@ fn fetch_aliases(config: Option<&Value>) -> Result, Str fn forward_commandline_arguments(m: &ArgMatches, scmd: &mut Vec) { let push = |flag: Option<&str>, val_name: &str, m: &ArgMatches, v: &mut Vec| { + debug!("Push({flag:?}, {val_name:?}, {matches:?}, {v:?}", + flag = flag, val_name = val_name, matches = m, v = v); + let _ = m .value_of(val_name) .map(|val| { diff --git a/lib/core/libimagrt/Cargo.toml b/lib/core/libimagrt/Cargo.toml index 7c31ae64..611a49c2 100644 --- a/lib/core/libimagrt/Cargo.toml +++ b/lib/core/libimagrt/Cargo.toml @@ -53,6 +53,11 @@ features = ["no_logging"] [features] default = [] +# Make logger initialization inside `runtime::Runtime` public. +# This feature is _only_ used for the `imag` binary itself. You do not need this +# feature and if you think you do you're doing it wrong. +pub_logging_initialization = [] + # Enable testing functionality. Used for building the libimagrt for testing CLI # apps. Do not use in production! testing = [] diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs index 4dfe3b5f..f42ee88d 100644 --- a/lib/core/libimagrt/src/runtime.rs +++ b/lib/core/libimagrt/src/runtime.rs @@ -127,6 +127,7 @@ impl<'a> Runtime<'a> { debug!("RTP path = {:?}", rtp); debug!("Store path = {:?}", storepath); + debug!("CLI = {:?}", matches); let store_result = if cli_app.use_inmemory_fs() { Store::new_with_backend(storepath, @@ -317,14 +318,22 @@ impl<'a> Runtime<'a> { "logging-destinations" } + #[cfg(feature = "pub_logging_initialization")] + pub fn init_logger(matches: &ArgMatches, config: Option<&Value>) { + Self::_init_logger(matches, config) + } + #[cfg(not(feature = "pub_logging_initialization"))] + fn init_logger(matches: &ArgMatches, config: Option<&Value>) { + Self::_init_logger(matches, config) + } + /// Initialize the internal logger /// /// If the environment variable "IMAG_LOG_ENV" is set, this simply /// initializes a env-logger instance. Errors are ignored in this case. /// If the environment variable is not set, this initializes the internal imag logger. On /// error, this exits (as there is nothing we can do about that) - /// - fn init_logger(matches: &ArgMatches, config: Option<&Value>) { + fn _init_logger(matches: &ArgMatches, config: Option<&Value>) { use log::set_max_level; use log::set_boxed_logger; use std::env::var as env_var;