lexa_logger/builder.rs
1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ Copyright: (c) 2023, Mike 'PhiSyX' S. (https://github.com/PhiSyX) ┃
3// ┃ SPDX-License-Identifier: MPL-2.0 ┃
4// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
5// ┃ ┃
6// ┃ This Source Code Form is subject to the terms of the Mozilla Public ┃
7// ┃ License, v. 2.0. If a copy of the MPL was not distributed with this ┃
8// ┃ file, You can obtain one at https://mozilla.org/MPL/2.0/. ┃
9// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
10
11use crate::echo::Echo;
12
13// ---- //
14// Type //
15// ---- //
16
17pub(crate) type LoggerFormatFn = fn(&std::fmt::Arguments, &log::Record, &mut Echo) -> String;
18pub(crate) type LoggerFilterCallback = dyn Fn(&log::Metadata) -> bool + Send + Sync;
19
20// --------- //
21// Interface //
22// --------- //
23
24pub trait LoggerBuilder<T>
25{
26 /// Ajoute un filtre au système de log.
27 fn filter<F>(self, predicate: F, dependency: impl ToString) -> Self
28 where
29 F: 'static,
30 F: Send + Sync,
31 F: Fn(&log::Metadata) -> bool;
32
33 /// Autorise ou non les logs à avoir les couleurs sur les informations
34 /// contrôlées par notre système.
35 fn with_color(self, colorized: impl Into<bool>) -> Self;
36
37 /// Le format du log.
38 fn with_format(self, format: LoggerFormatFn) -> Self;
39
40 /// Le niveau de log.
41 #[cfg(not(feature = "tracing"))]
42 fn with_level(self, level: impl Into<log::LevelFilter>) -> Self;
43 #[cfg(feature = "tracing")]
44 fn with_level(self, level: impl Into<tracing::level_filters::LevelFilter>) -> Self;
45
46 /// Autorise ou non les logs à avoir un timestamp.
47 fn with_timestamp(self, b: impl Into<bool>) -> Self;
48
49 /// Construction du logger.
50 fn build(self) -> T;
51}
52
53// --------- //
54// Structure //
55// --------- //
56
57pub struct Logger;
58
59// -------------- //
60// Implémentation //
61// -------------- //
62
63impl Logger
64{
65 /// Monteur de structure d'un logger de type stdout.
66 ///
67 /// Paramètres activés:
68 /// 1. [LoggerBuilder::with_color()]
69 /// 2. [LoggerBuilder::with_timestamp()]
70 pub fn stdout() -> crate::stdout::LoggerStdoutBuilder
71 {
72 crate::stdout::LoggerStdout::builder()
73 .with_color(true)
74 .with_timestamp(true)
75 }
76
77 // NOTE: Ajouter d'autres types de builder avec des paramètres par défaut
78 // ici...
79}