xref: /aosp_15_r20/external/pigweed/pw_log/rust/pw_log_backend_println.rs (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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)]
24 pub mod __private {
25     pub use pw_log_backend_println_macro::{_pw_log_backend, _pw_logf_backend};
26 
27     use pw_log_backend_api::LogLevel;
28 
log_level_tag(level: LogLevel) -> &'static str29     pub const fn log_level_tag(level: LogLevel) -> &'static str {
30         match level {
31             LogLevel::Debug => "DBG",
32             LogLevel::Info => "INF",
33             LogLevel::Warn => "WRN",
34             LogLevel::Error => "ERR",
35             LogLevel::Critical => "CRT",
36             LogLevel::Fatal => "FTL",
37         }
38     }
39 }
40 
41 // Implement the `pw_log` backend API.
42 #[macro_export]
43 macro_rules! pw_log_backend {
44   ($log_level:expr, $format_string:literal $(, $args:expr)* $(,)?) => {{
45     use $crate::__private as __pw_log_backend_crate;
46     $crate::__private::_pw_log_backend!($log_level, $format_string, $($args),*);
47   }};
48 }
49 
50 #[macro_export]
51 macro_rules! pw_logf_backend {
52   ($log_level:expr, $format_string:literal $(, $args:expr)* $(,)?) => {{
53     use $crate::__private as __pw_log_backend_crate;
54     $crate::__private::_pw_logf_backend!($log_level, $format_string, $($args),*);
55   }};
56 }
57