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
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
use std::{
    cmp, fmt,
    hash::Hash,
    str::FromStr,
    sync::atomic::{self, AtomicU32},
};

/// An enum representing the verbosity levels for logging.
#[repr(u32)]
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
pub enum Level {
    /// The "fatal" level.
    ///
    /// Crashes, panics.
    Fatal = 1,
    /// The "error" level.
    ///
    /// Designates very serious errors.
    Error,
    /// The "warn" level.
    ///
    /// Designates hazardous situations.
    Warn,
    /// The "info" level.
    ///
    /// Designates useful information.
    Info,
    /// The "debug" level.
    ///
    /// Designates lower priority information.
    Debug,
    /// The "trace" level.
    ///
    /// Designates very low priority, often extremely verbose, information.
    Trace,
}

impl Level {
    pub fn from_value(value: u32) -> Option<Self> {
        match value {
            1 => Some(Self::Fatal),
            2 => Some(Self::Error),
            3 => Some(Self::Warn),
            4 => Some(Self::Info),
            5 => Some(Self::Debug),
            6 => Some(Self::Trace),
            _ => None,
        }
    }
}

/// An enum representing the available verbosity level filters of the logger.
#[repr(u32)]
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
pub enum LevelFilter {
    /// A level lower than all log levels.
    Off,
    /// Corresponds to the `Fatal` log level.
    Fatal,
    /// Corresponds to the `Error` log level.
    Error,
    /// Corresponds to the `Warn` log level.
    Warn,
    /// Corresponds to the `Info` log level.
    Info,
    /// Corresponds to the `Debug` log level.
    Debug,
    /// Corresponds to the `Trace` log level.
    Trace,
}

impl PartialEq<LevelFilter> for Level {
    #[inline(always)]
    fn eq(&self, other: &LevelFilter) -> bool {
        *self as u32 == *other as u32
    }
}

impl PartialOrd for Level {
    #[inline(always)]
    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
        Some(self.cmp(other))
    }

    #[inline(always)]
    fn lt(&self, other: &Self) -> bool {
        (*self as u32) < *other as u32
    }

    #[inline(always)]
    fn le(&self, other: &Self) -> bool {
        *self as u32 <= *other as u32
    }

    #[inline(always)]
    fn gt(&self, other: &Self) -> bool {
        *self as u32 > *other as u32
    }

    #[inline(always)]
    fn ge(&self, other: &Self) -> bool {
        *self as u32 >= *other as u32
    }
}

impl PartialOrd<LevelFilter> for Level {
    #[inline(always)]
    fn partial_cmp(&self, other: &LevelFilter) -> Option<cmp::Ordering> {
        Some((*self as u32).cmp(&(*other as u32)))
    }

    #[inline(always)]
    fn lt(&self, other: &LevelFilter) -> bool {
        (*self as u32) < *other as u32
    }

    #[inline(always)]
    fn le(&self, other: &LevelFilter) -> bool {
        *self as u32 <= *other as u32
    }

    #[inline(always)]
    fn gt(&self, other: &LevelFilter) -> bool {
        *self as u32 > *other as u32
    }

    #[inline(always)]
    fn ge(&self, other: &LevelFilter) -> bool {
        *self as u32 >= *other as u32
    }
}

impl Ord for Level {
    #[inline(always)]
    fn cmp(&self, other: &Self) -> cmp::Ordering {
        (*self as u32).cmp(&(*other as u32))
    }
}

fn ok_or<T, E>(t: Option<T>, e: E) -> Result<T, E> {
    match t {
        Some(t) => Ok(t),
        None => Err(e),
    }
}

pub struct ParseLevelError(());

impl FromStr for Level {
    type Err = ParseLevelError;
    fn from_str(level: &str) -> Result<Self, Self::Err> {
        ok_or(
            LEVEL_NAMES
                .iter()
                .position(|&name| str::eq_ignore_ascii_case(name, level))
                .into_iter()
                .filter(|&idx| idx != 0)
                .map(|idx| Self::from_u32(idx as u32).unwrap())
                .next(),
            ParseLevelError(()),
        )
    }
}

impl fmt::Display for Level {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.pad(self.as_str())
    }
}

impl Level {
    pub(crate) fn from_u32(u: u32) -> Option<Self> {
        match u {
            1 => Some(Self::Fatal),
            2 => Some(Self::Error),
            3 => Some(Self::Warn),
            4 => Some(Self::Info),
            5 => Some(Self::Debug),
            6 => Some(Self::Trace),
            _ => None,
        }
    }
    /// Returns the most verbose logging level.
    #[inline(always)]
    pub fn max() -> Self {
        Self::Trace
    }

