Struct servlin::log::internal::LogFileWriterBuilder
source · pub struct LogFileWriterBuilder {
pub max_keep_age: Option<Duration>,
pub max_keep_bytes: u64,
pub max_write_age: Duration,
pub max_write_bytes: u64,
pub path_prefix: PathBuf,
}Fields§
§max_keep_age: Option<Duration>§max_keep_bytes: u64§max_write_age: Duration§max_write_bytes: u64§path_prefix: PathBufImplementations§
source§impl LogFileWriterBuilder
impl LogFileWriterBuilder
sourcepub fn with_max_keep_age(self, duration: Duration) -> Self
pub fn with_max_keep_age(self, duration: Duration) -> Self
Configures the struct to continuously delete files that match path_prefix
and are older than max_keep_age.
Defaults to 24 hours.
Panics
Panics when duration is less than 1 minute.
sourcepub fn with_max_write_age(self, duration: Duration) -> Self
pub fn with_max_write_age(self, duration: Duration) -> Self
Configures the struct to close the current file and create a new file whenever
the current file is older than duration.
Defaults to 10 MiB.
Panics
Panics when duration is less than 1 second.
sourcepub fn with_max_write_bytes(self, len: u64) -> Self
pub fn with_max_write_bytes(self, len: u64) -> Self
Configures the struct to write len bytes or less to each log file
before switching to a new one.
Panics
Panics when len is less than 64 KiB.
sourcepub fn start_writer_thread(self) -> Result<SyncSender<LogEvent>, Error>
pub fn start_writer_thread(self) -> Result<SyncSender<LogEvent>, Error>
Creates the first log file and starts the log file writer thread.
Errors
Returns Err when it fails to create the first log file.
Examples found in repository?
examples/http-put.rs (line 82)
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
pub fn main() {
println!("Access the server at http://127.0.0.1:8000/upload");
let _guard = set_global_logger(
LogFileWriter::new_builder("log", 100 * 1024 * 1024)
.start_writer_thread()
.unwrap(),
)
.unwrap();
safina_timer::start_timer_thread();
let executor = safina_executor::Executor::default();
let cache_dir = TempDir::new().unwrap();
let state = Arc::new(State::new());
let request_handler =
move |req: Request| log_request_and_response(req, |req| handle_req(state, req)).unwrap();
executor
.block_on(
HttpServerBuilder::new()
.listen_addr(socket_addr_127_0_0_1(8000))
.max_conns(100)
.small_body_len(64 * 1024)
.receive_large_bodies(cache_dir.path())
.spawn_and_join(request_handler),
)
.unwrap();
}Auto Trait Implementations§
impl RefUnwindSafe for LogFileWriterBuilder
impl Send for LogFileWriterBuilder
impl Sync for LogFileWriterBuilder
impl Unpin for LogFileWriterBuilder
impl UnwindSafe for LogFileWriterBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more