timber_rust/factory/factory.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Dante Doménech Martinez dante19031999@gmail.com
3
4#[cfg(feature = "awscout")]
5use crate::factory::awscout::CloudWatch;
6use crate::factory::fmt::FmtWrite;
7use crate::factory::io::IoWrite;
8#[cfg(feature = "loki")]
9use crate::factory::loki::Loki;
10use crate::factory::std::CerrWrite;
11use crate::factory::std::CoutWrite;
12use crate::factory::vec::Vector;
13use crate::{Logger, SilentLogger};
14
15/// The primary entry point for the Timber logging system.
16///
17/// `LoggerFactory` provides a centralized interface for creating specialized
18/// loggers. It uses a fluent builder pattern to allow for granular configuration
19/// of retry policies, concurrency models, and destination-specific settings.
20///
21/// ### Example: Console Logging
22/// ```rust
23/// # use timber_rust::LoggerFactory;
24/// # use timber_rust::Concurrency;
25/// let logger = LoggerFactory::cout()
26/// .max_retries(5)
27/// .build(Concurrency::Async);
28/// ```
29///
30/// ### Example: Capturing Logs for Testing
31/// ```rust
32/// # use timber_rust::LoggerFactory;
33/// # use timber_rust::Concurrency;
34/// let logger = LoggerFactory::vector()
35/// .capacity(500)
36/// .build(Concurrency::Sync);
37/// ```
38pub struct LoggerFactory {}
39
40impl LoggerFactory {
41 /// Returns a "No-Op" logger that discards all messages.
42 ///
43 /// Useful for silencing output in production environments or as a
44 /// default placeholder in library configuration.
45 pub fn silent() -> Logger {
46 Logger::new(SilentLogger::new())
47 }
48
49 /// Creates a builder for Grafana Loki.
50 ///
51 /// Requires the `loki` feature to be enabled.
52 #[cfg(feature = "loki")]
53 #[cfg_attr(docsrs, doc(cfg(feature = "loki")))]
54 pub fn loki() -> Loki {
55 Loki {}
56 }
57
58 /// Creates a builder for Amazon CloudWatch.
59 ///
60 /// Requires the `aws` feature to be enabled.
61 #[cfg(feature = "awscout")]
62 #[cfg_attr(docsrs, doc(cfg(feature = "awscout")))]
63 pub fn cloudwatch() -> CloudWatch {
64 CloudWatch {}
65 }
66
67 /// Creates a builder for byte-oriented output targets (Files, TCP streams).
68 pub fn io() -> IoWrite {
69 IoWrite::default()
70 }
71
72 /// Creates a builder for string-oriented output targets ([`String`], in-memory buffers).
73 pub fn fmt() -> FmtWrite {
74 FmtWrite::default()
75 }
76
77 /// Creates a builder for capturing structured [`Message`][crate::Message] data in a [`Vec`].
78 ///
79 /// Ideal for unit testing and programmatic analysis.
80 pub fn vector() -> Vector {
81 Vector::default()
82 }
83
84 /// Creates a builder for logging to the Standard Output (stdout).
85 pub fn cout() -> CoutWrite {
86 CoutWrite::default()
87 }
88
89 /// Creates a builder for logging to the Standard Error (stderr).
90 pub fn cerr() -> CerrWrite {
91 CerrWrite::default()
92 }
93}