#![cfg(feature = "loki")]
#![cfg_attr(docsrs, doc(cfg(feature = "loki")))]
use crate::{Logger, LokiLogger, service};
pub struct Loki {}
pub struct LokiConfig {
config: service::LokiConfig,
}
pub struct LokiFactoryService {
config: service::LokiConfig,
service: Box<dyn service::Loki + Send + Sync>,
}
impl Loki {
pub fn config(self, config: service::LokiConfig) -> LokiConfig {
LokiConfig { config }
}
pub fn service(
self,
config: service::LokiConfig,
service: Box<dyn service::Loki + Send + Sync>,
) -> LokiFactoryService {
LokiFactoryService { config, service }
}
}
impl LokiConfig {
pub fn new(config: service::LokiConfig) -> Self {
Self { config }
}
pub fn get_config(&self) -> &service::LokiConfig {
&self.config
}
pub fn config(self, config: service::LokiConfig) -> Self {
Self { config, ..self }
}
pub fn build(self) -> Logger {
Logger::new(self.build_impl())
}
pub fn build_impl(self) -> Box<LokiLogger> {
LokiLogger::new(self.config)
}
pub fn service(self, service: Box<dyn service::Loki + Send + Sync>) -> LokiFactoryService {
LokiFactoryService {
config: self.config,
service,
}
}
}
impl LokiFactoryService {
pub fn new(config: service::LokiConfig, service: Box<dyn service::Loki + Send + Sync>) -> Self {
Self { config, service }
}
pub fn get_config(&self) -> &service::LokiConfig {
&self.config
}
pub fn get_service(&self) -> &(dyn service::Loki + Send + Sync) {
self.service.as_ref()
}
pub fn config(self, config: service::LokiConfig) -> Self {
Self { config, ..self }
}
pub fn service(self, service: Box<dyn service::Loki + Send + Sync>) -> Self {
Self { service, ..self }
}
pub fn build(self) -> Logger {
Logger::new(self.build_impl())
}
pub fn build_impl(self) -> Box<LokiLogger> {
LokiLogger::with_service(self.config, self.service)
}
}