nginx_discovery/types/
access_log.rs1use std::collections::HashMap;
4use std::path::PathBuf;
5
6#[derive(Debug, Clone, PartialEq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct AccessLog {
10 pub path: PathBuf,
12
13 pub format_name: Option<String>,
15
16 pub options: HashMap<String, String>,
18
19 pub context: LogContext,
21}
22
23#[derive(Debug, Clone, PartialEq, Eq)]
25#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
26pub enum LogContext {
27 Main,
29 Server(String),
31 Location(String),
33}
34
35impl AccessLog {
36 #[must_use]
38 pub fn new(path: impl Into<PathBuf>) -> Self {
39 Self {
40 path: path.into(),
41 format_name: None,
42 options: HashMap::new(),
43 context: LogContext::Main,
44 }
45 }
46
47 #[must_use]
49 pub fn with_format(mut self, format: impl Into<String>) -> Self {
50 self.format_name = Some(format.into());
51 self
52 }
53
54 #[must_use]
56 pub fn with_context(mut self, context: LogContext) -> Self {
57 self.context = context;
58 self
59 }
60
61 #[must_use]
63 pub fn with_option(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
64 self.options.insert(key.into(), value.into());
65 self
66 }
67}