Skip to content

Commit

Permalink
del label
Browse files Browse the repository at this point in the history
  • Loading branch information
estk committed Aug 1, 2023
1 parent 66b6068 commit 96a5918
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions trace4rs/src/appenders/rolling.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
use std::{
fs,
io::{
self,
LineWriter,
Write,
},
io::{self, LineWriter, Write},
};

use camino::{
Utf8Path,
Utf8PathBuf,
};
use camino::{Utf8Path, Utf8PathBuf};

use crate::{
env::try_expand_env_vars,
error::{
Error,
Result,
},
error::{Error, Result},
};

/// `LogFileMeta` allows us to keep track of an estimated length for a given
Expand Down Expand Up @@ -68,8 +58,8 @@ impl Trigger {
#[derive(Clone)]
pub struct FixedWindow {
/// invariant last < count
last: Option<usize>,
count: usize,
last: Option<usize>,
count: usize,
pattern: String,
}
impl FixedWindow {
Expand All @@ -95,7 +85,10 @@ impl FixedWindow {
// eas: Idk why im so dumb but this function is _bad_.
fn roll(&mut self, path: &Utf8Path) -> io::Result<()> {
// if None, we just need to roll to zero, which happens after this block
'outer: {

// see todo below
// 'outer: {
{
if let Some(mut c) = self.last {
// holding max rolls, saturation should be fine
if c.saturating_add(1) == self.count {
Expand Down Expand Up @@ -183,13 +176,13 @@ impl Roller {
/// An appender which writes to a file and manages rolling said file, either to
/// backups or by deletion.
pub struct RollingFile {
path: Utf8PathBuf,
path: Utf8PathBuf,
/// Writer will always be some except when it is being rolled or if there
/// was an error initing a new writer after abandonment of the previous.
writer: Option<LineWriter<fs::File>>,
meta: LogFileMeta,
writer: Option<LineWriter<fs::File>>,
meta: LogFileMeta,
trigger: Trigger,
roller: Roller,
roller: Roller,
}
impl RollingFile {
const DEFAULT_FILE_NAME: &'static str = "log";
Expand All @@ -208,14 +201,14 @@ impl RollingFile {
let expanded_path = try_expand_env_vars(p.as_ref());
let (writer, meta) = {
let writer = Self::new_writer(&expanded_path).map_err(|e| Error::CreateFailed {
path: expanded_path.clone().into_owned(),
path: expanded_path.clone().into_owned(),
source: e,
})?;
let meta = writer
.get_ref()
.metadata()
.map_err(|e| Error::MetadataFailed {
path: expanded_path.clone().into_owned(),
path: expanded_path.clone().into_owned(),
source: e,
})?;
(writer, LogFileMeta::from_meta(&meta))
Expand Down Expand Up @@ -285,7 +278,7 @@ impl RollingFile {
/// pattern: "{filename}.{}".
///
/// ```ignore
///
///
/// make_qualified_pattern(Path::from("./foo/bar.log"), None); // -> "./foo/bar.log.{}"
/// make_qualified_pattern(Path::from("./foo/bar.log"), Some("bar_roll.{}")); // -> "./foo/bar_roll.{}"
/// ```
Expand Down

0 comments on commit 96a5918

Please sign in to comment.