pw_log_backend/
pw_log_backend_println.rs

1// Copyright 2023 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15//! `pw_log` backend that calls [`std::println!`] to emit log messages.  This
16//! module is useful when you have an application or test running on the
17//! development host and you want messages to be emitted to `stdout`.
18//!
19//! *Note*: This modules requires `std`.
20//!
21//! TODO: <pwbug.dev/311232605> - Document how to configure facade backends.
22
23#[doc(hidden)]
24pub mod __private {
25    use pw_log_backend_api::LogLevel;
26    pub use pw_log_backend_println_macro::{_pw_log_backend, _pw_logf_backend};
27
28    pub const fn log_level_tag(level: LogLevel) -> &'static str {
29        match level {
30            LogLevel::Debug => "DBG",
31            LogLevel::Info => "INF",
32            LogLevel::Warn => "WRN",
33            LogLevel::Error => "ERR",
34            LogLevel::Critical => "CRT",
35            LogLevel::Fatal => "FTL",
36        }
37    }
38}
39
40// Implement the `pw_log` backend API.
41#[macro_export]
42macro_rules! pw_log_backend {
43  ($log_level:expr, $format_string:literal $(, $args:expr)* $(,)?) => {{
44    use $crate::__private as __pw_log_backend_crate;
45    $crate::__private::_pw_log_backend!($log_level, $format_string, $($args),*);
46  }};
47}
48
49#[macro_export]
50macro_rules! pw_logf_backend {
51  ($log_level:expr, $format_string:literal $(, $args:expr)* $(,)?) => {{
52    use $crate::__private as __pw_log_backend_crate;
53    $crate::__private::_pw_logf_backend!($log_level, $format_string, $($args),*);
54  }};
55}