From: Ian Jackson Date: Fri, 25 Dec 2020 18:05:13 +0000 (+0000) Subject: arrange to split log_config from config X-Git-Tag: otter-0.2.0~132 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=9b0a8878038c164a355f9e64d966ab4ece4148b0;p=otter.git arrange to split log_config from config Mostly to make debug better Signed-off-by: Ian Jackson --- diff --git a/src/bin/daemon-otter.rs b/src/bin/daemon-otter.rs index 41cb0e6c..25cd534d 100644 --- a/src/bin/daemon-otter.rs +++ b/src/bin/daemon-otter.rs @@ -213,7 +213,7 @@ fn main() { let c = config(); - flexi_logger::Logger::with(c.log.clone()).start()?; + flexi_logger::Logger::with(log_config().clone()).start()?; debug!("resolved config: {:#?}", c); diff --git a/src/config.rs b/src/config.rs index f9069d10..1f9bee4e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -36,6 +36,12 @@ pub struct ServerConfigSpec { pub sendmail: Option, } +#[derive(Debug,Clone)] +pub struct WholeServerConfig { + server: Arc, + log: LogSpecification, +} + #[derive(Debug,Clone)] pub struct ServerConfig { save_dir: String, @@ -48,16 +54,15 @@ pub struct ServerConfig { pub template_dir: String, pub nwtemplate_dir: String, pub wasm_dir: String, - pub log: LogSpecification, pub bundled_sources: String, pub shapelibs: Vec, pub sendmail: String, } -impl TryFrom for ServerConfig { +impl TryFrom for WholeServerConfig { type Error = AE; #[throws(Self::Error)] - fn try_from(spec: ServerConfigSpec) -> ServerConfig { + fn try_from(spec: ServerConfigSpec) -> WholeServerConfig { let ServerConfigSpec { base_dir, save_dir, command_socket, debug, http_port, public_url, sse_wildcard_url, rocket_workers, @@ -122,21 +127,28 @@ impl TryFrom for ServerConfig { let log = LogSpecification::from_toml(&log) .context("log specification")?; - ServerConfig { + let server = ServerConfig { save_dir, command_socket, debug, http_port, public_url, sse_wildcard_url, rocket_workers, template_dir, nwtemplate_dir, wasm_dir, - log, bundled_sources, shapelibs, sendmail, + bundled_sources, shapelibs, sendmail, + }; + WholeServerConfig { + server: Arc::new(server), + log, } } } pub fn config() -> Arc { - GLOBAL.config.read().unwrap().clone() + GLOBAL.config.read().unwrap().server.clone() +} +pub fn log_config() -> LogSpecification { + GLOBAL.config.read().unwrap().log.clone() } -fn set_config(config: ServerConfig) { - *GLOBAL.config.write().unwrap() = Arc::new(config) +fn set_config(whole: WholeServerConfig) { + *GLOBAL.config.write().unwrap() = whole; } impl ServerConfig { @@ -149,9 +161,9 @@ impl ServerConfig { let mut buf = String::new(); File::open(&config_filename).with_context(||config_filename.to_string())? .read_to_string(&mut buf)?; - let config : ServerConfigSpec = toml_de::from_str(&buf)?; - let config = config.try_into()?; - set_config(config); + let spec : ServerConfigSpec = toml_de::from_str(&buf)?; + let whole = spec.try_into()?; + set_config(whole); } #[throws(AE)] @@ -175,8 +187,8 @@ impl ServerConfig { } } -impl Default for ServerConfig { - fn default() -> ServerConfig { +impl Default for WholeServerConfig { + fn default() -> WholeServerConfig { let spec: ServerConfigSpec = toml_de::from_str(r#" public_url = "INTERNAL ERROR" "#) diff --git a/src/global.rs b/src/global.rs index 025fb045..2c07faea 100644 --- a/src/global.rs +++ b/src/global.rs @@ -195,7 +195,7 @@ pub struct Global { // <- InstanceContainer -> // inner locks which the game needs: dirty: Mutex>, - pub config: RwLock>, + pub config: RwLock, // fast global lookups players: RwLock>,