Mercurial > hg > icedtea-web
changeset 1554:65de3b40a457
Implemented basic stub for file logging
* rust-launcher/src/log_helper.rs: extracted log_impl from os.Implemented (always on for now) call to log to file
* rust-launcher/src/main.rs: made aware of new log_hlper module
* rust-launcher/src/os_access.rs: adapted to log_helper. Added forgotten is_verbose to windows os impl.
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Sat, 16 Feb 2019 20:56:33 +0100 |
parents | 6bf82af023c1 |
children | 7ef277699fd1 |
files | ChangeLog rust-launcher/src/log_helper.rs rust-launcher/src/main.rs rust-launcher/src/os_access.rs |
diffstat | 4 files changed, 66 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sat Feb 16 18:51:33 2019 +0100 +++ b/ChangeLog Sat Feb 16 20:56:33 2019 +0100 @@ -1,3 +1,13 @@ +2019-02-16 Jiri Vanek <jvanek@redhat.com> + + Implemented basic stub for file logging + * rust-launcher/src/log_helper.rs: extracted log_impl from os. + Implemented (always on for now) call to log to file + * rust-launcher/src/main.rs: made aware of new log_hlper module + * rust-launcher/src/os_access.rs: adapted to log_helper. Added forgotten is_verbose + to windows os impl. + + 2019-02-16 Jiri Vanek <jvanek@redhat.com> * rust-launcher/src/os_access.rs: removed duplicated code from windows launchers
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rust-launcher/src/log_helper.rs Sat Feb 16 20:56:33 2019 +0100 @@ -0,0 +1,46 @@ +use os_access; +use std::fs::OpenOptions; +use std::io::Write; +use std::time::SystemTime; +use std::time::UNIX_EPOCH; +use std::fs::File; + +static mut first: bool = true; + +//0 critical +//1 info +//2 debug only +pub fn log_impl(level: i32, os: &os_access::Os, s: &str) { + if level == 0 {} else if level == 1 { + println!("{}", s); + } else if level == 2 { + if os.is_verbose() { + println!("{}", s); + } + } + unsafe { + if first { + //mkdir + //createfile + //rust itw log initiate dor so + first = false; + let start = SystemTime::now(); + let t = start.duration_since(UNIX_EPOCH).expect("time should be measureable"); + let mut file = File::create("my-file").expect("failed to create file log"); + if let Err(e) = write!(&mut file, "itw-rust-debug: file log started: {}\n", t.as_secs()) { + println!("Couldn't write to file: {}", e); + } + file.sync_all(); + } + } + let mut file = OpenOptions::new() + .write(true) + .append(true) + .open("my-file") + .expect("failed to append to file log"); + + if let Err(e) = writeln!(&mut file, "{}", s) { + println!("Couldn't write to file: {}", e); + } + file.sync_all(); +} \ No newline at end of file
--- a/rust-launcher/src/main.rs Sat Feb 16 18:51:33 2019 +0100 +++ b/rust-launcher/src/main.rs Sat Feb 16 20:56:33 2019 +0100 @@ -6,6 +6,7 @@ mod utils; mod property; mod jars_helper; +mod log_helper; use std::string::String; use std::fmt::Write;
--- a/rust-launcher/src/os_access.rs Sat Feb 16 18:51:33 2019 +0100 +++ b/rust-launcher/src/os_access.rs Sat Feb 16 20:56:33 2019 +0100 @@ -2,6 +2,7 @@ use dirs_paths_helper; use std::env; use std::fmt::Write; +use log_helper; pub fn create_java_cmd(os: &Os,jre_dir: &std::path::PathBuf, args: &Vec<String>) -> std::process::Command { let mut bin_java = jre_dir.clone(); @@ -29,20 +30,6 @@ java executable: [{}], arguments: [{:?}]", jre_dir.clone().into_os_string().to_str().expect("path should unwrap"), args) } } -//0 critical -//1 info -//2 debug only -fn log_impl(level: i32, os: &Os, s: &str) { - if level == 0 { - - } else if level == 1 { - println!("{}", s); - } else if level == 2 { - if os.is_verbose() { - println!("{}", s); - } - } -} pub trait Os { // logging "api" can change @@ -88,11 +75,11 @@ fn log(&self, s: &str) { - log_impl(2,self, s); + log_helper::log_impl(2,self, s); } fn info(&self, s: &str) { - log_impl(1,self, s); + log_helper::log_impl(1,self, s); } fn get_registry_jdk(&self) -> Option<std::path::PathBuf> { @@ -176,11 +163,15 @@ #[cfg(windows)] impl Os for Windows { fn log(&self, s: &str) { - log_impl(2,self, s); + log_helper::log_impl(2,self, s); } fn info(&self, s: &str) { - log_impl(1,self, s); + log_helper::log_impl(1,self, s); + } + + fn is_verbose(&self) -> bool { + return self.verbose; } fn get_registry_jdk(&self) -> Option<std::path::PathBuf> {