cortex_m_log/
lib.rs

1//! Logging facilities for Cortex-M processors
2//!
3//! ## Destinations
4//!
5//! The crate provides following destinations for writes:
6//! - [Dummy](destination/dummy/struct.Dummy.html) - noop destination that performs no writes. Useful for release mode
7//! - [Itm](destination/itm/struct.Itm.html) - Uses Cortex-M [Itm](https://docs.rs/cortex-m/0.5.1/cortex_m/itm/index.html) to send output. Note that it is available only on ARMv7-M and newer
8//! - [Semihosting](destination/semihosting/trait.SemihostingComp.html) - Uses Cortex-M [Semihosting](https://docs.rs/cortex-m-semihosting) to send output.
9//!
10//! All destinations implements [fmt::Write](https://doc.rust-lang.org/core/fmt/trait.Write.html)
11//! to provide simple and generic interface
12//!
13//! ## Printers
14//!
15//! Each destination is provided with corresponding [Printer](printer/trait.Printer.html).
16//! In addition to providing generic interface it also allows to configure Interrupt mode for all
17//! prints. [See](modes/index.html).
18//!
19//! ## Macros
20//!
21//! The crate provide primitieve macros that are enabled only in debug release.
22//! Controlled by `debug_assertions` attribute
23//!
24//! ```rust
25//! use cortex_m_log::{print, println, d_print, d_println};
26//! use cortex_m_log::printer::Dummy;
27//!
28//! fn main() {
29//!     let mut log = Dummy::new();
30//!     println!(log, "Some print with newline!");
31//!     //Debug version of print that resolves into nothing in release mode
32//!     //Note that you must import print macro for it to work
33//!     d_print!(log, "Print stuff: {}", "stuff");
34//!     //Note that you must import println macro for it to work
35//!     d_println!(log, "Print stuff: {} and also newline", "stuff");
36//! }
37//! ```
38
39#![no_std]
40#![warn(missing_docs)]
41#![cfg_attr(feature = "cargo-clippy", allow(clippy::style))]
42
43pub mod modes;
44pub mod destination;
45pub mod printer;
46#[cfg(feature = "log-integration")]
47pub mod log;
48
49///Print macro that uses Printers to write formatted output
50#[macro_export]
51macro_rules! print {
52    ($logger:expr, $($arg:tt)+) => ({
53        use $crate::printer::Printer;
54        $logger.print(format_args!($($arg)+));
55    })
56}
57
58///Print macro that uses Printers to write formatted output with newline
59#[macro_export]
60macro_rules! println {
61    ($logger:expr, $($arg:tt)+) => ({
62        use $crate::printer::Printer;
63        $logger.println(format_args!($($arg)+));
64    })
65}
66
67///Deubg print macro that uses Printers to write formatted output
68///
69///It is defined to empty macro unless `debug_assertions` is enabled
70#[macro_export]
71#[cfg(not(debug_assertions))]
72macro_rules! d_print {
73    ($logger:expr, $($arg:tt)+) => ({
74    })
75}
76
77///Deubg print macro that uses Printers to write formatted output
78///
79///It is defined to empty macro unless `debug_assertions` is enabled
80#[macro_export]
81#[cfg(debug_assertions)]
82macro_rules! d_print {
83    ($logger:expr, $($arg:tt)+) => ({
84        print!($logger, $($arg)+)
85    })
86}
87
88///Deubg print macro that uses Printers to write formatted output with newline
89///
90///It is defined to empty macro unless `debug_assertions` is enabled
91#[macro_export]
92#[cfg(not(debug_assertions))]
93macro_rules! d_println {
94    ($logger:expr, $($arg:tt)+) => ({
95    })
96}
97
98///Deubg print macro that uses Printers to write formatted output with newline
99///
100///It is defined to empty macro unless `debug_assertions` is enabled
101#[macro_export]
102#[cfg(debug_assertions)]
103macro_rules! d_println {
104    ($logger:expr, $($arg:tt)+) => ({
105        println!($logger, $($arg)+)
106    })
107}