the_logger 0.5.3

A very simple but customizable logger for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518

/// Constant to define the initial log text content maximum length. Customizable by config
const LOG_CONTENT_INITIAL_LENGTH: usize = 300;

/// Constant to define the initial location text content maximum length. Customizable by config
const LOCATION_CONTENT_INITIAL_LENGTH: usize = 60;

#[derive(Debug)]
/// TheLoggerConfig allows the user to configure on startup the logger's output.
pub struct TheLoggerConfig {
    date_config: TheDateConfig,
    time_config: TheTimeConfig,
    misc_config: TheMiscConfig,
    log_level: LogLevel
}

#[derive(Default, Debug)]
/// Date configuration section of TheLogger's config
struct TheDateConfig {
    hide_years: bool,
    hide_months: bool,
    hide_days: bool,
}

#[derive(Default, Debug)]
/// Time configuration section of TheLogger's config
struct TheTimeConfig {
    hide_hours: bool,
    hide_minutes: bool,
    hide_seconds: bool,
    hide_millisecs: bool,
    hide_microsecs: bool,
    utc_time: bool
}

#[derive(Default, Debug)]
/// Miscellaneous configuration section, that includes the ability to:
/// - Hide the log level
/// - Hide the file name
/// - Hide the file line number
/// - Show the column number (hidden by default)
/// - Configure the location text content's maximum length
/// - Configure the log text content's maximum length
struct TheMiscConfig {
    hide_level: bool,
    hide_file_name: bool,
    hide_file_line: bool,
    show_file_column: bool,
    location_length: usize,
    log_content_length: usize
}

#[derive(Default, Debug, Copy, Clone)]
/// 7 different types of log levels to allow the user to use the log n any way they need to
pub(super) enum LogLevel {
    #[default]
    Verbose,
    Information,
    Error,
    Warning,
    Debug,
    Trace,
    Critical
}

impl TheLoggerConfig {
    // Log Type methods
    /// ## Description
    /// Configures the log level as verbose adding the [[VERBOSE]] tag
    pub async fn verbose(mut self) -> Self {
        self.log_level = LogLevel::Verbose;
        self
    }

    /// ## Description
    /// Configures the log level as informational adding the [[INFO]] tag
    pub async fn info(mut self) -> Self {
        self.log_level = LogLevel::Information;
        self
    }

    /// ## Description
    /// Configures the log level as error adding the [[ERROR]] tag
    pub async fn error(mut self) -> Self{
        self.log_level = LogLevel::Error;
        self
    }

    /// ## Description
    /// Configures the log level as warning adding the [[WARNING]] tag
    pub async fn warning(mut self) -> Self {
        self.log_level = LogLevel::Warning;
        self
    }

    /// ## Description
    /// Configures the log level as debug adding the [[DEBUG]] tag
    pub async fn debug(mut self) -> Self {
        self.log_level = LogLevel::Debug;
        self
    }

    /// ## Description
    /// Configures the log level as trace adding the [[TRACE]] tag
    pub async fn trace(mut self) -> Self {
        self.log_level = LogLevel::Trace;
        self
    }

    /// ## Description
    /// Configures the log level as critical adding the [[CRITICAL]] tag
    pub async fn critical(mut self) -> Self {
        self.log_level = LogLevel::Critical;
        self
    }
    ///////////////////////////
    /* Configuration methods */
    ///////////////////////////
    /// ## Description
    /// Configures the log date to hide the years. Default is to show them
    pub fn hide_years(mut self) -> Self {
        self.date_config.hide_years = true;
        self
    }

    /// ## Description
    /// Configures the log date to hide the months. Default is to show them
    pub fn hide_months(mut self) -> Self {
        self.date_config.hide_months = true;
        self
    }

    /// ## Description
    /// Configures the log date to hide the days. Default is to show them
    pub fn hide_days(mut self) -> Self {
        self.date_config.hide_days = true;
        self
    }

    /// ## Description
    /// Configures the log time to hide the hours. Default is to show them
    pub fn hide_hours(mut self) -> Self {
        self.time_config.hide_hours = true;
        self
    }

    /// ## Description
    /// Configures the log time to hide the minutes. Default is to show them
    pub fn hide_minutes(mut self) -> Self {
        self.time_config.hide_minutes = true;
        self
    }

    /// ## Description
    /// Configures the log time to hide the seconds. Default is to show them
    pub fn hide_seconds(mut self) -> Self {
        self.time_config.hide_seconds = true;
        self
    }

    /// ## Description
    /// Configures the log time to hide the milliseconds. Default is to show them
    ///
    /// ### Warning
    /// Hiding the milliseconds and showing the microseconds would cause an unexpected time tracking in the logs,
    ///
    /// therefore, in this specific case, both milliseconds and microseconds will be hidden
    pub fn hide_millisecs(mut self) -> Self {
        self.time_config.hide_millisecs = true;
        self
    }

    /// ## Description
    /// Configures the log time to hide the microseconds. Default is to show them
    ///
    /// ### Warning
    /// Hiding the milliseconds and showing the microseconds would cause an unexpected time tracking in the logs,
    ///
    /// therefore, in this specific case, both milliseconds and microseconds will be hidden
    pub fn hide_microsecs(mut self) -> Self {
        self.time_config.hide_microsecs = true;
        self
    }

    /// ## Description
    /// Configures the log timezone to UTC format. Default is Local time
    pub fn utc_time(mut self) -> Self {
        self.time_config.utc_time = true;
        self
    }

    /// ## Description
    /// Configures the log level to be hidden. Default is to show it
    pub fn hide_level(mut self) -> Self {
        self.misc_config.hide_level = true;
        self
    }

    /// ## Description
    /// Configures the log file location to be hidden. Default is to show it
    pub fn hide_file_name(mut self) -> Self {
        self.misc_config.hide_file_name = true;
        self.misc_config.hide_file_line = true;
        self.misc_config.show_file_column = false;
        self
    }

    /// ## Description
    /// Configures the log file line number to be hidden. Default is to show it
    pub fn hide_file_line(mut self) -> Self {
        self.misc_config.hide_file_line = true;
        self
    }

    /// ## Description
    /// Configures the log file column number to be hidden. Default is to hide it
    pub fn hide_file_column(mut self) -> Self {
        self.misc_config.show_file_column = false;
        self
    }

    /// ## Description
    /// Configures the log date to show the years. Default is to show them
    pub fn show_years(mut self) -> Self {
        self.date_config.hide_years = false;
        self
    }

    /// ## Description
    /// Configures the log date to show the months. Default is to show them
    pub fn show_months(mut self) -> Self {
        self.date_config.hide_months = false;
        self
    }

    /// ## Description
    /// Configures the log date to show the days. Default is to show them
    pub fn show_days(mut self) -> Self {
        self.date_config.hide_days = false;
        self
    }

    /// ## Description
    /// Configures the log time to show the hours. Default is to show them
    pub fn show_hours(mut self) -> Self {
        self.time_config.hide_hours = false;
        self
    }

    /// ## Description
    /// Configures the log time to show the minutes. Default is to show them
    pub fn show_minutes(mut self) -> Self {
        self.time_config.hide_minutes = false;
        self
    }

    /// ## Description
    /// Configures the log time to show the seconds. Default is to show them
    pub fn show_seconds(mut self) -> Self {
        self.time_config.hide_seconds = false;
        self
    }

    /// ## Description
    /// Configures the log time to show the milliseconds. Default is to show them
    ///
    /// ### Warning
    /// Hiding the milliseconds and showing the microseconds would cause an unexpected time tracking in the logs,
    ///
    /// therefore, in this specific case, both milliseconds and microseconds will be hidden
    pub fn show_millisecs(mut self) -> Self {
        self.time_config.hide_millisecs = false;
        self
    }

    /// ## Description
    /// Configures the log time to show the microseconds. Default is to show them
    ///
    /// ### Warning
    /// Hiding the milliseconds and showing the microseconds would cause an unexpected time tracking in the logs,
    ///
    /// therefore, in this specific case, both milliseconds and microseconds will be hidden
    pub fn show_microsecs(mut self) -> Self {
        self.time_config.hide_microsecs = false;
        self
    }

    /// ## Description
    /// Configures the log timezone to Local format. Default is Local time
    pub fn local_time(mut self) -> Self {
        self.time_config.utc_time = false;
        self
    }

    /// ## Description
    /// Configures the log level to be shown. Default is to show it
    pub fn show_level(mut self) -> Self {
        self.misc_config.hide_level = false;
        self
    }

    /// ## Description
    /// Configures the log file location to be shown. Default is to show it
    pub fn show_file_name(mut self) -> Self {
        self.misc_config.hide_file_name = false;
        self
    }

    /// ## Description
    /// Configures the log file line number to be shown. Default is to show it
    pub fn show_file_line(mut self) -> Self {
        self.misc_config.hide_file_line = false;
        self
    }

    /// ## Description
    /// Configures the log file column number to be shown. Default is to hide it
    pub fn show_file_column(mut self) -> Self {
        self.misc_config.show_file_column = true;
        self
    }

    /// ## Description
    /// Configures the log file name, line and column location content's length. Default is 100 characters
    pub fn location_content_length(mut self, length: usize) -> Self {
        self.misc_config.location_length = length;
        self
    }

    /// ## Description
    /// Configures the log message content's length. Default is 300 characters
    pub fn log_content_length(mut self, length: usize) -> Self {
        self.misc_config.log_content_length = length;
        self
    }

    /////////////
    /* Getters */
    /////////////
    #[doc(hidden)]
    pub(super) fn get_years_config(&self) -> bool {
        self.date_config.hide_years
    }

    #[doc(hidden)]
    pub(super) fn get_months_config(&self) -> bool {
        self.date_config.hide_months
    }

    #[doc(hidden)]
    pub(super) fn get_days_config(&self) -> bool {
        self.date_config.hide_days
    }

    #[doc(hidden)]
    pub(super) fn get_hours_config(&self) -> bool {
        self.time_config.hide_hours
    }

    #[doc(hidden)]
    pub(super) fn get_minutes_config(&self) -> bool {
        self.time_config.hide_minutes
    }

    #[doc(hidden)]
    pub(super) fn get_seconds_config(&self) -> bool {
        self.time_config.hide_seconds
    }

    #[doc(hidden)]
    pub(super) fn get_millisecs_config(&self) -> bool {
        self.time_config.hide_millisecs
    }

    #[doc(hidden)]
    pub(super) fn get_microsecs_config(&self) -> bool {
        self.time_config.hide_microsecs
    }

    #[doc(hidden)]
    pub(super) fn get_utc_config(&self) -> bool {
        self.time_config.utc_time
    }

    #[doc(hidden)]
    pub(super) fn get_level_config(&self) -> bool {
        self.misc_config.hide_level
    }

    #[doc(hidden)]
    pub(super) fn get_file_name_config(&self) -> bool {
        self.misc_config.hide_file_name
    }

    #[doc(hidden)]
    pub(super) fn get_file_line_config(&self) -> bool {
        self.misc_config.hide_file_line
    }

    #[doc(hidden)]
    pub(super) fn get_file_column_config(&self) -> bool {
        self.misc_config.show_file_column
    }

    #[doc(hidden)]
    pub(super) fn get_log_level(&self) -> LogLevel {
        self.log_level
    }

    #[doc(hidden)]
    pub(super) fn get_location_length(&self) -> usize {
        self.misc_config.location_length
    }

    #[doc(hidden)]
    pub(super) fn get_log_content_length(&self) -> usize {
        self.misc_config.log_content_length
    }

    /////////////
    /* Setters */
    /////////////
    #[doc(hidden)]
    pub(super) fn set_years_config(&mut self, data: bool) {
        self.date_config.hide_years = data;
    }

    #[doc(hidden)]
    pub(super) fn set_months_config(&mut self, data: bool) {
        self.date_config.hide_months = data;
    }

    #[doc(hidden)]
    pub(super) fn set_days_config(&mut self, data: bool) {
        self.date_config.hide_days = data;
    }

    #[doc(hidden)]
    pub(super) fn set_hours_config(&mut self, data: bool) {
        self.time_config.hide_hours = data;
    }

    #[doc(hidden)]
    pub(super) fn set_minutes_config(&mut self, data: bool) {
        self.time_config.hide_minutes = data;
    }

    #[doc(hidden)]
    pub(super) fn set_seconds_config(&mut self, data: bool) {
        self.time_config.hide_seconds = data;
    }

    #[doc(hidden)]
    pub(super) fn set_millisecs_config(&mut self, data: bool) {
        self.time_config.hide_millisecs = data;
    }

    #[doc(hidden)]
    pub(super) fn set_microsecs_config(&mut self, data: bool) {
        self.time_config.hide_microsecs = data;
    }

    #[doc(hidden)]
    pub(super) fn set_utc_config(&mut self, data: bool) {
        self.time_config.utc_time = data;
    }

    #[doc(hidden)]
    pub(super) fn set_level_config(&mut self, data: bool) {
        self.misc_config.hide_level = data;
    }

    #[doc(hidden)]
    pub(super) fn set_file_name_config(&mut self, data: bool) {
        self.misc_config.hide_file_name = data;
    }

    #[doc(hidden)]
    pub(super) fn set_file_line_config(&mut self, data: bool) {
        self.misc_config.hide_file_line = data;
    }

    #[doc(hidden)]
    pub(super) fn set_file_column_config(&mut self, data: bool) {
        self.misc_config.show_file_column = data;
    }

    #[doc(hidden)]
    pub(super) fn set_log_level(&mut self, data: LogLevel) {
        self.log_level = data;
    }

    #[doc(hidden)]
    pub(super) fn set_location_length(&mut self, data: usize) {
        self.misc_config.location_length = data;
    }

    #[doc(hidden)]
    pub(super) fn set_log_content_length(&mut self, data: usize) {
        self.misc_config.log_content_length = data;
    }
}

impl Default for TheLoggerConfig {
    /// Custom implementation of the default trait to include default length values for location and log content text
    fn default() -> Self {
        Self {
            date_config: TheDateConfig::default(),
            time_config: TheTimeConfig::default(),
            misc_config: TheMiscConfig {
                location_length: LOCATION_CONTENT_INITIAL_LENGTH,
                log_content_length: LOG_CONTENT_INITIAL_LENGTH,
                ..Default::default()
            },
            log_level: LogLevel::Verbose
        }
    }
}