# HG changeset patch # User Jiri Vanek # Date 1550321600 -3600 # Node ID db378366679b5d7a77c132954a70d0127d0f78d9 # Parent 8b44a9e23bd2ea1cc56e4921967eb73ababde04c Native launchers got loading (unused for now) of advanced logging properties * rust-launcher/src/dirs_paths_helper.rs: added struct AdvancedLogging which holds setup of extended logging * rust-launcher/src/main.rs: now load advanced settings from properties. Debug output of jre from properties moved to utils.rs * rust-launcher/src/property_from_file.rs: declared keys for advanced logging properties. Added simple string validator. * rust-launcher/src/property_from_files_resolver.rs: now provides reading methods with validation for new logging keys * rust-launcher/src/utils.rs: got that logging message from main. diff -r 8b44a9e23bd2 -r db378366679b ChangeLog --- a/ChangeLog Sat Feb 16 13:45:10 2019 +0100 +++ b/ChangeLog Sat Feb 16 13:53:20 2019 +0100 @@ -1,3 +1,12 @@ +2019-02-16 Jiri Vanek + + Native launchers got loading (unused for now) of advanced logging properties + * rust-launcher/src/dirs_paths_helper.rs: added struct AdvancedLogging which holds setup of extended logging + * rust-launcher/src/main.rs: now load advanced settings from properties. Debug output of jre from properties moved to utils.rs + * rust-launcher/src/property_from_file.rs: declared keys for advanced logging properties. Added simple string validator. + * rust-launcher/src/property_from_files_resolver.rs: now provides reading methods with validation for new logging keys + * rust-launcher/src/utils.rs: got that logging message from main. + 2019-02-16 Jiri Vanek * Makefile.am: fixed issue with MODULARJDK_ARGS_FILE being installded as executable diff -r 8b44a9e23bd2 -r db378366679b rust-launcher/src/dirs_paths_helper.rs --- a/rust-launcher/src/dirs_paths_helper.rs Sat Feb 16 13:45:10 2019 +0100 +++ b/rust-launcher/src/dirs_paths_helper.rs Sat Feb 16 13:53:20 2019 +0100 @@ -1,4 +1,5 @@ use os_access; +use property_from_files_resolver; use std; use std::env; @@ -7,6 +8,37 @@ pub static DEPLOYMENT_PROPERTIES: &'static str = "deployment.properties"; +pub struct AdvancedLogging { + pub log_to_file: bool, + pub user_logdir: std::path::PathBuf, + pub log_to_stdstreams: bool , + pub log_to_system: bool, +} + +impl Default for AdvancedLogging { + fn default() -> AdvancedLogging { + AdvancedLogging { + log_to_file: false, + user_logdir: std::path::PathBuf::from("undeffined"), + log_to_stdstreams: true, + log_to_system: true + } + } +} + +impl AdvancedLogging { + pub fn load(os: &os_access::Os) -> AdvancedLogging { + AdvancedLogging { + log_to_file: property_from_files_resolver::try_log_to_file_from_properties(os), + log_to_stdstreams: property_from_files_resolver::try_log_to_streams_from_properties(os), + log_to_system: property_from_files_resolver::try_log_to_system_from_properties(os), + user_logdir: property_from_files_resolver::try_custom_logdir_from_properties(os) + } + } + + +} + pub fn get_xdg_config_dir(os: &os_access::Os) -> Option { match env::var("XDG_CONFIG_HOME") { Ok(war) => { diff -r 8b44a9e23bd2 -r db378366679b rust-launcher/src/main.rs --- a/rust-launcher/src/main.rs Sat Feb 16 13:45:10 2019 +0100 +++ b/rust-launcher/src/main.rs Sat Feb 16 13:53:20 2019 +0100 @@ -75,9 +75,7 @@ fn main() { let os = get_os(is_debug_on()); os.log(&dirs_paths_helper::path_to_string(&dirs_paths_helper::current_program())); - let mut info1 = String::new(); - write!(&mut info1, "itw-rust-debug: trying jdk over properties ({})", property_from_file::JRE_PROPERTY_NAME).expect("unwrap failed"); - os.log(&info1); + let al = dirs_paths_helper::AdvancedLogging::load(&os); let java_dir = utils::find_jre(&os); let mut info2 = String::new(); write!(&mut info2, "selected jre: {}", java_dir.display()).expect("unwrap failed"); @@ -199,7 +197,7 @@ os.log("itw-rust-debug: unrecognized jdk! Fallback to 8!"); return 8; } - _Error => { + _error => { os.log("itw-rust-debug: failed to launch jdk recognition. fallback to 8"); return 8 } diff -r 8b44a9e23bd2 -r db378366679b rust-launcher/src/property_from_file.rs --- a/rust-launcher/src/property_from_file.rs Sat Feb 16 13:45:10 2019 +0100 +++ b/rust-launcher/src/property_from_file.rs Sat Feb 16 13:53:20 2019 +0100 @@ -10,6 +10,11 @@ pub static JRE_PROPERTY_NAME: &'static str = "deployment.jre.dir"; pub static VERBOSE_PROPERTY_NAME: &'static str = "deployment.log"; +pub static KEY_USER_LOG_DIR: &'static str = "deployment.user.logdir"; //custom log file; default to xdg_confgi/icedtea-web/log +pub static KEY_ENABLE_LOGGING_TOFILE: &'static str = "deployment.log.file"; //is loging to file enabled? default false +pub static KEY_ENABLE_LOGGING_TOSTREAMS: &'static str = "deployment.log.stdstreams";//is logging to stdouts enabled?defoult true +pub static KEY_ENABLE_LOGGING_TOSYSTEMLOG: &'static str = "deployment.log.system";//is logging to system logs enabled? default true + pub trait Validator { fn validate(&self, s: &str) -> bool; @@ -47,6 +52,21 @@ } } +pub struct NotMandatoryPathValidator {} + + +impl Validator for NotMandatoryPathValidator { + fn validate(&self, _s: &str) -> bool { + true + } + + fn get_fail_message(&self, key: &str, value: &str, file: &Option) -> String { + let mut res = String::new(); + write!(&mut res, "the String value of {} read from {} under key {} is not valid. Expected String", value, file.clone().expect("jre path should be loaded").display(), key).expect("unwrap failed"); + return res; + } +} + fn verify_bool_string(val: &String) -> bool { val.trim().to_lowercase() == "true" || val.trim().to_lowercase() == "false" } diff -r 8b44a9e23bd2 -r db378366679b rust-launcher/src/property_from_files_resolver.rs --- a/rust-launcher/src/property_from_files_resolver.rs Sat Feb 16 13:45:10 2019 +0100 +++ b/rust-launcher/src/property_from_files_resolver.rs Sat Feb 16 13:53:20 2019 +0100 @@ -34,6 +34,64 @@ } } +pub fn try_log_to_file_from_properties(logger: &os_access::Os) -> bool { + let str_bool = try_key_from_properties_files(logger, &get_basic_array(logger), property_from_file::KEY_ENABLE_LOGGING_TOFILE, &property_from_file::BoolValidator {}); + match str_bool { + Some(val) => { + property_from_file::str_to_bool(&val) + } + None => { + dirs_paths_helper::AdvancedLogging::default().log_to_file + } + } +} + +pub fn try_log_to_streams_from_properties(logger: &os_access::Os) -> bool { + let str_bool = try_key_from_properties_files(logger, &get_basic_array(logger), property_from_file::KEY_ENABLE_LOGGING_TOSTREAMS, &property_from_file::BoolValidator {}); + match str_bool { + Some(val) => { + property_from_file::str_to_bool(&val) + } + None => { + dirs_paths_helper::AdvancedLogging::default().log_to_stdstreams + } + } +} + +pub fn try_log_to_system_from_properties(logger: &os_access::Os) -> bool { + let str_bool = try_key_from_properties_files(logger, &get_basic_array(logger), property_from_file::KEY_ENABLE_LOGGING_TOSYSTEMLOG, &property_from_file::BoolValidator {}); + match str_bool { + Some(val) => { + property_from_file::str_to_bool(&val) + } + None => { + dirs_paths_helper::AdvancedLogging::default().log_to_system + } + } +} + +pub fn try_custom_logdir_from_properties(logger: &os_access::Os) -> std::path::PathBuf { + let str_candidate = try_key_from_properties_files(logger, &get_basic_array(logger), property_from_file::KEY_USER_LOG_DIR, &property_from_file::NotMandatoryPathValidator {}); + match str_candidate { + Some(val) => { + std::path::PathBuf::from(val) + } + None => { + let mut cfgdir_candidate = logger.get_user_config_dir(); + match cfgdir_candidate { + Some(mut cfgdir) => { + cfgdir.push("/log"); + cfgdir + } + None => { + std::path::PathBuf::from("unloadable") + } + } + } + } +} + + fn try_key_from_properties_files(logger: &os_access::Os, array: &[Option], key: &str, validator: &property_from_file::Validator) -> Option { for file in array { let mut info1 = String::new(); diff -r 8b44a9e23bd2 -r db378366679b rust-launcher/src/utils.rs --- a/rust-launcher/src/utils.rs Sat Feb 16 13:45:10 2019 +0100 +++ b/rust-launcher/src/utils.rs Sat Feb 16 13:53:20 2019 +0100 @@ -6,8 +6,12 @@ use std::fmt::Write; use hardcoded_paths; use property_from_files_resolver; +use property_from_file; pub fn find_jre(os: &os_access::Os) -> std::path::PathBuf { + let mut info1 = String::new(); + write!(&mut info1, "itw-rust-debug: trying jdk over properties ({})", property_from_file::JRE_PROPERTY_NAME).expect("unwrap failed"); + os.log(&info1); match property_from_files_resolver::try_jdk_from_properties(os) { Some(path) => { os.log("itw-rust-debug: found and using");