| Crates.io | rustler_logger |
| lib.rs | rustler_logger |
| version | 0.4.3 |
| created_at | 2026-01-15 12:16:36.285676+00 |
| updated_at | 2026-01-15 17:02:22.838431+00 |
| description | log from Rustler NIFs to Elixir's Logger |
| homepage | https://github.com/jvantuyl/rustler_logger |
| repository | https://github.com/jvantuyl/rustler_logger |
| max_upload_size | |
| id | 2045455 |
| size | 38,615 |
rustler provides fairly seamless integration between Rust and Elixir.
However, Rust NIFs aren't really integrated with Elixir's logging infrastructure.
This crate provides a set of macros that can be used to log messages directly to the Elixir logger.
log_to_elixir attribute macro that wraps functions with code that captures the Elixir environment to send logslog! macro to actually emit log messagesdebug!, info!, etc.)use rustler::{nif, Env, Term};
use rustler_logger::*;
#[nif]
#[log_to_elixir]
fn show_off_logging() {
info!(
"Hello, ~p! ~p items on your list labeled ~p", // erlang-style format string
"world", 42, "TODO", // format arguments
user="bob", answer=420/10 // metadata
);
// all of the log levels
debug!("convenience");
info!("macros");
notice!("for");
warn!("each");
error!("log");
critical!("level");
alert!("are");
emergency!("available");
// If you need to select a level programmatically, you can use the `log!`
// macro with a level argument.
let log_level = LogLevel::Debug;
log!(log_level, "This is a {} message", log_level.as_str());
}
// This is necessary to load the panic hook.
fn load(_env: Env, _term: Term) -> bool {
log_init();
true
}
rustler::init!("Elixir.Your.Module", load = load);
Failing to initialize the logger can cause panic messages to not be emitted.
Failing to wrap functions with log_to_elixir can cause log messages to not be emitted.