mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2024-12-26 07:05:56 -05:00
use mylog::Format::from_str
This commit is contained in:
parent
de56739571
commit
482d8a3074
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1292,7 +1292,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "mylog"
|
name = "mylog"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/scottlamb/mylog#00d39a9ca0c1f399c453360de3f1e7f61db0d50d"
|
source = "git+https://github.com/scottlamb/mylog#bebeacb74efc127f9c16e57e38886c8e6ba8a95c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"log",
|
"log",
|
||||||
|
13
src/main.rs
13
src/main.rs
@ -31,6 +31,7 @@
|
|||||||
#![cfg_attr(all(feature="nightly", test), feature(test))]
|
#![cfg_attr(all(feature="nightly", test), feature(test))]
|
||||||
|
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
|
use std::str::FromStr;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
mod body;
|
mod body;
|
||||||
@ -93,20 +94,12 @@ impl Args {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_fmt<S: AsRef<str>>(fmt: S) -> Option<mylog::Format> {
|
|
||||||
match fmt.as_ref() {
|
|
||||||
"google" => Some(mylog::Format::Google),
|
|
||||||
"google-systemd" => Some(mylog::Format::GoogleSystemd),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::from_args();
|
let args = Args::from_args();
|
||||||
let mut h = mylog::Builder::new()
|
let mut h = mylog::Builder::new()
|
||||||
.set_format(::std::env::var("MOONFIRE_FORMAT")
|
.set_format(::std::env::var("MOONFIRE_FORMAT")
|
||||||
.ok()
|
.map_err(|_| ())
|
||||||
.and_then(parse_fmt)
|
.and_then(|s| mylog::Format::from_str(&s))
|
||||||
.unwrap_or(mylog::Format::Google))
|
.unwrap_or(mylog::Format::Google))
|
||||||
.set_spec(&::std::env::var("MOONFIRE_LOG").unwrap_or("info".to_owned()))
|
.set_spec(&::std::env::var("MOONFIRE_LOG").unwrap_or("info".to_owned()))
|
||||||
.build();
|
.build();
|
||||||
|
Loading…
Reference in New Issue
Block a user