    /// Converts the `Level` to the equivalent `LevelFilter`.
    #[inline(always)]
    pub fn to_level_filter(self) -> LevelFilter {
        LevelFilter::from_u32(self as u32).unwrap()
    }

    /// Returns the string representation of the `Level`.
    ///
    /// This returns the same string as the `fmt::Display` implementation.
    pub fn as_str(self) -> &'static str {
        LEVEL_NAMES[self as usize]
    }

    /// Iterate through all supported logging levels.
    ///
    /// The order of iteration is from more severe to less severe log messages.
    ///
    /// # Examples
    ///
    /// ```
    /// use micromegas_tracing::prelude::*;
    ///
    /// let mut levels = Level::iter();
    ///
    /// assert_eq!(Some(Level::Fatal), levels.next());
    /// assert_eq!(Some(Level::Trace), levels.last());
    /// ```
    pub fn iter() -> impl Iterator<Item = Self> {
        (1..7).map(|i| Self::from_u32(i).unwrap())
    }
}

impl PartialEq<Level> for LevelFilter {
    #[inline(always)]
    fn eq(&self, other: &Level) -> bool {
        other.eq(self)
    }
}

impl PartialOrd for LevelFilter {
    #[inline(always)]
    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
        Some(self.cmp(other))
    }

    #[inline(always)]
    fn lt(&self, other: &Self) -> bool {
        (*self as u32) < *other as u32
    }

    #[inline(always)]
    fn le(&self, other: &Self) -> bool {
        *self as u32 <= *other as u32
    }

    #[inline(always)]
    fn gt(&self, other: &Self) -> bool {
        *self as u32 > *other as u32
    }

    #[inline(always)]
    fn ge(&self, other: &Self) -> bool {
        *self as u32 >= *other as u32
    }
}

impl PartialOrd<Level> for LevelFilter {
    #[inline(always)]
    fn partial_cmp(&self, other: &Level) -> Option<cmp::Ordering> {
        Some((*self as u32).cmp(&(*other as u32)))
    }

    #[inline(always)]
    fn lt(&self, other: &Level) -> bool {
        (*self as u32) < *other as u32
    }

    #[inline(always)]
    fn le(&self, other: &Level) -> bool {
        *self as u32 <= *other as u32
    }

    #[inline(always)]
    fn gt(&self, other: &Level) -> bool {
        *self as u32 > *other as u32
    }

    #[inline(always)]
    fn ge(&self, other: &Level) -> bool {
        *self as u32 >= *other as u32
    }
}

impl Ord for LevelFilter {
    #[inline(always)]
    fn cmp(&self, other: &Self) -> cmp::Ordering {
        (*self as u32).cmp(&(*other as u32))
    }
}

impl FromStr for LevelFilter {
    type Err = ParseLevelError;
    fn from_str(level: &str) -> Result<Self, Self::Err> {
        ok_or(
            LEVEL_NAMES
                .iter()
                .position(|&name| str::eq_ignore_ascii_case(name, level))
                .map(|p| Self::from_u32(p as u32).unwrap()),
            ParseLevelError(()),
        )
    }
}

impl fmt::Display for LevelFilter {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.pad(self.as_str())
    }
}

impl LevelFilter {
    pub(crate) fn from_u32(u: u32) -> Option<Self> {
        match u {
            0 => Some(Self::Off),
            1 => Some(Self::Fatal),
            2 => Some(Self::Error),
            3 => Some(Self::Warn),
            4 => Some(Self::Info),
            5 => Some(Self::Debug),
            6 => Some(Self::Trace),
            _ => None,
        }
    }

    /// Returns the most verbose logging level filter.
    #[inline(always)]
    pub fn max() -> Self {
        Self::Trace
    }

    /// Converts `self` to the equivalent `Level`.
    ///
    /// Returns `None` if `self` is `LevelFilter::Off`.
    #[inline(always)]
    pub fn to_level(self) -> Option<Level> {
        Level::from_u32(self as u32)
    }

    /// Returns the string representation of the `LevelFilter`.
    ///
    /// This returns the same string as the `fmt::Display` implementation.
    pub fn as_str(self) -> &'static str {
        LEVEL_NAMES[self as usize]
    }

    /// Iterate through all supported filtering levels.
    ///
    /// The order of iteration is from less to more verbose filtering.
    ///
    /// # Examples
    ///
    /// ```
    /// use micromegas_tracing::prelude::*;
    ///
    /// let mut levels = LevelFilter::iter();
    ///
    /// assert_eq!(Some(LevelFilter::Off), levels.next());
    /// assert_eq!(Some(LevelFilter::Trace), levels.last());
    /// ```
    pub fn iter() -> impl Iterator<Item = Self> {
        (0..7).map(|i| Self::from_u32(i).unwrap())
    }
}

