pub struct Service { /* private fields */ }Expand description
The background logging service.
Service owns the receive end of the MPSC channel, the currently active log file,
and the unbound Unix Datagram Socket used for broadcasting. It runs entirely on a
dedicated tokio task and never shares memory with the HTTP request threads.
Callers interact with the service indirectly through the [GLOBAL_LOGGER] sender
and the [LoggerHandler] returned by Service::start. The Service itself is
consumed by the background task and is not accessible after startup.
Implementations§
Source§impl Service
impl Service
Sourcepub async fn start(
capacity: usize,
) -> Result<(Sender<Entry>, LoggerHandler), Error>
pub async fn start( capacity: usize, ) -> Result<(Sender<Entry>, LoggerHandler), Error>
Initializes the logging service and spawns its background task.
This method must be called once during server startup. It:
- Creates a bounded MPSC channel with the specified
capacity. - Resolves the XDG state directory and creates
kosh/logsif it does not exist. - Opens (or creates) the current day’s log file in append mode.
- Creates an unbound Unix Datagram Socket for broadcasting.
- Spawns a dedicated
tokiotask that runs theService::runloop.
The returned [Sender] should be stored in [GLOBAL_LOGGER] immediately after
this call. The returned [LoggerHandler] should be kept alive and awaited during
graceful shutdown via [LoggerHandler::shutdown_with_grace].
§Errors
Returns [error::Error::LogDirectoryInitialization] if the XDG state directory
cannot be determined. Returns [error::Error::Io] if the log directory cannot be
created or the initial log file cannot be opened.
pub fn path() -> Option<PathBuf>
Auto Trait Implementations§
impl !Freeze for Service
impl !RefUnwindSafe for Service
impl Send for Service
impl Sync for Service
impl Unpin for Service
impl UnsafeUnpin for Service
impl UnwindSafe for Service
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more