Fixed startup error when terminal isn't available
This commit is contained in:
parent
fc9049fea5
commit
2bd1b8220d
1 changed files with 27 additions and 3 deletions
30
src/main.rs
30
src/main.rs
|
@ -67,6 +67,8 @@ use std::path::Path;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use simplelog::{Config, TermLogger, LogLevelFilter};
|
use simplelog::{Config, TermLogger, LogLevelFilter};
|
||||||
|
#[cfg(unix)]
|
||||||
|
use simplelog::{SimpleLogger};
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
mod config;
|
mod config;
|
||||||
|
@ -115,6 +117,30 @@ fn daemonize(options: &getopts::Matches) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn init_log(log_level: LogLevelFilter, options: &getopts::Matches) -> Result<()> {
|
||||||
|
if options.opt_present("f") {
|
||||||
|
if let Err(e) = TermLogger::init(log_level, Config::default()) {
|
||||||
|
bail!("Error starting terminal logger: {}", e);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if let Err(e) = SimpleLogger::init(log_level, Config::default()) {
|
||||||
|
bail!("Error starting simple logger: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn init_log(log_level: LogLevelFilter, _: &getopts::Matches) -> Result<()> {
|
||||||
|
if let Err(e) = TermLogger::init(log_level, Config::default()) {
|
||||||
|
bail!("Error starting terminal logger: {}", e);
|
||||||
|
};
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn run() -> Result<()> {
|
fn run() -> Result<()> {
|
||||||
|
|
||||||
// Parse CLI options
|
// Parse CLI options
|
||||||
|
@ -153,9 +179,7 @@ fn run() -> Result<()> {
|
||||||
_ => LogLevelFilter::Info,
|
_ => LogLevelFilter::Info,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = TermLogger::init(log_level, Config::default()) {
|
init_log(log_level, &matches)?;
|
||||||
bail!("Error starting logger: {}", e);
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
daemonize(&matches)?;
|
daemonize(&matches)?;
|
||||||
|
|
Loading…
Add table
Reference in a new issue