#[repr(u32)]
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
/// An enum representing the level of verbosity for `metrics`/`thread_spans`/`spans`.
pub enum Verbosity {
    /// The "min" level.
    ///
    /// Designates vey low details events, meaning overall lower frequency.
    Min = 1,
    /// The "med" level.
    ///
    /// Designates medium level level of details, meaning overall medium frequency
    Med,
    /// The "Max" level.
    ///
    /// Designates very high frequency events.
    Max,
}

/// An enum representing the available verbosity level filters of the logger.
#[repr(u32)]
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
pub enum LodFilter {
    /// A level lower than all log levels.
    Off,
    /// Corresponds to the `Min` log level.
    Min,
    /// Corresponds to the `Med` log level.
    Med,
    /// Corresponds to the `Max` log level.
    Max,
}

impl PartialEq<LodFilter> for Verbosity {
    #[inline(always)]
    fn eq(&self, other: &LodFilter) -> bool {
        *self as u32 == *other as u32
    }
}

impl PartialOrd for Verbosity {
    #[inline(always)]
    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
        Some(self.cmp(other))
    }

    #[inline(always)]
    fn lt(&self, other: &Self) -> bool {
        (*self as u32) < *other as u32
    }

    #[inline(always)]
    fn le(&self, other: &Self) -> bool {
        *self as u32 <= *other as u32
    }

    #[inline(always)]
    fn gt(&self, other: &Self) -> bool {
        *self as u32 > *other as u32
    }

    #[inline(always)]
    fn ge(&self, other: &Self) -> bool {
        *self as u32 >= *other as u32
    }
}

impl PartialOrd<LodFilter> for Verbosity {
    #[inline(always)]
    fn partial_cmp(&self, other: &LodFilter) -> Option<cmp::Ordering> {
        Some((*self as u32).cmp(&(*other as u32)))
    }

    #[inline(always)]
    fn lt(&self, other: &LodFilter) -> bool {
        (*self as u32) < *other as u32
    }

    #[inline(always)]
    fn le(&self, other: &LodFilter) -> bool {
        *self as u32 <= *other as u32
    }

    #[inline(always)]
    fn gt(&self, other: &LodFilter) -> bool {
        *self as u32 > *other as u32
    }

    #[inline(always)]
    fn ge(&self, other: &LodFilter) -> bool {
        *self as u32 >= *other as u32
    }
}

impl Ord for Verbosity {
    #[inline(always)]
    fn cmp(&self, other: &Self) -> cmp::Ordering {
        (*self as u32).cmp(&(*other as u32))
    }
}

impl FromStr for Verbosity {
    type Err = ParseLevelError;
    fn from_str(level: &str) -> Result<Self, Self::Err> {
        ok_or(
            LOD_NAMES
                .iter()
                .position(|&name| str::eq_ignore_ascii_case(name, level))
                .into_iter()
                .filter(|&idx| idx != 0)
                .map(|idx| Self::from_usize(idx).unwrap())
                .next(),
            ParseLevelError(()),
        )
    }
}

impl fmt::Display for Verbosity {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.pad(self.as_str())
    }
}

impl Verbosity {
    fn from_usize(u: usize) -> Option<Self> {
        match u {
            1 => Some(Self::Min),
            2 => Some(Self::Med),
            3 => Some(Self::Max),
            _ => None,
        }
    }

    fn from_u32(u: u32) -> Option<Self> {
        match u {
            1 => Some(Self::Min),
            2 => Some(Self::Med),
            3 => Some(Self::Max),
            _ => None,
        }
    }

    /// Returns the most verbose logging level.
    #[inline(always)]
    pub fn max() -> Self {
        Self::Max
    }

    /// Converts the `Lod` to the equivalent `LodFilter`.
    #[inline(always)]
    pub fn to_level_filter(self) -> LodFilter {
        LodFilter::from_u32(self as u32).unwrap()
    }

    /// Returns the string representation of the `Lod`.
    ///
    /// This returns the same string as the `fmt::Display` implementation.
    pub fn as_str(self) -> &'static str {
        LOD_NAMES[self as usize]
    }

    /// Iterate through all supported logging levels.
    ///
    /// The order of iteration is from more severe to less severe log messages.
    ///
    /// # Examples
    ///
    /// ```
    /// use micromegas_tracing::prelude::*;
    ///
    /// let mut lods = Verbosity::iter();
    ///
    /// assert_eq!(Some(Verbosity::Min), lods.next());
    /// assert_eq!(Some(Verbosity::Max), lods.last());
    /// ```
    pub fn iter() -> impl Iterator<Item = Self> {
        (1..4).map(|i| Self::from_usize(i).unwrap())
    }
}

