use std::collections::HashMap;
use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AccessLog {
pub path: PathBuf,
pub format_name: Option<String>,
pub options: HashMap<String, String>,
pub context: LogContext,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum LogContext {
Main,
Server(String),
Location(String),
}
impl AccessLog {
#[must_use]
pub fn new(path: impl Into<PathBuf>) -> Self {
Self {
path: path.into(),
format_name: None,
options: HashMap::new(),
context: LogContext::Main,
}
}
#[must_use]
pub fn with_format(mut self, format: impl Into<String>) -> Self {
self.format_name = Some(format.into());
self
}
#[must_use]
pub fn with_context(mut self, context: LogContext) -> Self {
self.context = context;
self
}
#[must_use]
pub fn with_option(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.options.insert(key.into(), value.into());
self
}
}