Skip to main content

ferrilog_core/
lib.rs

1#![feature(min_specialization, thread_local, core_intrinsics)]
2#![allow(internal_features)]
3
4pub mod builder;
5pub mod encode;
6pub mod header;
7pub mod logger;
8pub mod number_format;
9pub mod output;
10pub mod poller;
11pub mod spsc_queue;
12pub mod thread_buffer;
13pub mod timestamp_counter;
14
15// User-facing re-exports
16pub use builder::{FlashLogBuilder, FlashLogGuard, builder};
17// Proc-macro internals -- not part of the public API surface.
18#[doc(hidden)]
19pub use encode::{
20    ENCODED_SIZE_DYNAMIC, EncodeBinary, EncodeConstBinaryFormat, EncodeConstDefaultFormat,
21    EncodeConstFloatFormat, EncodeConstLowerHexFormat, EncodeConstOctalFormat,
22    EncodeConstUpperHexFormat, EncodeLowerHex, EncodeOctal, EncodeUpperHex, FORMAT_ALIGN_CENTER,
23    FORMAT_ALIGN_LEFT, FORMAT_ALIGN_NONE, FORMAT_ALIGN_RIGHT, FORMAT_PRECISION_NONE, VecWriter,
24    append_display_const_default, append_display_with_spec,
25};
26pub use encode::{Encode, EncodeFast};
27#[doc(hidden)]
28pub use header::{
29    HeaderDateCache, StaticHeader, StaticHeaderWriteFn, append_header_nanoseconds,
30    append_header_time,
31};
32#[doc(hidden)]
33pub use logger::{DecodeFn, StaticInfo, check_level, set_static_header};
34pub use logger::{
35    QueueFullCallback, QueueFullPolicy, flush_on, poll, queue_full_count, reset_queue_full_count,
36    set_flush_buffer_size, set_flush_delay, set_header_pattern, set_level, set_log_file,
37    set_log_file_with_rotation, set_output_writer, set_queue_full_callback, set_queue_full_policy,
38    start_polling_thread, start_polling_thread_on_core, stop_polling_thread,
39};
40pub use output::RotationConfig;
41#[doc(hidden)]
42pub use spsc_queue::{
43    PAYLOAD_ARGS_OFFSET, PAYLOAD_HEADER_SIZE, PAYLOAD_INFO_OFFSET, PAYLOAD_TIMESTAMP_OFFSET,
44};
45#[doc(hidden)]
46pub use thread_buffer::alloc_message;
47pub use thread_buffer::set_thread_name;
48#[doc(hidden)]
49pub use timestamp_counter::TimestampCounter;
50
51/// Log severity level.
52#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
53#[repr(u8)]
54pub enum Level {
55    /// Debug level.
56    DBG = 0,
57    /// Info level.
58    INF = 1,
59    /// Warning level.
60    WRN = 2,
61    /// Error level.
62    ERR = 3,
63    /// Logging disabled.
64    OFF = 4,
65}
66
67impl Level {
68    /// Returns the level name as a byte slice (e.g., `b"INF"`).
69    #[inline]
70    pub fn as_bytes(&self) -> &'static [u8] {
71        match self {
72            Level::DBG => b"DBG",
73            Level::INF => b"INF",
74            Level::WRN => b"WRN",
75            Level::ERR => b"ERR",
76            Level::OFF => b"OFF",
77        }
78    }
79}
80
81/// Converts a `u8` to a [`Level`]. Values outside the valid range map to [`Level::OFF`].
82#[inline]
83pub fn level_from_u8(value: u8) -> Level {
84    match value {
85        0 => Level::DBG,
86        1 => Level::INF,
87        2 => Level::WRN,
88        3 => Level::ERR,
89        _ => Level::OFF,
90    }
91}
92
93/// Shorthand constant for [`Level::DBG`].
94pub const DBG: Level = Level::DBG;
95/// Shorthand constant for [`Level::INF`].
96pub const INF: Level = Level::INF;
97/// Shorthand constant for [`Level::WRN`].
98pub const WRN: Level = Level::WRN;
99/// Shorthand constant for [`Level::ERR`].
100pub const ERR: Level = Level::ERR;
101/// Shorthand constant for [`Level::OFF`].
102pub const OFF: Level = Level::OFF;
103
104/// Alias for [`Level::DBG`].
105pub const DEBUG: Level = Level::DBG;
106/// Alias for [`Level::INF`].
107pub const INFO: Level = Level::INF;
108/// Alias for [`Level::WRN`].
109pub const WARN: Level = Level::WRN;
110/// Alias for [`Level::ERR`].
111pub const ERROR: Level = Level::ERR;