Fixed formatting with `rustfmt`.
Removed the stdio bit!
But still starting fern with just stderr if the log file stuff fails.
@@ -22,15 +22,15 @@ extern crate dirs;
extern crate xi_core_lib;
extern crate xi_rpc;
-use std::io;
use std::fs;
+use std::io;
use std::path::PathBuf;
use xi_core_lib::XiCore;
use xi_rpc::RpcLoop;
-const XI_DIRECTORY: &'static str = "xi-core";
-const XI_LOG_FILE: &'static str = "xi-core.log";
+const XI_DIRECTORY: &str = "xi-core";
+const XI_LOG_FILE: &str = "xi-core.log";
fn get_logging_directory() -> Option<PathBuf> {
if let Some(mut log_dir) = dirs::data_local_dir() {
@@ -46,11 +46,14 @@ fn path_for_log_file<P: AsRef<str>>(filename: P) -> Option<PathBuf> {
if let Some(mut logging_directory) = get_logging_directory() {
// Create the logging directory
match fs::create_dir_all(&logging_directory) {
- Ok(_) => (), Err(why) => eprintln!("[WARNING] {:?}", why)
+ Ok(_) => (),
+ Err(why) => eprintln!("[WARNING] {:?}", why),
}
logging_directory.push(filename.as_ref());
Some(logging_directory)
- } else { None }
+ } else {
+ None
+ }
}
fn setup_logging() -> Result<(), fern::InitError> {
@@ -64,7 +67,7 @@ fn setup_logging() -> Result<(), fern::InitError> {
Err(_) => log::LevelFilter::Info,
};
- let fern_dispatch = fern::Dispatch::new()
+ let mut fern_dispatch = fern::Dispatch::new()
.format(|out, message, record| {
out.finish(format_args!(
"{}[{}][{}] {}",
@@ -73,21 +76,18 @@ fn setup_logging() -> Result<(), fern::InitError> {
record.level(),
message,
))
- })
- .level(level_filter)
+ }).level(level_filter)
.chain(io::stderr());
if let Some(logging_file_path) = path_for_log_file(XI_LOG_FILE) {
- fern_dispatch
- .chain(fern::log_file(logging_file_path)?)
- .apply()?;
+ fern_dispatch = fern_dispatch.chain(fern::log_file(logging_file_path)?)
} else {
- eprintln!("[WARNING] There was an issue getting the path for the log file, using stdout");
- fern_dispatch
- .chain(io::stdout())
- .apply()?;
+ eprintln!(
+ "[WARNING] There was an issue getting the path for the log file, just using stderr"
+ );
}
- info!("Logging with fern setup");
+ fern_dispatch.apply()?;
+ info!("Logging with fern is setup");
Ok(())
}
@@ -98,7 +98,10 @@ fn main() {
let mut rpc_looper = RpcLoop::new(stdout);
if let Err(e) = setup_logging() {
- eprintln!("[ERROR] setup_logging returned error, logging disabled: {:?}", e);
+ eprintln!(
+ "[ERROR] setup_logging returned error, logging disabled: {:?}",
+ e
+ );
}
match rpc_looper.mainloop(|| stdin.lock(), &mut state) {
