1
+ use crate :: ZERO_DURATION ;
1
2
use std:: time:: Duration ;
2
3
3
4
/// Default buffer capacity (8k), when buffering is used.
@@ -45,10 +46,10 @@ pub const DEFAULT_MESSAGE_CAPA: usize = 200;
45
46
/// is dropped (and all output is flushed automatically).
46
47
///
47
48
/// `WriteMode::Direct` (i.e. without buffering) is the slowest option with all output devices,
48
- /// showing that buffered I/O pays off. But it takes slightly more resources, especially
49
- /// if you do not suppress flushing.
49
+ /// showing that buffered I/O pays off.
50
50
///
51
- /// Using `log_to_stdout()` and then redirecting the output to a file makes things faster,
51
+ /// Using `log_to_stdout()` and then redirecting the output to a file can make things faster,
52
+ /// likely because the operating system's adds buffering,
52
53
/// but is still significantly slower than writing to files directly.
53
54
///
54
55
#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
@@ -115,7 +116,7 @@ pub enum WriteMode {
115
116
} ,
116
117
}
117
118
impl WriteMode {
118
- pub ( crate ) fn inner ( & self ) -> EffectiveWriteMode {
119
+ pub ( crate ) fn effective_write_mode ( & self ) -> EffectiveWriteMode {
119
120
match * self {
120
121
Self :: Direct | Self :: SupportCapture => EffectiveWriteMode :: Direct ,
121
122
Self :: BufferDontFlush => {
@@ -158,7 +159,7 @@ impl WriteMode {
158
159
Self :: Async => Self :: AsyncWith {
159
160
pool_capa : DEFAULT_POOL_CAPA ,
160
161
message_capa : DEFAULT_MESSAGE_CAPA ,
161
- flush_interval : Duration :: from_secs ( 0 ) ,
162
+ flush_interval : ZERO_DURATION ,
162
163
} ,
163
164
#[ cfg( feature = "async" ) ]
164
165
Self :: AsyncWith {
@@ -168,12 +169,12 @@ impl WriteMode {
168
169
} => Self :: AsyncWith {
169
170
pool_capa : * pool_capa,
170
171
message_capa : * message_capa,
171
- flush_interval : Duration :: from_secs ( 0 ) ,
172
+ flush_interval : ZERO_DURATION ,
172
173
} ,
173
174
}
174
175
}
175
176
pub ( crate ) fn buffersize ( & self ) -> Option < usize > {
176
- match self . inner ( ) {
177
+ match self . effective_write_mode ( ) {
177
178
EffectiveWriteMode :: Direct => None ,
178
179
EffectiveWriteMode :: BufferAndFlushWith ( bufsize)
179
180
| EffectiveWriteMode :: BufferDontFlushWith ( bufsize) => Some ( bufsize) ,
@@ -190,7 +191,7 @@ impl WriteMode {
190
191
Self :: Direct
191
192
| Self :: SupportCapture
192
193
| Self :: BufferDontFlush
193
- | Self :: BufferDontFlushWith ( _) => Duration :: from_secs ( 0 ) ,
194
+ | Self :: BufferDontFlushWith ( _) => ZERO_DURATION ,
194
195
Self :: BufferAndFlush => DEFAULT_FLUSH_INTERVAL ,
195
196
#[ cfg( feature = "async" ) ]
196
197
Self :: Async => DEFAULT_FLUSH_INTERVAL ,
0 commit comments