pub struct FileBackend { /* private fields */ }Expand description
Appends audit events to a file as JSON lines.
§Examples
use ash_log::*;
use std::sync::Arc;
let backend = FileBackend::builder("/var/log/audit.jsonl")
.rotation(RotationPolicy::size(64 * 1024 * 1024).keeping(10))
.errors(Arc::new(StderrErrorSink))
.build()
.expect("open the audit log");
let logger = Logger::builder(Arc::new(backend)).build();
logger.info("started");Implementations§
Source§impl FileBackend
impl FileBackend
Sourcepub fn builder<P: Into<PathBuf>>(path: P) -> FileBackendBuilder
pub fn builder<P: Into<PathBuf>>(path: P) -> FileBackendBuilder
Start building a backend writing to path.
Sourcepub fn new<P: Into<PathBuf>>(path: P) -> Result<Self>
pub fn new<P: Into<PathBuf>>(path: P) -> Result<Self>
Open path for appending with no rotation and no error reporting.
§Errors
Returns the underlying error if the file cannot be opened or created.
Sourcepub fn reopen(&self) -> Result<()>
pub fn reopen(&self) -> Result<()>
Close and reopen the file at its original path.
Call this from a SIGHUP handler when an external rotator such as
logrotate moves the file aside. Without it the process keeps writing
to the renamed inode.
§Errors
Returns the underlying error if the path cannot be reopened. The old handle is dropped either way, so a failure leaves the backend unable to write rather than writing to the wrong place.
Sourcepub fn current_size(&self) -> u64
pub fn current_size(&self) -> u64
Number of bytes written to the current file.
Trait Implementations§
Source§impl AuditBackend for FileBackend
impl AuditBackend for FileBackend
Auto Trait Implementations§
impl !Freeze for FileBackend
impl !RefUnwindSafe for FileBackend
impl !UnwindSafe for FileBackend
impl Forget for FileBackend
impl Move for FileBackend
impl Send for FileBackend
impl Sync for FileBackend
impl Unpin for FileBackend
impl UnsafeUnpin for FileBackend
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