Merge branch 'runtime-logging-init-imag'
This merge adds logging capabilities to the `imag` binaries. For this, the libimagrt had to get a new compiletime feature which makes the logging initialization public for this usecase. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
commit
9978bce622
4 changed files with 32 additions and 3 deletions
|
@ -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"]
|
||||
|
||||
|
|
|
@ -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<BTreeMap<String, String>, Str
|
|||
|
||||
fn forward_commandline_arguments(m: &ArgMatches, scmd: &mut Vec<String>) {
|
||||
let push = |flag: Option<&str>, val_name: &str, m: &ArgMatches, v: &mut Vec<String>| {
|
||||
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| {
|
||||
|
|
|
@ -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 = []
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue