rmesg
A 'dmesg' implementation in Rust
As a command-line utility
) )
)
As a Crate
This mainly serves as a crate, but if compiled, will become a simple executable that will dump kernel log buffer contents onto the console.
The value of this is programmatic access to kernel buffer from Rust
programs, and a Rust-based klogctl
implementation.
Depend on the rmesg crate
Include it in Cargo.toml:
[]
= "0.6.0"
Reading the entire buffer as a string
To read the kernel message buffer as a String (the string will have line-breaks you'll have to make sense of):
use rmesg;
let log_result = rmesg;
assert!;
let logs = log_result.unwrap;
assert!;
The parameter sole bool parameter tells the rmesg call whether to clear the buffer when read, or to preserve it. When preserved, subsequent calls will get repeated lines. In order to read line-by-line without clearing the buffer, use the second method described below.
Reading the buffer line-by-line
However must useful is being able to read the kernel logs line-by-line:
use ;
// Enable timestamps in kernel log lines if not already enabled - otherwise the iterator will
// ignore all lines and get stuck.
let enable_timestamp_result = kernel_log_timestamps_enable;
assert!;
// Don't clear the buffer. Poll every second.
let iterator_result = with_options;
assert!;
let iterator = iterator_result.unwrap;
for line in iterator