pub struct LogConfig {
pub log_dir: PathBuf,
pub log_file_prefix: String,
pub rotation: LogRotation,
pub max_files: Option<usize>,
pub level: String,
pub stdout: bool,
}Expand description
Logging configuration
Provides configuration for file-based logging with rotation support.
Fields§
§log_dir: PathBufLog directory path
log_file_prefix: StringLog file name prefix
rotation: LogRotationLog rotation interval
max_files: Option<usize>Maximum number of log files to keep (None = unlimited)
level: StringLog level (trace, debug, info, warn, error)
stdout: boolWhether to also log to stdout
Implementations§
Source§impl LogConfig
impl LogConfig
Sourcepub fn new(log_dir: impl Into<PathBuf>) -> Self
pub fn new(log_dir: impl Into<PathBuf>) -> Self
Create a new log config with the specified log directory
Sourcepub fn with_level(self, level: &str) -> Self
pub fn with_level(self, level: &str) -> Self
Set log level (trace, debug, info, warn, error)
Sourcepub fn with_rotation(self, rotation: LogRotation) -> Self
pub fn with_rotation(self, rotation: LogRotation) -> Self
Set log rotation interval
Sourcepub fn with_max_files(self, max_files: usize) -> Self
pub fn with_max_files(self, max_files: usize) -> Self
Set maximum number of log files to keep
Sourcepub fn with_prefix(self, prefix: &str) -> Self
pub fn with_prefix(self, prefix: &str) -> Self
Set log file name prefix
Sourcepub fn with_stdout(self, enabled: bool) -> Self
pub fn with_stdout(self, enabled: bool) -> Self
Enable or disable stdout logging
Sourcepub fn init(&self) -> Result<LogGuard, Box<dyn Error + Send + Sync>>
pub fn init(&self) -> Result<LogGuard, Box<dyn Error + Send + Sync>>
Initialize the logging system
Returns a guard that must be held for the duration of the program. When the guard is dropped, any remaining logs will be flushed.
§Example
use batata_client::logging::LogConfig;
let _guard = LogConfig::new("/var/log/batata")
.with_level("info")
.init()
.expect("Failed to init logging");
// Logging is now active
tracing::info!("Hello, world!");Trait Implementations§
Auto Trait Implementations§
impl Freeze for LogConfig
impl RefUnwindSafe for LogConfig
impl Send for LogConfig
impl Sync for LogConfig
impl Unpin for LogConfig
impl UnwindSafe for LogConfig
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request