diff --git a/acme_common/Cargo.toml b/acme_common/Cargo.toml index 8564b49..1b5125d 100644 --- a/acme_common/Cargo.toml +++ b/acme_common/Cargo.toml @@ -14,8 +14,10 @@ name = "acme_common" [dependencies] base64 = "0.10" daemonize = "0.4" +env_logger = "0.6" handlebars = "2.0.0-beta.1" http_req = "0.4" +log = "0.4" openssl = "0.10" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/acme_common/src/lib.rs b/acme_common/src/lib.rs index 33c7625..dd6fad2 100644 --- a/acme_common/src/lib.rs +++ b/acme_common/src/lib.rs @@ -2,6 +2,7 @@ use daemonize::Daemonize; pub mod error; pub mod gen; +pub mod logs; pub fn b64_encode>(input: &T) -> String { base64::encode_config(input, base64::URL_SAFE_NO_PAD) diff --git a/acmed/src/logs.rs b/acme_common/src/logs.rs similarity index 83% rename from acmed/src/logs.rs rename to acme_common/src/logs.rs index 1f07dc3..7db3cd2 100644 --- a/acmed/src/logs.rs +++ b/acme_common/src/logs.rs @@ -1,8 +1,11 @@ -use acme_common::error::Error; +use crate::error::Error; use env_logger::Builder; use log::LevelFilter; use syslog::Facility; +const DEFAULT_LOG_SYSTEM: LogSystem = LogSystem::SysLog; +const DEFAULT_LOG_LEVEL: LevelFilter = LevelFilter::Warn; + #[derive(Debug, PartialEq, Eq)] pub enum LogSystem { SysLog, @@ -21,7 +24,7 @@ fn get_loglevel(log_level: Option<&str>) -> Result { return Err(format!("{}: invalid log level", v).into()); } }, - None => crate::DEFAULT_LOG_LEVEL, + None => DEFAULT_LOG_LEVEL, }; Ok(level) } @@ -53,7 +56,7 @@ pub fn set_log_system( } else if has_stderr { LogSystem::StdErr } else { - crate::DEFAULT_LOG_SYSTEM + DEFAULT_LOG_SYSTEM }; match logtype { LogSystem::SysLog => set_log_syslog(log_level)?, @@ -64,7 +67,7 @@ pub fn set_log_system( #[cfg(test)] mod tests { - use super::set_log_system; + use super::{set_log_system, DEFAULT_LOG_LEVEL, DEFAULT_LOG_SYSTEM}; #[test] fn test_invalid_level() { @@ -77,7 +80,7 @@ mod tests { let ret = set_log_system(None, false, false); assert!(ret.is_ok()); let (logtype, log_level) = ret.unwrap(); - assert_eq!(logtype, crate::DEFAULT_LOG_SYSTEM); - assert_eq!(log_level, crate::DEFAULT_LOG_LEVEL); + assert_eq!(logtype, DEFAULT_LOG_SYSTEM); + assert_eq!(log_level, DEFAULT_LOG_LEVEL); } } diff --git a/acmed/Cargo.toml b/acmed/Cargo.toml index 33cae5c..8ec41c9 100644 --- a/acmed/Cargo.toml +++ b/acmed/Cargo.toml @@ -14,14 +14,12 @@ build = "build.rs" [dependencies] acme_common = { path = "../acme_common" } clap = "2.32" -env_logger = "0.6" handlebars = "2.0.0-beta.1" http_req = "0.4" log = "0.4" openssl = "0.10" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -syslog = "4.0" time = "0.1" toml = "0.5" diff --git a/acmed/src/main.rs b/acmed/src/main.rs index aa957d3..0a86163 100644 --- a/acmed/src/main.rs +++ b/acmed/src/main.rs @@ -1,13 +1,12 @@ use crate::main_event_loop::MainEventLoop; use acme_common::init_server; use clap::{App, Arg}; -use log::{error, LevelFilter}; +use log::error; mod acme_proto; mod certificate; mod config; mod hooks; -mod logs; mod main_event_loop; mod storage; @@ -25,8 +24,6 @@ pub const DEFAULT_CERT_FILE_MODE: u32 = 0o644; pub const DEFAULT_PK_FILE_MODE: u32 = 0o600; pub const DEFAULT_ACCOUNT_FILE_MODE: u32 = 0o600; pub const DEFAULT_KP_REUSE: bool = false; -pub const DEFAULT_LOG_SYSTEM: logs::LogSystem = logs::LogSystem::SysLog; -pub const DEFAULT_LOG_LEVEL: LevelFilter = LevelFilter::Warn; pub const DEFAULT_JWS_SIGN_ALGO: &str = "ES256"; pub const DEFAULT_POOL_NB_TRIES: usize = 20; pub const DEFAULT_POOL_WAIT_SEC: u64 = 5; @@ -80,7 +77,7 @@ fn main() { ) .get_matches(); - match logs::set_log_system( + match acme_common::logs::set_log_system( matches.value_of("log-level"), matches.is_present("log-syslog"), matches.is_present("to-stderr"),