[−][src]Module fluence_sdk_main::logger
This module enables log messages from the Wasm side. Internally this module can be viewed as a
client for the Logger Module of Asmble. Logger module provides methods that can print out
logs to stdout (destination can differ and really depends only on WasmVm implementation).
This module is implemented as a logging facade for crate log. To enable this module in
your project please specify wasm_logger feature of fluence_sdk.
Note that this module works only for the Wasm environment and Fluence WasmVm - by specifying
this feature it is possible to compile application for the wasm32-unknown-unknown target.
(please refer to the first example to find out a way to avoid it).
The logging ability is disabled in WasmVm by default so this feature should be used only for
debugging purposes. Please refer to backend app debugging section of the Fluence book to find
more information about it.
Examples
This example initializes WasmLogger if target arch is Wasm and simple_logger otherwise.
Macroses from crate log used as a logging facade.
use fluence::sdk::*;
use log::{error, trace};
use simple_logger;
fn main() {
if cfg!(target_arch = "wasm32") {
logger::WasmLogger::init_with_level(log::Level::Info).unwrap();
} else {
simple_logger::init_with_level(log::Level::Info).unwrap();
}
error!("This message will be logged.");
trace!("This message will not be logged.");
}
This example provides method for initialization WasmLogger only for Wasm target without
specifying logger level:
use fluence::sdk::*;
use log::info;
/// This method initializes WasmLogger and should be called at the start of the application.
#[no_mangle]
#[cfg(target_arch = "wasm32")]
fn init_logger() {
logger::WasmLogger::init().unwrap();
info!("If you can see this message that logger was successfully initialized.");
}
Structs
| WasmLogger | The Wasm Logger. |