src/logger/builder.rs

Lines

100.00 %

Functions

100.00 %

Regions

99.36 %

LineCountSource (jump to first uncovered line)
1
//
2
// File Name:    builder.rs
3
// Directory:    src/logger
4
// Project Name: flogging
5
//
6
// Copyright (C) 2025 Bradley Willcott
7
//
8
// SPDX-License-Identifier: GPL-3.0-or-later
9
//
10
// This library (crate) is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
14
//
15
// This library (crate) is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
// GNU General Public License for more details.
19
//
20
// You should have received a copy of the GNU General Public License
21
// along with this library (crate).  If not, see <https://www.gnu.org/licenses/>.
22
//
23
24
//!
25
//! # LoggerBuilder
26
//!
27
28
use crate::*;
29
use std::{cell::RefCell, collections::HashMap, fs};
30
31
///
32
/// Used by [`Logger`] to provide more flexibility in the configuration of the
33
/// final logger.
34
///
35
pub struct LoggerBuilder {
36
    mod_path: String,
37
    fn_name: String,
38
    level: Level,
39
    handlers: RefCell<HashMap<Handler, Box<dyn HandlerTrait>>>,
40
}
41
42
impl LoggerBuilder {
4346
    pub(super) fn create(mod_path: String) -> Self {
4446
        LoggerBuilder {
4546
            mod_path,
4646
            fn_name: String::new(),
4746
            level: Level::default(),
4846
            handlers: RefCell::new(HashMap::new()),
4946
        }
5046
    }
51
52
    ///
53
    /// Adds a [`ConsoleHandler`] with the default formatter,
54
    /// with output according to: [`ConsoleType::StdOut`].
55
    ///
56
    /// ## Examples
57
    /// ```
58
    /// extern crate flogging;
59
    /// use flogging::*;
60
    ///
61
    /// let mut log = Logger::builder(module_path!())
62
    ///     .add_console_handler()
63
    ///     .build();
64
    /// ```
65
    ///
6616
    pub fn add_console_handler(self) -> Self {
6716
        self.add_handler_with(Handler::Console, None, None, None, None)
6816
    }
69
70
    ///
71
    /// Adds a [`ConsoleHandler`] with the required formatter,
72
    /// with output according to: [`ConsoleType::StdOut`].
73
    ///
74
    /// ## Parameters
75
    /// - `format_type` - The format type used to produce the required formatter.
76
    /// - `custom_formatter` - The optional boxed custom formatter.
77
    ///   Used by the [`FormatType::Custom`] to produce a [`Formatter::Custom`].
78
    ///
79
    /// ## Examples
80
    /// First, using a provided formatter:
81
    /// ```
82
    /// extern crate flogging;
83
    /// use flogging::*;
84
    ///
85
    /// let mut log = Logger::builder(module_path!())
86
    ///     .add_console_handler_with(FormatType::Iso8601, None)
87
    ///     .build();
88
    /// ```
89
    /// Now using a custom formatter:
90
    /// ```
91
    /// extern crate flogging;
92
    /// use flogging::*;
93
    ///
94
    /// let mut log = Logger::builder(module_path!())
95
    ///     .add_console_handler_with(
96
    ///         FormatType::Custom,
97
    ///         Some(Box::new(MockFormatter::new())),
98
    ///     )
99
    ///     .build();
100
    /// ```
101
    ///
1022
    pub fn add_console_handler_with(
1032
        self,
1042
        format_type: FormatType,
1052
        custom_formatter: Option<Box<dyn FormatTrait>>,
1062
    ) -> Self {
1072
        self.add_handler_with(
1082
            Handler::Console,
1092
            None,
1102
            None,
1112
            Some(format_type),
1122
            custom_formatter,
113
        )
1142
    }
115
116
    ///
117
    /// Adds a [`ConsoleHandler`] with the default formatter,
118
    /// with output according to: [`ConsoleType::StdErr`].
119
    ///
120
    /// ## Examples
121
    /// ```
122
    /// extern crate flogging;
123
    /// use flogging::*;
124
    ///
125
    /// let mut log = Logger::builder(module_path!())
126
    ///     .add_econsole_handler()
127
    ///     .build();
128
    /// ```
129
    ///
1304
    pub fn add_econsole_handler(self) -> Self {
1314
        self.add_handler_with(Handler::EConsole, None, None, None, None)
1324
    }
133
134
    ///
135
    /// Adds a [`ConsoleHandler`] with the required formatter,
136
    /// with output according to: [`ConsoleType::StdErr`].
137
    ///
138
    /// ## Parameters
139
    /// - `format_type` - The format type used to produce the required formatter.
140
    /// - `custom_formatter` - The optional boxed custom formatter.
141
    ///   Used by the [`FormatType::Custom`] to produce a [`Formatter::Custom`].
142
    ///
143
    /// ## Examples
144
    /// First, using a provided formatter:
145
    /// ```
146
    /// extern crate flogging;
147
    /// use flogging::*;
148
    ///
149
    /// let mut log = Logger::builder(module_path!())
150
    ///     .add_econsole_handler_with(FormatType::Iso8601, None)
151
    ///     .build();
152
    /// ```
153
    /// Now using a custom formatter:
154
    /// ```
155
    /// extern crate flogging;
156
    /// use flogging::*;
157
    ///
158
    /// let mut log = Logger::builder(module_path!())
159
    ///     .add_econsole_handler_with(
160
    ///         FormatType::Custom,
161
    ///         Some(Box::new(MockFormatter::new())),
162
    ///     )
163
    ///     .build();
164
    /// ```
165
    ///
1662
    pub fn add_econsole_handler_with(
1672
        self,
1682
        format_type: FormatType,
1692
        custom_formatter: Option<Box<dyn FormatTrait>>,
1702
    ) -> Self {
1712
        self.add_handler_with(
1722
            Handler::EConsole,
1732
            None,
1742
            None,
1752
            Some(format_type),
1762
            custom_formatter,
177
        )
1782
    }
179
180
    ///
181
    /// Adds a custom handler with the default formatter.
182
    ///
183
    /// ## Parameters
184
    /// - `label` - Unique identifier for this custom handler. Used when attempting to
185
    ///   retrieve this handler: [`has_handler()`][Logger::has_handler], [`get_handler()`][Logger::get_handler]
186
    /// - `custom_handler` - The boxed custom handler.
187
    ///
188
    /// ## Examples
189
    /// ```
190
    /// extern crate flogging;
191
    /// use flogging::*;
192
    ///
193
    /// let mut log = Logger::builder(module_path!())
194
    ///     .add_custom_handler(
195
    ///         "MockHandler",
196
    ///         Box::new(MockHandler::create("What ever you need").unwrap()),
197
    ///     )
198
    ///     .build();
199
    /// ```
200
    ///
2013
    pub fn add_custom_handler(self, label: &str, custom_handler: Box<dyn HandlerTrait>) -> Self {
2023
        self.add_handler_with(
2033
            Handler::Custom(label.to_string()),
2043
            Some(custom_handler),
2053
            None,
2063
            None,
2073
            None,
208
        )
2093
    }
210
211
    ///
212
    /// Adds a custom handler with the required formatter.
213
    ///
214
    /// ## Parameters
215
    /// - `label` - Unique identifier for this custom handler. Used when attempting to
216
    ///   retrieve this handler: [`has_handler()`][Logger::has_handler], [`get_handler()`][Logger::get_handler]
217
    /// - `custom_handler` - The boxed custom handler.
218
    /// - `format_type` - The format type used to produce the required formatter.
219
    /// - `custom_formatter` - The optional boxed custom formatter.
220
    ///   Used by the [`FormatType::Custom`] to produce a [`Formatter::Custom`].
221
    ///
222
    /// ## Examples
223
    /// First, using a provided formatter:
224
    /// ```
225
    /// extern crate flogging;
226
    /// use flogging::*;
227
    ///
228
    /// let mut log = Logger::builder(module_path!())
229
    ///     .add_custom_handler_with(
230
    ///         "MockHandler",
231
    ///         Box::new(MockHandler::create("What ever you need").unwrap()),
232
    ///         FormatType::Simple,
233
    ///         None,
234
    ///     )
235
    ///     .build();
236
    /// ```
237
    /// Now using a custom formatter:
238
    /// ```
239
    /// extern crate flogging;
240
    /// use flogging::*;
241
    ///
242
    /// let mut log = Logger::builder(module_path!())
243
    ///     .add_custom_handler_with(
244
    ///         "MockHandler",
245
    ///         Box::new(MockHandler::create("What ever you need").unwrap()),
246
    ///         FormatType::Custom,
247
    ///         Some(Box::new(MockFormatter::new())),
248
    ///     )
249
    ///     .build();
250
    /// ```
251
    ///
2522
    pub fn add_custom_handler_with(
2532
        self,
2542
        label: &str,
2552
        custom_handler: Box<dyn HandlerTrait>,
2562
        format_type: FormatType,
2572
        custom_formatter: Option<Box<dyn FormatTrait>>,
2582
    ) -> Self {
2592
        self.add_handler_with(
2602
            Handler::Custom(label.to_string()),
2612
            Some(custom_handler),
2622
            None,
2632
            Some(format_type),
2642
            custom_formatter,
265
        )
2662
    }
267
268
    ///
269
    /// Adds a [`FileHandler`] with the default formatter.
270
    ///
271
    /// ## Parameters
272
    ///
273
    /// - `filename` - The name of the output log file. Must include any relevant
274
    ///   path (relative or absolute).
275
    ///
276
    /// ## Examples
277
    /// ```
278
    /// extern crate flogging;
279
    /// use flogging::*;
280
    ///
281
    /// let mut log = Logger::builder(module_path!())
282
    ///     .add_file_handler("test_logs/builder.log")
283
    ///     .build();
284
    /// ```
285
    ///
28617
    pub fn add_file_handler(self, filename: &str) -> Self {
28717
        self.add_handler_with(Handler::File, None, Some(filename), None, None)
28817
    }
289
290
    ///
291
    /// Adds a [`FileHandler`] with the required formatter.
292
    ///
293
    /// ## Parameters
294
    /// - `filename` - The name of the output log file. Must include any relevant
295
    ///   path (relative or absolute).
296
    /// - `format_type` - The format type used to produce the required formatter.
297
    /// - `custom_formatter` - The optional boxed custom formatter.
298
    ///   Used by the [`FormatType::Custom`] to produce a [`Formatter::Custom`].
299
    ///
300
    /// ## Examples
301
    /// First, using a provided formatter:
302
    /// ```
303
    /// extern crate flogging;
304
    /// use flogging::*;
305
    ///
306
    /// let mut log = Logger::builder(module_path!())
307
    ///     .add_file_handler_with("test_logs/builder.log", FormatType::Iso8601, None)
308
    ///     .build();
309
    /// ```
310
    /// Now using a custom formatter:
311
    /// ```
312
    /// extern crate flogging;
313
    /// use flogging::*;
314
    ///
315
    /// let mut log = Logger::builder(module_path!())
316
    ///     .add_file_handler_with(
317
    ///         "test_logs/builder.log",
318
    ///         FormatType::Custom,
319
    ///         Some(Box::new(MockFormatter::new())),
320
    ///     )
321
    ///     .build();
322
    /// ```
323
    ///
3243
    pub fn add_file_handler_with(
3253
        self,
3263
        filename: &str,
3273
        format_type: FormatType,
3283
        custom_formatter: Option<Box<dyn FormatTrait>>,
3293
    ) -> Self {
3303
        self.add_handler_with(
3313
            Handler::File,
3323
            None,
3333
            Some(filename),
3343
            Some(format_type),
3353
            custom_formatter,
336
        )
3373
    }
338
33965
    fn add_handler_with(
34065
        mut self,
34165
        handler: Handler,
34265
        custom_handler: Option<Box<dyn HandlerTrait>>,
34365
        filename: Option<&str>,
34465
        format_type: Option<FormatType>,
34565
        custom_formatter: Option<Box<dyn FormatTrait>>,
34665
    ) -> Self {
34765
        let name = filename.unwrap_or(&self.mod_path);
34865
        let mut h: Box<dyn HandlerTrait> = match handler {
349
            Handler::Console => {
35018
                Box::new(ConsoleHandler::create(ConsoleType::StdOut.as_str()).unwrap())
351
            }
352
            Handler::EConsole => {
3536
                Box::new(ConsoleHandler::create(ConsoleType::StdErr.as_str()).unwrap())
354
            }
35520
            Handler::File => Box::new(FileHandler::create(name).unwrap()),
356
            Handler::PConsole => {
3574
                Box::new(ConsoleHandler::create(ConsoleType::Production.as_str()).unwrap())
358
            }
35912
            Handler::String => Box::new(StringHandler::create(name).unwrap()),
3605
            Handler::Custom(_) => custom_handler.unwrap(),
361
        };
362
36365
        if let Some(f) = format_type {
36412
            h.set_formatter(match f {
3655
                FormatType::Iso8601 => f.create(None),
3663
                FormatType::Simple => f.create(None),
3671
                FormatType::UnixTimestamp => f.create(None),
3683
                FormatType::Custom => f.create(custom_formatter),
369
            });
37053
        }
371
37265
        let map = self.handlers.get_mut();
37365
        map.insert(handler, h);
374
37565
        self
37665
    }
377
378
    ///
379
    /// Adds a [`ConsoleHandler`] with the default formatter,
380
    /// with output according to: [`ConsoleType::Production`].
381
    ///
382
    /// ## Examples
383
    /// ```
384
    /// extern crate flogging;
385
    /// use flogging::*;
386
    ///
387
    /// let mut log = Logger::builder(module_path!())
388
    ///     .add_pconsole_handler()
389
    ///     .build();
390
    /// ```
391
    ///
3923
    pub fn add_pconsole_handler(self) -> Self {
3933
        self.add_handler_with(Handler::PConsole, None, None, None, None)
3943
    }
395
396
    ///
397
    /// Adds a [`ConsoleHandler`] with the required formatter,
398
    /// with output according to: [`ConsoleType::Production`].
399
    ///
400
    /// ## Parameters
401
    /// - `format_type` - The format type used to produce the required formatter.
402
    /// - `custom_formatter` - The optional boxed custom formatter.
403
    ///   Used by the [`FormatType::Custom`] to produce a [`Formatter::Custom`].
404
    ///
405
    /// ## Examples
406
    /// First, using a provided formatter:
407
    /// ```
408
    /// extern crate flogging;
409
    /// use flogging::*;
410
    ///
411
    /// let mut log = Logger::builder(module_path!())
412
    ///     .add_pconsole_handler_with(FormatType::Iso8601, None)
413
    ///     .build();
414
    /// ```
415
    /// Now using a custom formatter:
416
    /// ```
417
    /// extern crate flogging;
418
    /// use flogging::*;
419
    ///
420
    /// let mut log = Logger::builder(module_path!())
421
    ///     .add_pconsole_handler_with(
422
    ///         FormatType::Custom,
423
    ///         Some(Box::new(MockFormatter::new())),
424
    ///     )
425
    ///     .build();
426
    /// ```
427
    ///
4281
    pub fn add_pconsole_handler_with(
4291
        self,
4301
        format_type: FormatType,
4311
        custom_formatter: Option<Box<dyn FormatTrait>>,
4321
    ) -> Self {
4331
        self.add_handler_with(
4341
            Handler::PConsole,
4351
            None,
4361
            None,
4371
            Some(format_type),
4381
            custom_formatter,
439
        )
4401
    }
441
442
    ///
443
    /// Adds a [`StringHandler`] with the default formatter.
444
    ///
445
    /// ## Examples
446
    /// ```
447
    /// extern crate flogging;
448
    /// use flogging::*;
449
    ///
450
    /// let mut log = Logger::builder(module_path!())
451
    ///     .add_string_handler()
452
    ///     .build();
453
    /// ```
454
    ///
45511
    pub fn add_string_handler(self) -> Self {
45611
        self.add_handler_with(Handler::String, None, None, None, None)
45711
    }
458
459
    ///
460
    /// Adds a [`StringHandler`] with the required formatter.
461
    ///
462
    /// ## Parameters
463
    /// - `format_type` - The format type used to produce the required formatter.
464
    /// - `custom_formatter` - The optional boxed custom formatter.
465
    ///   Used by the [`FormatType::Custom`] to produce a [`Formatter::Custom`].
466
    ///
467
    /// ## Examples
468
    /// First, using a provided formatter:
469
    /// ```
470
    /// extern crate flogging;
471
    /// use flogging::*;
472
    ///
473
    /// let mut log = Logger::builder(module_path!())
474
    ///     .add_string_handler_with(FormatType::Iso8601, None)
475
    ///     .build();
476
    /// ```
477
    /// Now using a custom formatter:
478
    /// ```
479
    /// extern crate flogging;
480
    /// use flogging::*;
481
    ///
482
    /// let mut log = Logger::builder(module_path!())
483
    ///     .add_string_handler_with(
484
    ///         FormatType::Custom,
485
    ///         Some(Box::new(MockFormatter::new())),
486
    ///     )
487
    ///     .build();
488
    /// ```
489
    ///
4901
    pub fn add_string_handler_with(
4911
        self,
4921
        format_type: FormatType,
4931
        custom_formatter: Option<Box<dyn FormatTrait>>,
4941
    ) -> Self {
4951
        self.add_handler_with(
4961
            Handler::String,
4971
            None,
4981
            None,
4991
            Some(format_type),
5001
            custom_formatter,
501
        )
5021
    }
503
504
    ///
505
    /// Complete the build process and produce the final [`Logger`] instance.
506
    ///
507
    /// ## Examples
508
    /// ```
509
    /// extern crate flogging;
510
    /// use flogging::*;
511
    ///
512
    /// let mut log = Logger::builder(module_path!())
513
    ///     .add_console_handler()
514
    ///     .build();
515
    /// ```
516
    ///
51745
    pub fn build(self) -> Logger {
51845
        Logger {
51945
            mod_path: self.mod_path.clone(),
52045
            fn_name: self.fn_name.clone(),
52145
            level: self.level,
52245
            handlers: self.handlers,
52345
        }
52445
    }
525
526
    ///
527
    /// Remove an existing log file.
528
    ///
529
    /// The purpose of this, is to allow resetting of the log file, each time
530
    /// a test run is done.
531
    ///
532
    /// ## Note
533
    ///
534
    /// This **must** be called _before_ adding the corresponding file handler
535
    /// that is going to open this file.
536
    ///
537
    /// ## Parameters
538
    ///
539
    /// - `filename` - The name of the output log file. Must include any relevant
540
    ///   path (relative or absolute).
541
    ///
542
    /// ## Examples
543
    /// ```
544
    /// extern crate flogging;
545
    /// use flogging::*;
546
    ///
547
    /// let mut log = Logger::builder(module_path!())
548
    ///     .remove_file("test_logs/builder.log")
549
    ///     .add_file_handler("test_logs/builder.log")
550
    ///     .build();
551
    /// ```
552
    ///
55314
    pub fn remove_file(self, filename: &str) -> Self {
55414
        let _ = fs::remove_file(filename).is_err();
55514
        self
55614
    }
557
558
    ///
559
    /// Set the current function/method name.
560
    ///
561
    /// ## Parameters
562
    /// - `fn_name` - The name of the function/method in which you are
563
    ///   logging.
564
    ///
565
    /// Returns itself for chaining purposes.
566
    ///
56715
    pub fn set_fn_name(mut self, fn_name: &str) -> Self {
56815
        self.fn_name = fn_name.to_string();
56915
        self
57015
    }
571
572
    ///
573
    /// Set the logging level for the [`Logger`] instance being configured.
574
    ///
575
    /// ## Parameters
576
    /// - `level` - The new level to set.
577
    ///
578
    /// ## Examples
579
    /// ```
580
    /// extern crate flogging;
581
    /// use flogging::*;
582
    ///
583
    /// let mut log = Logger::builder(module_path!())
584
    ///     .add_console_handler()
585
    ///     .set_level(Level::ALL)
586
    ///     .build();
587
    /// ```
588
    ///
58914
    pub fn set_level(mut self, level: Level) -> Self {
59014
        self.level = level;
59114
        self
59214
    }
593
}
594
595
#[cfg(test)]
596
mod tests {
597
    use crate::*;
598
    use regex::Regex;
599
    use std::io::{Result, Stdout, Write, stdout};
600
601
    #[test]
6021
    fn temp() -> Result<()> {
6031
        let msg = "arguments";
6041
        let mut w = stdout();
6051
        writeln!(&mut w)?;
6061
        writeln!(&mut w, "test")?;
6071
        writeln!(&mut w, "formatted {}", msg)?;
608
609
        // assert_eq!(&w[..], "\ntest\nformatted arguments\n".as_bytes());
6101
        Ok(())
6111
    }
612
    #[test]
6131
    fn add_console_handler() {
6141
        let expected = "flogging::logger::builder::tests->add_console_handler [INFO   ] We begin!
6151
flogging::logger::builder::tests->add_console_handler [WARNING] Need more tests.
6161
"
6171
        .to_string();
618
6191
        let mut log = Logger::builder(module_path!())
6201
            .add_console_handler()
6211
            .set_fn_name("add_console_handler")
6221
            .build();
623
6241
        let h = log.get_handler(crate::Handler::Console).unwrap();
6251
        h.set_test_mode(true);
626
6271
        log.info("We begin!");
6281
        log.warning("Need more tests.");
629
6301
        let h = log.get_handler(crate::Handler::Console).unwrap();
6311
        let buf = h.get_log();
6321
        assert_eq!(expected, buf);
6331
    }
634
635
    #[test]
6361
    fn add_console_handler_with() {
6371
        let re_str =
6381
"^(?:\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{9}\\+\\d{2}:\\d{2}) flogging::logger::builder::tests->add_console_handler_with \\[INFO   ] We begin!
6391
(?:\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{9}\\+\\d{2}:\\d{2}) flogging::logger::builder::tests->add_console_handler_with \\[WARNING] Need more tests.
6401
$";
641
6421
        let re = Regex::new(re_str).unwrap();
643
6441
        let mut log = Logger::builder(module_path!())
6451
            .add_console_handler_with(FormatType::Iso8601, None)
6461
            .set_fn_name("add_console_handler_with")
6471
            .build();
648
6491
        let h = log.get_handler(crate::Handler::Console).unwrap();
6501
        h.set_test_mode(true);
651
6521
        log.info("We begin!");
6531
        log.warning("Need more tests.");
654
6551
        let h = log.get_handler(crate::Handler::Console).unwrap();
6561
        let result = h.get_log();
6571
        println!("{result}");
658
6591
        assert!(re.is_match(&result));
6601
    }
661
662
    #[test]
6631
    fn add_econsole_handler() {
6641
        let mut log = Logger::builder(module_path!())
6651
            .add_econsole_handler()
6661
            .set_fn_name("add_econsole_handler")
6671
            .build();
668
6691
        log.info("We begin!");
6701
        log.warning("Need more tests.");
6711
    }
672
673
    #[test]
6741
    fn add_econsole_handler_with() {
6751
        let mut log = Logger::builder(module_path!())
6761
            .add_econsole_handler_with(FormatType::Iso8601, None)
6771
            .set_fn_name("add_econsole_handler_with")
6781
            .build();
679
6801
        log.info("We begin!");
6811
        log.warning("Need more tests.");
6821
    }
683
684
    #[test]
6851
    fn add_custom_handler() {
6861
        let mut log = Logger::builder(module_path!())
6871
            .add_custom_handler(
6881
                "Console",
6891
                Box::new(ConsoleHandler::create(ConsoleType::StdOut.as_str()).unwrap()),
690
            )
6911
            .set_fn_name("add_custom_handler")
6921
            .build();
693
6941
        log.info("We begin!");
6951
        log.warning("Need more tests.");
6961
    }
697
698
    #[test]
6991
    fn add_custom_handler_with() {
7001
        let mut log = Logger::builder(module_path!())
7011
            .add_custom_handler_with(
7021
                "Console",
7031
                Box::new(ConsoleHandler::create(ConsoleType::StdOut.as_str()).unwrap()),
7041
                FormatType::Custom,
7051
                Some(Box::new(MockFormatter::new())),
706
            )
7071
            .set_fn_name("add_custom_handler_with")
7081
            .build();
709
7101
        log.info("We begin!");
7111
        log.warning("Need more tests.");
7121
    }
713
714
    #[test]
7151
    fn add_file_handler() {
7161
        let mut log = Logger::builder(module_path!())
7171
            .add_file_handler("test_logs/add_file_handler.log")
7181
            .set_fn_name("add_file_handler")
7191
            .build();
720
7211
        log.info("We begin!");
7221
        log.warning("Need more tests.");
7231
    }
724
725
    #[test]
7261
    fn add_file_handler_with() {
7271
        let mut log = Logger::builder(module_path!())
7281
            .add_file_handler_with(
7291
                "test_logs/add_file_handler_with.log",
7301
                crate::FormatType::UnixTimestamp,
7311
                None,
732
            )
7331
            .set_fn_name("add_file_handler_with")
7341
            .build();
735
7361
        log.info("We begin!");
7371
        log.warning("Need more tests.");
7381
    }
739
740
    #[test]
7411
    fn add_pconsole_handler() {
7421
        let mut log = Logger::builder(module_path!())
7431
            .add_pconsole_handler()
7441
            .set_fn_name("add_pconsole_handler")
7451
            .build();
746
7471
        log.info("We begin!");
7481
        log.warning("Need more tests.");
7491
    }
750
751
    #[test]
7521
    fn add_pconsole_handler_with() {
7531
        let mut log = Logger::builder(module_path!())
7541
            .add_pconsole_handler_with(FormatType::Iso8601, None)
7551
            .set_fn_name("add_pconsole_handler_with")
7561
            .build();
757
7581
        log.info("We begin!");
7591
        log.warning("Need more tests.");
7601
    }
761
762
    #[test]
7631
    fn add_string_handler() {
7641
        let mut log = Logger::builder(module_path!())
7651
            .add_string_handler()
7661
            .set_fn_name("add_string_handler")
7671
            .build();
768
7691
        log.info("We begin!");
7701
        log.warning("Need more tests.");
7711
    }
772
773
    #[test]
7741
    fn add_string_handler_with() {
7751
        let mut log = Logger::builder(module_path!())
7761
            .add_string_handler_with(crate::FormatType::Simple, None)
7771
            .set_fn_name("add_string_handler_with")
7781
            .build();
779
7801
        log.info("We begin!");
7811
        log.warning("Need more tests.");
7821
    }
783
784
    #[test]
7851
    fn remove_file() {
7861
        let mut log = Logger::builder(module_path!())
7871
            .remove_file("test_logs/remove_file.log")
7881
            .add_file_handler("test_logs/remove_file.log")
7891
            .set_fn_name("add_file_handler")
7901
            .build();
791
7921
        log.info("We begin!");
7931
        log.warning("Need more tests.");
7941
    }
795
}