rmesg
A 'dmesg' implementation in Rust
As a command-line utility
Cargo Install
Usage
) )
)
)
As a Crate
The real value of this crate is programmatic access to kernel buffer from Rust
programs, allowing a dmesg
that can be consumed programmatically.
The complete API can be found in the main.rs
file which uses the sync/async versions of the APIs, both single-shot and iterative.
Depend on the rmesg crate
Include it in Cargo.toml:
[]
= "1.0.0"
Suppots two features:
async
- Exposes asynchronous Stream APIsync
- Exposes synchronous Iterator API
Reading the buffer single-shot (non-blocking)
NOTE: Reading single-shot is the same interface for sync or async
use rmesg;
// Read all logs as one big string with line-breaks
let raw = logs_raw.unwrap;
print!
// Read logs as a Vec of Entry'ies (`Vec<Entry>`)
// and can be processed entry-by-entry
let entries = log_entries.unwrap;
for entry in entries
Indefinitely iterating
With feature sync
(i.e. synchronous), provides an Iterator over Result<Entry, RMesgError>.
use rmesg;
let entries = logs_iter?;
for maybe_entry in entries
With feature async
(i.e. asynchronous), provides a Stream over Result<Entry, RMesgError>.
use rmesg;
// given that it's a stream over Result's, use the conveniences provided to us
use TryStreamExt;
let mut entries = logs_iter.await?;
while let Some = entries.try_next.await?