# HG changeset patch # User Jiri Vanek # Date 1550498626 -3600 # Node ID bfafe88b8719d22be7b8e1b0bf49f93779ae8d08 # Parent 42fc135e170bec9c89cc01b50f926b0b034a03fb For linux, implemented and used system logging * rust-launcher/src/hardcoded_paths.rs: call to info moved to important * rust-launcher/src/jars_helper.rs: same * rust-launcher/src/log_helper.rs: if log_to_system is true(defoult) log_impl logs important messages also to system log * rust-launcher/src/os_access.rs: added trait methods of important and system_log. Implemented for Linux * rust-launcher/src/utils.rs:call to info moved to important. TestLogger got implemented and important and system_log declared as panicking diff -r 42fc135e170b -r bfafe88b8719 ChangeLog --- a/ChangeLog Mon Feb 18 14:43:05 2019 +0100 +++ b/ChangeLog Mon Feb 18 15:03:46 2019 +0100 @@ -1,3 +1,13 @@ +2019-02-18 Jiri Vanek + + For linux, implemented and used system logging + * rust-launcher/src/hardcoded_paths.rs: call to info moved to important + * rust-launcher/src/jars_helper.rs: same + * rust-launcher/src/log_helper.rs: if log_to_system is true(defoult) log_impl logs important messages also to system log + * rust-launcher/src/os_access.rs: added trait methods of important and system_log. Implemented for Linux + * rust-launcher/src/utils.rs:call to info moved to important. TestLogger got implemented and important and system_log + declared as panicking + 2019-02-17 Jiri Vanek Implemented proper file logging diff -r 42fc135e170b -r bfafe88b8719 rust-launcher/src/hardcoded_paths.rs --- a/rust-launcher/src/hardcoded_paths.rs Mon Feb 18 14:43:05 2019 +0100 +++ b/rust-launcher/src/hardcoded_paths.rs Mon Feb 18 15:03:46 2019 +0100 @@ -107,7 +107,7 @@ _err => { let mut info = String::new(); write!(&mut info, "ITW-LIBS provided, but have invalid value of {}. Use BUNDLED, DISTRIBUTION or BOTH", result_of_override_var); - logger.info(&info); + logger.important(&info); } } _error => { diff -r 42fc135e170b -r bfafe88b8719 rust-launcher/src/jars_helper.rs --- a/rust-launcher/src/jars_helper.rs Mon Feb 18 14:43:05 2019 +0100 +++ b/rust-launcher/src/jars_helper.rs Mon Feb 18 15:03:46 2019 +0100 @@ -77,7 +77,7 @@ } else { let mut info1 = String::new(); write!(&mut info1, "custom ITW_HOME provided, but do not exists or is not directory: {}", &(dirs_paths_helper::path_to_string(&custom_dir))); - logger.info(&info1); + logger.important(&info1); } } _error => { @@ -113,9 +113,9 @@ } } //fallback to hardcoded, but warn - logger.info("Warning!, Fall back in resolve_jar to hardcoded paths: "); + logger.important("Warning!, Fall back in resolve_jar to hardcoded paths: "); let result = std::path::PathBuf::from(full_hardcoded_path); - logger.info(&dirs_paths_helper::path_to_string(&result)); + logger.important(&dirs_paths_helper::path_to_string(&result)); result } diff -r 42fc135e170b -r bfafe88b8719 rust-launcher/src/log_helper.rs --- a/rust-launcher/src/log_helper.rs Mon Feb 18 14:43:05 2019 +0100 +++ b/rust-launcher/src/log_helper.rs Mon Feb 18 15:03:46 2019 +0100 @@ -14,7 +14,14 @@ //1 info //2 debug only pub fn log_impl(level: i32, os: &os_access::Os, s: &str) { - if level == 0 {} else if level == 1 { + if level == 0 { + println!("{}", s); + if os.advanced_logging().log_to_system { + let mut info2 = String::from("IcedTea-Web nativerustlauncher error. Consult - https://icedtea.classpath.org/wiki/IcedTea-Web\n"); + info2.push_str(s); + os.system_log(&info2); + } + } else if level == 1 { println!("{}", s); } else if level == 2 { if os.is_verbose() { diff -r 42fc135e170b -r bfafe88b8719 rust-launcher/src/os_access.rs --- a/rust-launcher/src/os_access.rs Mon Feb 18 14:43:05 2019 +0100 +++ b/rust-launcher/src/os_access.rs Mon Feb 18 15:03:46 2019 +0100 @@ -35,6 +35,8 @@ fn advanced_logging(&self) -> &log_helper::AdvancedLogging; fn log(&self, s: &str); fn info(&self, s: &str); + fn important(&self, s: &str); + fn system_log(&self, s: &str); fn get_registry_jdk(&self) -> Option; // next to system and home cfg dir, there is also by-jre config dir, but that do not need to be handled os-specific way // https://docs.oracle.com/javase/7/docs/technotes/guides/jweb/jcp/properties.html @@ -74,6 +76,29 @@ #[cfg(not(windows))] impl Os for Linux { + fn system_log(&self, s: &str) { + let mut cmd = std::process::Command::new("logger"); + cmd.arg("-p"); + cmd.arg("user.err"); + cmd.arg("--"); + cmd.arg(s); + let output_result = cmd.output(); + match output_result { + Ok(output) => { + let mut info = String::new(); + write!(&mut info, "itw-rust-debug: system log call returned {}", output.status.code().expect("Failed to read syslog process return value")).expect("unwrap failed"); + self.log(&info); + if !output.status.success() { + self.log(&String::from_utf8(output.stdout).expect("sout should unwrap")); + self.log(&String::from_utf8(output.stderr).expect("serr should unwrap")); + } + } + _error => { + self.log("itw-rust-debug: failed to call system log"); + } + } + } + fn advanced_logging(&self) -> &log_helper::AdvancedLogging { return &self.al; } @@ -82,7 +107,6 @@ return self.verbose; } - fn log(&self, s: &str) { log_helper::log_impl(2,self, s); } @@ -91,6 +115,10 @@ log_helper::log_impl(1,self, s); } + fn important(&self, s: &str) { + log_helper::log_impl(0,self, s); + } + fn get_registry_jdk(&self) -> Option { None } @@ -176,6 +204,8 @@ #[cfg(windows)] impl Os for Windows { + fn system_log(&self, s: &str){/*no go for now*/} + fn advanced_logging(&self) -> &log_helper::AdvancedLogging { return &self.al; } @@ -188,6 +218,10 @@ log_helper::log_impl(1,self, s); } + fn important(&self, s: &str) { + log_helper::log_impl(0,self, s); + } + fn is_verbose(&self) -> bool { return self.verbose; } diff -r 42fc135e170b -r bfafe88b8719 rust-launcher/src/utils.rs --- a/rust-launcher/src/utils.rs Mon Feb 18 14:43:05 2019 +0100 +++ b/rust-launcher/src/utils.rs Mon Feb 18 15:03:46 2019 +0100 @@ -65,7 +65,7 @@ None } else { if libsearch == hardcoded_paths::ItwLibSearch::BOTH { - os.info("your build is done as BOTH distribution and bundled, jdk from PATH may be not what you want!"); + os.important("your build is done as BOTH distribution and bundled, jdk from PATH may be not what you want!"); } get_jdk_from_given_path_testable(system_path, os) } @@ -99,7 +99,7 @@ if jre_bin_dir.file_name().expect("java's parent should have name") == "bin" { jre_dir = std::path::PathBuf::from(jre_bin_dir.parent().expect("java's bin dir should have parent")) } else { - os.info("Error: JRE from path seems to not have bin dir"); + os.important("Error: JRE from path seems to not have bin dir"); jre_dir = match jre_bin_dir.parent() { Some(p) => { //.../bin/ -> ... @@ -218,6 +218,8 @@ impl os_access::Os for TestLogger { + fn system_log(&self, s: &str){ panic!("not implemented"); } + fn advanced_logging(&self) -> &log_helper::AdvancedLogging { panic!("not implemented"); } @@ -236,6 +238,11 @@ self.vec.borrow_mut().push(ss); } + fn important(&self, s: &str) { + let ss = String::from(s); + self.vec.borrow_mut().push(ss); + } + fn get_registry_jdk(&self) -> Option { None }