2929//! AppendCount::new(2),
3030//! ContentLimit::Lines(3),
3131//! Compression::None,
32- //! #[cfg(unix)]
3332//! None,
3433//! );
3534//!
6261//! AppendCount::new(2),
6362//! ContentLimit::Bytes(5),
6463//! Compression::None,
65- //! #[cfg(unix)]
6664//! None,
6765//! );
6866//!
9997//! AppendCount::new(3),
10098//! ContentLimit::Bytes(1),
10199//! Compression::None,
102- //! #[cfg(unix)]
103100//! None,
104101//! );
105102//!
158155//! AppendTimestamp::default(FileLimit::MaxFiles(2)),
159156//! ContentLimit::Bytes(1),
160157//! Compression::None,
161- //! #[cfg(unix)]
162158//! None,
163159//! );
164160//!
204200//! AppendTimestamp::default(FileLimit::MaxFiles(4)),
205201//! ContentLimit::Bytes(1),
206202//! Compression::OnRotate(2),
207- //! #[cfg(unix)]
208203//! None,
209204//! );
210205//!
@@ -303,9 +298,6 @@ use std::{
303298} ;
304299use suffix:: * ;
305300
306- #[ cfg( unix) ]
307- use std:: os:: unix:: fs:: OpenOptionsExt ;
308-
309301pub mod compression;
310302pub mod suffix;
311303#[ cfg( test) ]
@@ -392,8 +384,7 @@ pub struct FileRotate<S: SuffixScheme> {
392384 suffix_scheme : S ,
393385 /// The bool is whether or not there's a .gz suffix to the filename
394386 suffixes : BTreeSet < SuffixInfo < S :: Repr > > ,
395- #[ cfg( unix) ]
396- mode : Option < u32 > ,
387+ open_options : Option < OpenOptions > ,
397388}
398389
399390impl < S : SuffixScheme > FileRotate < S > {
@@ -404,6 +395,8 @@ impl<S: SuffixScheme> FileRotate<S> {
404395 ///
405396 /// `content_limit` specifies the limits for rotating a file.
406397 ///
398+ /// `open_options`: If provided, you must set `.read(true).create(true).append(true)`!
399+ ///
407400 /// # Panics
408401 ///
409402 /// Panics if `bytes == 0` or `lines == 0`.
@@ -412,7 +405,7 @@ impl<S: SuffixScheme> FileRotate<S> {
412405 suffix_scheme : S ,
413406 content_limit : ContentLimit ,
414407 compression : Compression ,
415- # [ cfg ( unix ) ] mode : Option < u32 > ,
408+ open_options : Option < OpenOptions > ,
416409 ) -> Self {
417410 match content_limit {
418411 ContentLimit :: Bytes ( bytes) => {
@@ -440,8 +433,7 @@ impl<S: SuffixScheme> FileRotate<S> {
440433 compression,
441434 suffixes : BTreeSet :: new ( ) ,
442435 suffix_scheme,
443- #[ cfg( unix) ]
444- mode,
436+ open_options,
445437 } ;
446438 s. ensure_log_directory_exists ( ) ;
447439 s. scan_suffixes ( ) ;
@@ -484,14 +476,11 @@ impl<S: SuffixScheme> FileRotate<S> {
484476 }
485477
486478 fn open_file ( & mut self ) {
487- let mut open_options = OpenOptions :: new ( ) ;
488-
489- open_options. read ( true ) . create ( true ) . append ( true ) ;
490-
491- #[ cfg( unix) ]
492- if let Some ( mode) = self . mode {
493- open_options. mode ( mode) ;
494- }
479+ let open_options = self . open_options . clone ( ) . unwrap_or_else ( || {
480+ let mut o = OpenOptions :: new ( ) ;
481+ o. read ( true ) . create ( true ) . append ( true ) ;
482+ o
483+ } ) ;
495484
496485 self . file = open_options. open ( & self . basepath ) . ok ( ) ;
497486 }
@@ -772,10 +761,12 @@ pub mod mock_time {
772761 static MOCK_TIME : RefCell <Option <DateTime <Local >>> = RefCell :: new( None ) ;
773762 }
774763
764+ /// Get current _mocked_ time
775765 pub fn now ( ) -> DateTime < Local > {
776766 MOCK_TIME . with ( |cell| cell. borrow ( ) . as_ref ( ) . cloned ( ) . unwrap_or_else ( Local :: now) )
777767 }
778768
769+ /// Set mocked time
779770 pub fn set_mock_time ( time : DateTime < Local > ) {
780771 MOCK_TIME . with ( |cell| * cell. borrow_mut ( ) = Some ( time) ) ;
781772 }
0 commit comments