aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-04-02 20:53:32 +0200
committermetamuffin <metamuffin@disroot.org>2025-04-02 20:53:32 +0200
commit8123a63fa9ec0e1736784cdb08d93a6ea72a904d (patch)
tree3bea24cb9d9fc31df2c7750311a1fe4ae4d3f554
parent631f621e31d209daf5cfe3a286d2aed5efb33cdc (diff)
downloadgnix-8123a63fa9ec0e1736784cdb08d93a6ea72a904d.tar
gnix-8123a63fa9ec0e1736784cdb08d93a6ea72a904d.tar.bz2
gnix-8123a63fa9ec0e1736784cdb08d93a6ea72a904d.tar.zst
maybe release log file guard to allow parallel request processing :)
-rw-r--r--src/modules/log.rs76
1 files changed, 39 insertions, 37 deletions
diff --git a/src/modules/log.rs b/src/modules/log.rs
index 6122624..3705657 100644
--- a/src/modules/log.rs
+++ b/src/modules/log.rs
@@ -214,47 +214,49 @@ impl Node for Log {
String::from_utf8_lossy_owned(out.into_inner())
}
};
-
- let mut g = self.file.write().await;
- if let Some((log, otime)) = g.as_mut() {
- if otime.elapsed() > Duration::from_secs(self.config.file_duration) {
- info!("closing log file (age)");
- log.flush().await?;
- *g = None;
+ {
+ let mut g = self.file.write().await;
+ if let Some((log, otime)) = g.as_mut() {
+ if otime.elapsed() > Duration::from_secs(self.config.file_duration) {
+ info!("closing log file");
+ log.flush().await?;
+ *g = None;
+ }
}
- }
- if g.is_none() {
- if self.config.output_temp.exists() {
- info!("moving log file");
- rename(
- &self.config.output_temp,
- self.config.output_done.join(
- SystemTime::UNIX_EPOCH
- .elapsed()
- .unwrap()
- .as_secs()
- .to_string(),
+ if g.is_none() {
+ if self.config.output_temp.exists() {
+ info!("moving log file");
+ rename(
+ &self.config.output_temp,
+ self.config.output_done.join(
+ SystemTime::UNIX_EPOCH
+ .elapsed()
+ .unwrap()
+ .as_secs()
+ .to_string(),
+ ),
+ )
+ .await?;
+ }
+ info!("opening new log file");
+ *g = Some((
+ BufWriter::new(
+ OpenOptions::new()
+ .append(true)
+ .create(true)
+ .open(&self.config.output_temp)
+ .await?,
),
- )
- .await?;
+ Instant::now(),
+ ));
+ }
+ let log = &mut g.as_mut().unwrap().0;
+ log.write_all(line.as_bytes()).await?;
+ if self.config.flush {
+ log.flush().await?;
}
- info!("opening new log file");
- *g = Some((
- BufWriter::new(
- OpenOptions::new()
- .append(true)
- .create(true)
- .open(&self.config.output_temp)
- .await?,
- ),
- Instant::now(),
- ));
- }
- let log = &mut g.as_mut().unwrap().0;
- log.write_all(line.as_bytes()).await?;
- if self.config.flush {
- log.flush().await?;
}
+
self.config.next.handle(context, request).await
})
}