Skip to content

Commit

Permalink
Fix #149 (remove remnants of "external_rotation")
Browse files Browse the repository at this point in the history
  • Loading branch information
emabee committed Sep 6, 2023
1 parent 03c9a26 commit 602d33f
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 77 deletions.
12 changes: 0 additions & 12 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,18 +464,6 @@ impl Logger {
self
}

/// Tries to make the logger react cooperatively if external tools rename or delete the log file.
#[deprecated(
since = "0.22.2",
note = "Use LoggerHandle::reopen_outputfile() instead"
)]
#[must_use]
#[cfg(feature = "external_rotation")]
pub fn watch_external_rotations(mut self) -> Self {
self.flwb = self.flwb.watch_external_rotations();
self
}

/// Makes the logger use UTC timestamps rather than local timestamps.
#[must_use]
pub fn use_utc(mut self) -> Self {
Expand Down
4 changes: 0 additions & 4 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ pub(crate) enum ErrorCode {
Flush,
Format,
LogFile,
#[cfg(feature = "external_rotation")]
LogFileWatcher,
#[cfg(feature = "specfile")]
LogSpecFile,
Poison,
Expand All @@ -38,8 +36,6 @@ impl ErrorCode {
Self::Flush => "flush",
Self::Format => "format",
Self::LogFile => "logfile",
#[cfg(feature = "external_rotation")]
Self::LogFileWatcher => "logfilewatcher",
#[cfg(feature = "specfile")]
Self::LogSpecFile => "logspecfile",
Self::Poison => "poison",
Expand Down
27 changes: 0 additions & 27 deletions src/writers/file_log_writer/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ pub struct FileLogWriterBuilder {
o_rotation_config: Option<RotationConfig>,
max_log_level: log::LevelFilter,
cleanup_in_background_thread: bool,
#[cfg(feature = "external_rotation")]
external_rotate_watcher: bool,
use_utc: bool,
}

Expand All @@ -38,8 +36,6 @@ impl FileLogWriterBuilder {
format: default_format,
max_log_level: log::LevelFilter::Trace,
cleanup_in_background_thread: true,
#[cfg(feature = "external_rotation")]
external_rotate_watcher: false,
use_utc: false,
}
}
Expand Down Expand Up @@ -80,24 +76,6 @@ impl FileLogWriterBuilder {
self
}

/// Makes the `FileLogWriter` react cooperatively if external tools rename or delete
/// the log file.
///
/// The `FileLogWriter` expects that nobody interacts with the log file,
/// and it offers capabilities to rotate, compress, and clean up log files.
///
/// Alternatively, tools like linux' `logrotate` can be used to rotate, compress or remove
/// log files. But renaming or deleting the current output file e.g. will not stop
/// `FileLogWriter` from writing to the now renamed or even deleted file!
/// You should use this method to make it watch for OS events that affect its outputfile
/// and react with closing its current output stream and recreating its configured output file.
#[must_use]
#[cfg(feature = "external_rotation")]
pub fn watch_external_rotations(mut self) -> Self {
self.external_rotate_watcher = true;
self
}

/// Use rotation to prevent indefinite growth of log files.
///
/// By default, the log file is fixed while your program is running and will grow indefinitely.
Expand Down Expand Up @@ -263,9 +241,6 @@ impl FileLogWriterBuilder {
#[cfg(not(feature = "async"))]
let cleanup_in_background_thread = self.cleanup_in_background_thread;

#[cfg(feature = "external_rotation")]
let external_rotate_watcher = self.external_rotate_watcher;

Ok(State::new(
FileLogWriterConfig {
print_message: self.cfg_print_message,
Expand All @@ -278,8 +253,6 @@ impl FileLogWriterBuilder {
},
self.o_rotation_config.as_ref().map(Clone::clone),
cleanup_in_background_thread,
#[cfg(feature = "external_rotation")]
external_rotate_watcher,
))
}
}
Expand Down
34 changes: 0 additions & 34 deletions src/writers/file_log_writer/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,13 @@ use crate::{
Age, Cleanup, Criterion, FileSpec, FlexiLoggerError, Naming,
};
use chrono::{DateTime, Datelike, Local, Timelike};
#[cfg(feature = "external_rotation")]
use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
use std::cmp::max;
use std::fs::{remove_file, File, OpenOptions};
use std::io::{BufRead, BufReader, BufWriter, Write};
use std::iter::Chain;
use std::ops::Add;
use std::path::{Path, PathBuf};
use std::vec::IntoIter;
#[cfg(feature = "external_rotation")]
use std::{
ops::Deref,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
};
const CURRENT_INFIX: &str = "_rCURRENT";
fn number_infix(idx: u32) -> String {
format!("_r{idx:0>5}")
Expand Down Expand Up @@ -177,8 +167,6 @@ impl std::fmt::Debug for Inner {
pub(super) struct State {
config: FileLogWriterConfig,
inner: Inner,
#[cfg(feature = "external_rotation")]
external_rotation: Arc<AtomicBool>,
}
impl State {
pub(super) fn new(
Expand All @@ -189,8 +177,6 @@ impl State {
Self {
config,
inner: Inner::Initial(o_rotation_config, cleanup_in_background_thread),
#[cfg(feature = "external_rotation")]
external_rotation,
}
}

Expand Down Expand Up @@ -322,9 +308,6 @@ impl State {
self.initialize()?;
}

#[cfg(feature = "external_rotation")]
self.react_on_external_rotation()?;

// rotate if necessary
self.mount_next_linewriter_if_necessary()
.unwrap_or_else(|e| {
Expand Down Expand Up @@ -364,23 +347,6 @@ impl State {
self.config.file_spec.as_pathbuf(o_infix)
}

// check if the currently used output file does still exist, and if not, then create and open it
#[cfg(feature = "external_rotation")]
fn react_on_external_rotation(&mut self) -> Result<(), std::io::Error> {
if self
.external_rotation
.deref()
.swap(false, Ordering::Relaxed)
{
if let Inner::Active(_, ref mut file, ref p_path) = self.inner {
if std::fs::metadata(p_path).is_err() {
*file = Box::new(OpenOptions::new().create(true).append(true).open(&p_path)?);
}
}
}
Ok(())
}

pub fn reopen_outputfile(&mut self) -> Result<(), std::io::Error> {
if let Inner::Active(_, ref mut file, ref p_path) = self.inner {
match OpenOptions::new().create(true).append(true).open(p_path) {
Expand Down

0 comments on commit 602d33f

Please sign in to comment.