Skip to main content

ferroui_android/
log.rs

1//! The log of the system.
2//!
3//! The standard output and the standard error of an Android process go
4//! nowhere, so what an application wants read (a panic, the lines of a
5//! smoke run) is written to the log of the system, which `logcat` shows.
6//! Not from the reference, whose runtime routes its traces there by itself.
7//! An application routes the log of the framework here with
8//! `AppBuilder::log_to_delegate`.
9
10/// The tag the backend writes its own lines under.
11pub const TAG: &str = "ferroui";
12
13/// The priorities of the log of the system (`android_LogPriority`).
14#[derive(Clone, Copy, Debug, PartialEq, Eq)]
15#[repr(i32)]
16pub enum LogPriority {
17    Verbose = 2,
18    Debug = 3,
19    Info = 4,
20    Warn = 5,
21    Error = 6,
22    Fatal = 7,
23}
24
25/// Writes a line to the log of the system under `tag`. On another system
26/// than Android the line goes to the standard error.
27pub fn write(priority: LogPriority, tag: &str, message: &str) {
28    #[cfg(target_os = "android")]
29    crate::interop::ndk::log_write(priority, tag, message);
30    #[cfg(not(target_os = "android"))]
31    eprintln!("{priority:?}/{tag}: {message}");
32}
33
34/// Writes an informational line under the tag of the backend.
35pub fn info(message: &str) {
36    write(LogPriority::Info, TAG, message);
37}
38
39/// Writes an error line under the tag of the backend.
40pub fn error(message: &str) {
41    write(LogPriority::Error, TAG, message);
42}