impl PartialEq<Verbosity> for LodFilter {
    #[inline(always)]
    fn eq(&self, other: &Verbosity) -> bool {
        other.eq(self)
    }
}

impl PartialOrd for LodFilter {
    #[inline(always)]
    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
        Some(self.cmp(other))
    }

    #[inline(always)]
    fn lt(&self, other: &Self) -> bool {
        (*self as u32) < *other as u32
    }

    #[inline(always)]
    fn le(&self, other: &Self) -> bool {
        *self as u32 <= *other as u32
    }

    #[inline(always)]
    fn gt(&self, other: &Self) -> bool {
        *self as u32 > *other as u32
    }

    #[inline(always)]
    fn ge(&self, other: &Self) -> bool {
        *self as u32 >= *other as u32
    }
}

impl PartialOrd<Verbosity> for LodFilter {
    #[inline(always)]
    fn partial_cmp(&self, other: &Verbosity) -> Option<cmp::Ordering> {
        Some((*self as u32).cmp(&(*other as u32)))
    }

    #[inline(always)]
    fn lt(&self, other: &Verbosity) -> bool {
        (*self as u32) < *other as u32
    }

    #[inline(always)]
    fn le(&self, other: &Verbosity) -> bool {
        *self as u32 <= *other as u32
    }

    #[inline(always)]
    fn gt(&self, other: &Verbosity) -> bool {
        *self as u32 > *other as u32
    }

    #[inline(always)]
    fn ge(&self, other: &Verbosity) -> bool {
        *self as u32 >= *other as u32
    }
}

impl Ord for LodFilter {
    #[inline(always)]
    fn cmp(&self, other: &Self) -> cmp::Ordering {
        (*self as u32).cmp(&(*other as u32))
    }
}

impl FromStr for LodFilter {
    type Err = ParseLevelError;
    fn from_str(level: &str) -> Result<Self, Self::Err> {
        ok_or(
            LOD_NAMES
                .iter()
                .position(|&name| str::eq_ignore_ascii_case(name, level))
                .map(|p| Self::from_usize(p).unwrap()),
            ParseLevelError(()),
        )
    }
}

impl fmt::Display for LodFilter {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.pad(self.as_str())
    }
}

impl LodFilter {
    fn from_usize(u: usize) -> Option<Self> {
        match u {
            0 => Some(Self::Off),
            1 => Some(Self::Min),
            2 => Some(Self::Med),
            3 => Some(Self::Max),
            _ => None,
        }
    }

    fn from_u32(u: u32) -> Option<Self> {
        match u {
            0 => Some(Self::Off),
            1 => Some(Self::Min),
            2 => Some(Self::Med),
            3 => Some(Self::Max),
            _ => None,
        }
    }

    /// Returns the most verbose logging level filter.
    #[inline(always)]
    pub fn max() -> Self {
        Self::Max
    }

    /// Converts `self` to the equivalent `Lod`.
    ///
    /// Returns `None` if `self` is `LodFilter::Off`.
    #[inline(always)]
    pub fn to_level(self) -> Option<Verbosity> {
        Verbosity::from_u32(self as u32)
    }

    /// Returns the string representation of the `LodFilter`.
    ///
    /// This returns the same string as the `fmt::Display` implementation.
    pub fn as_str(self) -> &'static str {
        LOD_NAMES[self as usize]
    }

    /// Iterate through all supported filtering levels.
    ///
    /// The order of iteration is from less to more verbose filtering.
    ///
    /// # Examples
    ///
    /// ```
    /// use micromegas_tracing::prelude::*;
    ///
    /// let mut lod_filters = LodFilter::iter();
    ///
    /// assert_eq!(Some(LodFilter::Off), lod_filters.next());
    /// assert_eq!(Some(LodFilter::Max), lod_filters.last());
    /// ```
    pub fn iter() -> impl Iterator<Item = Self> {
        (0..4).map(|i| Self::from_usize(i).unwrap())
    }
}

static MAX_LEVEL_FILTER: AtomicU32 = AtomicU32::new(0);
static MAX_LOD_FILTER: AtomicU32 = AtomicU32::new(0);

