Repository: actix/actix-web
File: src/middleware/logger.rs (Rust)

Code before:
/// `%{FOO}o`  response.headers['FOO']
///
/// `%{FOO}e`  os.environ['FOO']
///
/// # Security
///  **\*** It is calculated using
///  [`ConnectionInfo::realip_remote_addr()`](../dev/struct.ConnectionInfo.html#method.realip_remote_addr)
///
///  If you use this value ensure that all requests come from trusted hosts, since it is trivial
///  for the remote client to simulate being another client.
///
pub struct Logger(Rc<Inner>);

struct Inner {
    format: Format,
    exclude: HashSet<String>,
    exclude_regex: RegexSet,
}

impl Logger {
    /// Create `Logger` middleware with the specified `format`.
    pub fn new(format: &str) -> Logger {
        Logger(Rc::new(Inner {
            format: Format::new(format),
            exclude: HashSet::new(),
            exclude_regex: RegexSet::new(Vec::<&str>::new()).unwrap(),
        }))
    }

    /// Ignore and do not log access info for specified path.
    pub fn exclude<T: Into<String>>(mut self, path: T) -> Self {
        Rc::get_mut(&mut self.0)
            .unwrap()
            .exclude
            .insert(path.into());
        self
    }

    /// Ignore and do not log access info for paths that match regex
    pub fn exclude_regex<T: Into<String>>(
        mut self,
        path: T,
    ) -> Result<Self, regex::Error> {
        let inner = Rc::get_mut(&mut self.0).unwrap();
        let mut patterns: Vec<String> = inner.exclude_regex.patterns().into();
        patterns.push(path.into());
        let regex_set = RegexSet::new(patterns)?;
        inner.exclude_regex = regex_set;
        Ok(self)
    }
}

Review comment (suggestion):
I got `RegexSet::empty` added to `regex` v1.4.

```suggestion
            exclude_regex: RegexSet::empty(),
```

Code after:
/// `%{FOO}o`  response.headers['FOO']
///
/// `%{FOO}e`  os.environ['FOO']
///
/// # Security
///  **\*** It is calculated using
///  [`ConnectionInfo::realip_remote_addr()`](../dev/struct.ConnectionInfo.html#method.realip_remote_addr)
///
///  If you use this value ensure that all requests come from trusted hosts, since it is trivial
///  for the remote client to simulate being another client.
///
pub struct Logger(Rc<Inner>);

struct Inner {
    format: Format,
    exclude: HashSet<String>,
    exclude_regex: RegexSet,
}

impl Logger {
    /// Create `Logger` middleware with the specified `format`.
    pub fn new(format: &str) -> Logger {
        Logger(Rc::new(Inner {
            format: Format::new(format),
            exclude: HashSet::new(),
            exclude_regex: RegexSet::empty(),
        }))
    }

    /// Ignore and do not log access info for specified path.
    pub fn exclude<T: Into<String>>(mut self, path: T) -> Self {
        Rc::get_mut(&mut self.0)
            .unwrap()
            .exclude
            .insert(path.into());
        self
    }

    /// Ignore and do not log access info for paths that match regex
    pub fn exclude_regex<T: Into<String>>(mut self, path: T) -> Self {
        let inner = Rc::get_mut(&mut self.0).unwrap();
        let mut patterns = inner.exclude_regex.patterns().to_vec();
        patterns.push(path.into());
        let regex_set = RegexSet::new(patterns).unwrap();
        inner.exclude_regex = regex_set;
        self
    }
}

impl Default for Logger {
    /// Create `Logger` middleware with format: