use crate::service::{StandardWriteMessageFormatter, WriteMessageFormatter};
use crate::{Concurrency, DirectLogger, Logger, QueuedLogger, service};
pub struct CoutWrite {
max_retries: usize,
worker_count: usize,
}
impl CoutWrite {
pub fn get_max_retries(&self) -> usize {
self.max_retries
}
pub fn get_worker_count(&self) -> usize {
self.worker_count
}
pub fn max_retries(self, max_retries: usize) -> Self {
Self {
max_retries,
..self
}
}
pub fn worker_count(self, worker_count: usize) -> Self {
Self {
worker_count,
..self
}
}
pub fn build(self, concurrency: Concurrency) -> Logger {
match concurrency {
Concurrency::Sync => Logger::new(self.build_impl_direct()),
Concurrency::Async => Logger::new(self.build_impl_queued()),
}
}
pub fn build_with_formatter<MF>(self, concurrency: Concurrency, formatter: MF) -> Logger
where
MF: WriteMessageFormatter + 'static,
{
match concurrency {
Concurrency::Sync => Logger::new(self.build_impl_direct_with_formatter(formatter)),
Concurrency::Async => Logger::new(self.build_impl_queued_with_formatter(formatter)),
}
}
pub fn build_impl_direct(self) -> Box<DirectLogger> {
let max_retries = self.max_retries;
DirectLogger::new(self.build_service(), max_retries)
}
pub fn build_impl_queued(self) -> Box<QueuedLogger> {
let max_retries = self.max_retries;
let worker_count = self.worker_count;
QueuedLogger::new(self.build_service(), max_retries, worker_count)
}
pub fn build_impl_direct_with_formatter<MF>(self, formatter: MF) -> Box<DirectLogger>
where
MF: WriteMessageFormatter + 'static,
{
let max_retries = self.max_retries;
DirectLogger::new(self.build_service_with_formatter(formatter), max_retries)
}
pub fn build_impl_queued_with_formatter<MF>(self, formatter: MF) -> Box<QueuedLogger>
where
MF: WriteMessageFormatter + 'static,
{
let max_retries = self.max_retries;
let worker_count = self.worker_count;
QueuedLogger::new(
self.build_service_with_formatter(formatter),
max_retries,
worker_count,
)
}
pub fn build_service_with_formatter<MF>(self, formatter: MF) -> Box<service::CoutWrite<MF>>
where
MF: WriteMessageFormatter + 'static,
{
service::CoutWrite::with_formatter(formatter)
}
pub fn build_service(self) -> Box<service::CoutWrite<StandardWriteMessageFormatter>> {
service::CoutWrite::new()
}
}
impl Default for CoutWrite {
fn default() -> Self {
Self {
max_retries: 3,
worker_count: 1,
}
}
}
pub struct CerrWrite {
max_retries: usize,
worker_count: usize,
}
impl CerrWrite {
pub fn get_max_retries(&self) -> usize {
self.max_retries
}
pub fn get_worker_count(&self) -> usize {
self.worker_count
}
pub fn max_retries(self, max_retries: usize) -> Self {
Self {
max_retries,
..self
}
}
pub fn worker_count(self, worker_count: usize) -> Self {
Self {
worker_count,
..self
}
}
pub fn build(self, concurrency: Concurrency) -> Logger {
match concurrency {
Concurrency::Sync => Logger::new(self.build_impl_direct()),
Concurrency::Async => Logger::new(self.build_impl_queued()),
}
}
pub fn build_with_formatter<MF>(self, concurrency: Concurrency, formatter: MF) -> Logger
where
MF: WriteMessageFormatter + 'static,
{
match concurrency {
Concurrency::Sync => Logger::new(self.build_impl_direct_with_formatter(formatter)),
Concurrency::Async => Logger::new(self.build_impl_queued_with_formatter(formatter)),
}
}
pub fn build_impl_direct(self) -> Box<DirectLogger> {
let max_retries = self.max_retries;
DirectLogger::new(self.build_service(), max_retries)
}
pub fn build_impl_queued(self) -> Box<QueuedLogger> {
let max_retries = self.max_retries;
let worker_count = self.worker_count;
QueuedLogger::new(self.build_service(), max_retries, worker_count)
}
pub fn build_impl_direct_with_formatter<MF>(self, formatter: MF) -> Box<DirectLogger>
where
MF: WriteMessageFormatter + 'static,
{
let max_retries = self.max_retries;
DirectLogger::new(self.build_service_with_formatter(formatter), max_retries)
}
pub fn build_impl_queued_with_formatter<MF>(self, formatter: MF) -> Box<QueuedLogger>
where
MF: WriteMessageFormatter + 'static,
{
let max_retries = self.max_retries;
let worker_count = self.worker_count;
QueuedLogger::new(
self.build_service_with_formatter(formatter),
max_retries,
worker_count,
)
}
pub fn build_service_with_formatter<MF>(self, formatter: MF) -> Box<service::CerrWrite<MF>>
where
MF: WriteMessageFormatter + 'static,
{
service::CerrWrite::with_formatter(formatter)
}
pub fn build_service(self) -> Box<service::CerrWrite<StandardWriteMessageFormatter>> {
service::CerrWrite::new()
}
}
impl Default for CerrWrite {
fn default() -> Self {
Self {
max_retries: 3,
worker_count: 1,
}
}
}