static LEVEL_NAMES: [&str; 7] = ["OFF", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"];
static LOD_NAMES: [&str; 4] = ["OFF", "LOW", "MED", "HIGH"];

/// Sets the global maximum log level.
///
/// Generally, this should only be called by the active logging implementation.
///
/// Note that `Trace` is the maximum level, because it provides the maximum amount of detail in the emitted logs.
#[inline(always)]
pub fn set_max_level(level: LevelFilter) {
    MAX_LEVEL_FILTER.store(level as u32, atomic::Ordering::Relaxed);
}

/// Returns the current maximum log level.
#[inline(always)]
pub fn max_level() -> LevelFilter {
    // Since `LevelFilter` is `repr(u32)`,
    // this transmute is sound if and only if `MAX_LOG_LEVEL_FILTER`
    // is set to a u32 that is a valid discriminant for `LevelFilter`.
    // Since `MAX_LOG_LEVEL_FILTER` is private, the only time it's set
    // is by `set_max_level` above, i.e. by casting a `LevelFilter` to `u32`.
    // So any u32 stored in `MAX_LOG_LEVEL_FILTER` is a valid discriminant.
    unsafe { std::mem::transmute(MAX_LEVEL_FILTER.load(atomic::Ordering::Relaxed)) }
}

/// Sets the global maximum log level.
#[inline(always)]
pub fn set_max_lod(level: LodFilter) {
    MAX_LOD_FILTER.store(level as u32, atomic::Ordering::Relaxed);
}

/// Returns the current maximum log level.
#[inline(always)]
pub fn max_lod() -> LodFilter {
    // See comment above
    unsafe { std::mem::transmute(MAX_LOD_FILTER.load(atomic::Ordering::Relaxed)) }
}

/// The statically resolved maximum log level.
///
/// See the crate level documentation for information on how to configure this.
///
/// This value is checked by the log macros, but not by the `Log`ger returned by
/// the [`logger`] function. Code that manually calls functions on that value
/// should compare the level against this value.
///
/// [`logger`]: fn.logger.html
pub const STATIC_MAX_LEVEL: LevelFilter = MAX_LEVEL_INNER;

cfg_if::cfg_if! {
    if #[cfg(all(not(debug_assertions), feature = "release_max_level_off"))] {
        const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Off;
    } else if #[cfg(all(not(debug_assertions), feature = "release_max_level_error"))] {
        const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Error;
    } else if #[cfg(all(not(debug_assertions), feature = "release_max_level_warn"))] {
        const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Warn;
    } else if #[cfg(all(not(debug_assertions), feature = "release_max_level_info"))] {
        const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Info;
    } else if #[cfg(all(not(debug_assertions), feature = "release_max_level_debug"))] {
        const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Debug;
    } else if #[cfg(all(not(debug_assertions), feature = "release_max_level_trace"))] {
        const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Trace;
    } else if #[cfg(feature = "max_level_off")] {
        const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Off;
    } else if #[cfg(feature = "max_level_error")] {
        const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Error;
    } else if #[cfg(feature = "max_level_warn")] {
        const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Warn;
    } else if #[cfg(feature = "max_level_info")] {
        const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Info;
    } else if #[cfg(feature = "max_level_debug")] {
        const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Debug;
    } else {
        const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Trace;
    }
}

/// The statically resolved maximum metrics/spans lod.
///
/// See the crate level documentation for information on how to configure this.
///
/// This value is checked by the log macros, but not by the `Log`ger returned by
/// the [`logger`] function. Code that manually calls functions on that value
/// should compare the level against this value.
///
/// [`logger`]: fn.logger.html
pub const STATIC_MAX_LOD: LodFilter = MAX_LOD_INNER;

cfg_if::cfg_if! {
    if #[cfg(all(not(debug_assertions), feature = "release_max_lod_off"))] {
        const MAX_LOD_INNER: LodFilter = LodFilter::Off;
    } else if #[cfg(all(not(debug_assertions), feature = "release_max_lod_min"))] {
        const MAX_LOD_INNER: LodFilter = LodFilter::Min;
    } else if #[cfg(all(not(debug_assertions), feature = "release_max_lod_med"))] {
        const MAX_LOD_INNER: LodFilter = LodFilter::Med;
    } else if #[cfg(all(not(debug_assertions), feature = "release_max_lod_max"))] {
        const MAX_LOD_INNER: LodFilter = LodFilter::Max;
    } else if #[cfg(feature = "max_lod_off")] {
        const MAX_LOD_INNER: LodFilter = LodFilter::Off;
    } else if #[cfg(feature = "max_lod_min")] {
        const MAX_LOD_INNER: LodFilter = LodFilter::Min;
    } else if #[cfg(feature = "max_lod_med")] {
        const MAX_LOD_INNER: LodFilter = LodFilter::Med;
    } else {
        const MAX_LOD_INNER: LodFilter = LodFilter::Max;
    }
}