Skip to main content

kernel/kprint/
macros.rs

1// SPDX-License-Identifier: GPL-3.0-only
2//! Kernel print macros ([`kinfo!`](crate::kinfo), [`kdebug`](crate::kdebug), ...)
3//!
4//! Authors: MarioS271
5
6/// Internal kprint handler function
7#[inline(never)]
8pub fn __kprint(log_level: super::log_entry::LogLevel, args: core::fmt::Arguments<'_>) {
9    use super::log_entry::LogFlags;
10    use super::kernel_writer::KernelWriter;
11    use crate::state::kstate::KSTATE;
12
13    if KSTATE.kprint.config().max_log_level() >= log_level {
14        let mut w = KernelWriter::lock(
15            log_level,
16            LogFlags::NEWLINE
17        );
18        let _ = core::fmt::write(&mut w, args);
19    }
20}
21
22
23/// Log a line at emergency severity (system is unusable).
24#[macro_export]
25macro_rules! kemerg {
26    ($($arg:tt)*) => {
27        $crate::kprint::macros::__kprint($crate::kprint::log_entry::LogLevel::Emergency, format_args!($($arg)*));
28    };
29}
30
31/// Log a line at alert severity (action must be taken immediately).
32#[macro_export]
33macro_rules! kalert {
34    ($($arg:tt)*) => {
35        $crate::kprint::macros::__kprint($crate::kprint::log_entry::LogLevel::Alert, format_args!($($arg)*));
36    };
37}
38
39/// Log a line at critical severity.
40#[macro_export]
41macro_rules! kcrit {
42    ($($arg:tt)*) => {
43        $crate::kprint::macros::__kprint($crate::kprint::log_entry::LogLevel::Critical, format_args!($($arg)*));
44    };
45}
46
47/// Log a line at error severity.
48#[macro_export]
49macro_rules! kerror {
50    ($($arg:tt)*) => {
51        $crate::kprint::macros::__kprint($crate::kprint::log_entry::LogLevel::Error, format_args!($($arg)*));
52    };
53}
54
55/// Log a line at warning severity.
56#[macro_export]
57macro_rules! kwarn {
58    ($($arg:tt)*) => {
59        $crate::kprint::macros::__kprint($crate::kprint::log_entry::LogLevel::Warn, format_args!($($arg)*));
60    };
61}
62
63/// Log a line at notice severity.
64#[macro_export]
65macro_rules! knotice {
66    ($($arg:tt)*) => {
67        $crate::kprint::macros::__kprint($crate::kprint::log_entry::LogLevel::Notice, format_args!($($arg)*));
68    };
69}
70
71/// Log a line at info severity.
72#[macro_export]
73macro_rules! kinfo {
74    ($($arg:tt)*) => {
75        $crate::kprint::macros::__kprint($crate::kprint::log_entry::LogLevel::Info, format_args!($($arg)*));
76    };
77}
78
79/// Log a line at debug severity; compiled out unless the `debug-logging` feature is enabled.
80#[macro_export]
81macro_rules! kdebug {
82    ($($arg:tt)*) => {
83        {
84            #[cfg(feature = "debug-logging")]
85            $crate::kprint::macros::__kprint($crate::kprint::log_entry::LogLevel::Debug, format_args!($($arg)*));
86        };
87    };
88}