Browse Source

Move the logs to the acme_common lib

pull/5/head
Rodolphe Breard 6 years ago
parent
commit
eb7bc09134
  1. 2
      acme_common/Cargo.toml
  2. 1
      acme_common/src/lib.rs
  3. 15
      acme_common/src/logs.rs
  4. 2
      acmed/Cargo.toml
  5. 7
      acmed/src/main.rs

2
acme_common/Cargo.toml

@ -14,8 +14,10 @@ name = "acme_common"
[dependencies] [dependencies]
base64 = "0.10" base64 = "0.10"
daemonize = "0.4" daemonize = "0.4"
env_logger = "0.6"
handlebars = "2.0.0-beta.1" handlebars = "2.0.0-beta.1"
http_req = "0.4" http_req = "0.4"
log = "0.4"
openssl = "0.10" openssl = "0.10"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"

1
acme_common/src/lib.rs

@ -2,6 +2,7 @@ use daemonize::Daemonize;
pub mod error; pub mod error;
pub mod gen; pub mod gen;
pub mod logs;
pub fn b64_encode<T: ?Sized + AsRef<[u8]>>(input: &T) -> String { pub fn b64_encode<T: ?Sized + AsRef<[u8]>>(input: &T) -> String {
base64::encode_config(input, base64::URL_SAFE_NO_PAD) base64::encode_config(input, base64::URL_SAFE_NO_PAD)

15
acmed/src/logs.rs → acme_common/src/logs.rs

@ -1,8 +1,11 @@
use acme_common::error::Error;
use crate::error::Error;
use env_logger::Builder; use env_logger::Builder;
use log::LevelFilter; use log::LevelFilter;
use syslog::Facility; use syslog::Facility;
const DEFAULT_LOG_SYSTEM: LogSystem = LogSystem::SysLog;
const DEFAULT_LOG_LEVEL: LevelFilter = LevelFilter::Warn;
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum LogSystem { pub enum LogSystem {
SysLog, SysLog,
@ -21,7 +24,7 @@ fn get_loglevel(log_level: Option<&str>) -> Result<LevelFilter, Error> {
return Err(format!("{}: invalid log level", v).into()); return Err(format!("{}: invalid log level", v).into());
} }
}, },
None => crate::DEFAULT_LOG_LEVEL,
None => DEFAULT_LOG_LEVEL,
}; };
Ok(level) Ok(level)
} }
@ -53,7 +56,7 @@ pub fn set_log_system(
} else if has_stderr { } else if has_stderr {
LogSystem::StdErr LogSystem::StdErr
} else { } else {
crate::DEFAULT_LOG_SYSTEM
DEFAULT_LOG_SYSTEM
}; };
match logtype { match logtype {
LogSystem::SysLog => set_log_syslog(log_level)?, LogSystem::SysLog => set_log_syslog(log_level)?,
@ -64,7 +67,7 @@ pub fn set_log_system(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::set_log_system;
use super::{set_log_system, DEFAULT_LOG_LEVEL, DEFAULT_LOG_SYSTEM};
#[test] #[test]
fn test_invalid_level() { fn test_invalid_level() {
@ -77,7 +80,7 @@ mod tests {
let ret = set_log_system(None, false, false); let ret = set_log_system(None, false, false);
assert!(ret.is_ok()); assert!(ret.is_ok());
let (logtype, log_level) = ret.unwrap(); 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);
} }
} }

2
acmed/Cargo.toml

@ -14,14 +14,12 @@ build = "build.rs"
[dependencies] [dependencies]
acme_common = { path = "../acme_common" } acme_common = { path = "../acme_common" }
clap = "2.32" clap = "2.32"
env_logger = "0.6"
handlebars = "2.0.0-beta.1" handlebars = "2.0.0-beta.1"
http_req = "0.4" http_req = "0.4"
log = "0.4" log = "0.4"
openssl = "0.10" openssl = "0.10"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
syslog = "4.0"
time = "0.1" time = "0.1"
toml = "0.5" toml = "0.5"

7
acmed/src/main.rs

@ -1,13 +1,12 @@
use crate::main_event_loop::MainEventLoop; use crate::main_event_loop::MainEventLoop;
use acme_common::init_server; use acme_common::init_server;
use clap::{App, Arg}; use clap::{App, Arg};
use log::{error, LevelFilter};
use log::error;
mod acme_proto; mod acme_proto;
mod certificate; mod certificate;
mod config; mod config;
mod hooks; mod hooks;
mod logs;
mod main_event_loop; mod main_event_loop;
mod storage; 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_PK_FILE_MODE: u32 = 0o600;
pub const DEFAULT_ACCOUNT_FILE_MODE: u32 = 0o600; pub const DEFAULT_ACCOUNT_FILE_MODE: u32 = 0o600;
pub const DEFAULT_KP_REUSE: bool = false; 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_JWS_SIGN_ALGO: &str = "ES256";
pub const DEFAULT_POOL_NB_TRIES: usize = 20; pub const DEFAULT_POOL_NB_TRIES: usize = 20;
pub const DEFAULT_POOL_WAIT_SEC: u64 = 5; pub const DEFAULT_POOL_WAIT_SEC: u64 = 5;
@ -80,7 +77,7 @@ fn main() {
) )
.get_matches(); .get_matches();
match logs::set_log_system(
match acme_common::logs::set_log_system(
matches.value_of("log-level"), matches.value_of("log-level"),
matches.is_present("log-syslog"), matches.is_present("log-syslog"),
matches.is_present("to-stderr"), matches.is_present("to-stderr"),

Loading…
Cancel
Save