From: Ian Jackson Date: Sat, 5 Sep 2020 15:53:16 +0000 (+0100) Subject: parse log config X-Git-Tag: otter-0.2.0~1021 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=426333cb41a97954ee23cdc06fdeedf20a608ccc;p=otter.git parse log config --- diff --git a/Cargo.lock.example b/Cargo.lock.example index f92c0963..431ed268 100644 --- a/Cargo.lock.example +++ b/Cargo.lock.example @@ -377,6 +377,26 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "flexi_logger" +version = "0.15.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaab3caedb4149800f91e8e4899f29cd9ddf3b569b04c365ca9334f92f7542bf" +dependencies = [ + "atty", + "chrono", + "glob 0.3.0", + "lazy_static", + "log 0.4.11", + "notify", + "regex", + "serde", + "serde_derive", + "thiserror", + "toml 0.5.6", + "yansi", +] + [[package]] name = "fs2" version = "0.4.3" @@ -431,11 +451,13 @@ dependencies = [ "arrayvec", "failure", "fehler", + "flexi_logger", "fs2", "htmlescape", "index_vec", "inventory", "lazy_static", + "log 0.4.11", "nix", "num-traits", "percent-encoding 2.1.0", diff --git a/Cargo.toml b/Cargo.toml index dd27710b..ba29b04d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,9 @@ typetag = "0.1" rmp-serde = "0.14" rmp = "^0.8" +log = "0.4" +flexi_logger = { version = "0.15", features = [ "specfile" ] } + uds = "0" pwd = "1" failure = "0.1.8" # for pwd diff --git a/src/global.rs b/src/global.rs index 0123ace6..b0007e81 100644 --- a/src/global.rs +++ b/src/global.rs @@ -935,6 +935,7 @@ pub struct ServerConfigSpec { pub http_port: Option, pub rocket_workers: Option, pub template_dir: Option, + pub log: toml::Value, } #[derive(Debug,Clone)] @@ -945,6 +946,7 @@ pub struct ServerConfig { pub http_port: Option, pub rocket_workers: u16, pub template_dir: String, + pub log: LogSpecification, } impl TryFrom for ServerConfig { @@ -953,7 +955,7 @@ impl TryFrom for ServerConfig { fn try_from(spec: ServerConfigSpec) -> ServerConfig { let ServerConfigSpec { save_directory, command_socket, debug, - http_port, rocket_workers, template_dir + http_port, rocket_workers, template_dir, log, } = spec; let save_directory = save_directory @@ -972,9 +974,13 @@ impl TryFrom for ServerConfig { let template_dir = template_dir .unwrap_or_else(|| DEFAULT_TEMPLATE_DIR.to_owned()); + let log = toml::to_string(&log)?; + let log = LogSpecification::from_toml(&log) + .context("log specification")?; + ServerConfig { save_directory, command_socket, debug, - http_port, rocket_workers, template_dir + http_port, rocket_workers, template_dir, log, } } } diff --git a/src/imports.rs b/src/imports.rs index 5a87a8e6..6ef553e8 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -67,6 +67,8 @@ pub use regex::Regex; pub use arrayvec::ArrayVec; +pub use flexi_logger::{LogSpecification}; + pub use crate::global::*; pub use crate::gamestate::*; pub use crate::pieces::*;