1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! A simple example demonstrating logging with `EspIdfLogger`
//! Uncomment one of the options and comment all the others to see how it operates
use log::info;
fn main() {
esp_idf_svc::sys::link_patches();
//
// Option 1
//
// Easiest option: initialize the `log` crate with a hard-coded log level and with `EspIdfLogger`
// esp_idf_svc::log::init(::log::LevelFilter::Info);
//
// Option 2
//
// This is the same as the above, but uses a `RUST_LOG` environment variable to set the log level
// If this environment variable is not set, it defaults to `Info`
esp_idf_svc::log::init_from_env();
//
// Option 3
//
// A third option is to initialize the logger in a way where its log level is controlled
// by the ESP-IDF log configuration
//
// This way both C and Rust logs are controlled by the same configuration in `sdkconfig.defaults`,
// but this is not always desired, hence the above options
// esp_idf_svc::log::init_from_esp_idf();
// This is equivalent to `init_from_esp_idf()` and only kept for backwards compatibility
// esp_idf_svc::log::EspLogger::initialize_default();
//
// Option 4
//
// You can also do it all in a custom way
// static LOGGER: esp_idf_svc::log::EspIdfLogger<()> = esp_idf_svc::log::EspIdfLogger::new(()); // You can pass your own log filter too
// use esp_idf_svc::log::LogFilterBackend;
// ::log::set_logger(&LOGGER)
// .map(|()| LOGGER.filter().initialize())
// .unwrap();
// ::log::set_max_level(::log::LevelFilter::Debug);
info!("Hello, world! This is a logging example using `EspIdfLogger`.");
}