https://github.com/starryinternet/systemd-journal
Rust Bindings to Systemd's sd-journal APIs
https://github.com/starryinternet/systemd-journal
Last synced: about 1 year ago
JSON representation
Rust Bindings to Systemd's sd-journal APIs
- Host: GitHub
- URL: https://github.com/starryinternet/systemd-journal
- Owner: StarryInternet
- License: mit
- Created: 2020-10-13T19:39:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-10T21:45:53.000Z (over 5 years ago)
- Last Synced: 2025-02-05T09:38:58.111Z (over 1 year ago)
- Language: Rust
- Size: 23.4 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `systemd-journal`
A simple, zero-dependency crate for working with Systemd's
`sd_journal` API's.
## Code examples
`systemd_journal` provides an interface to the Systemd journal through
the `Journal` type.
```rust
let jrn = systemd_journal::Journal::new();
systemd_journal::info!(jrn, "Hello, world!")?;
if let Err(err) = something::dangerous() {
systemd_journal::error!(jrn, "Oops: {}", err)?;
}
let mut reader = jrn.read()?;
if let Some(mut entry) = reader.next()? {
if let Some(message) = entry.get("MESSAGE")? {
println!("First journal entry: {:?}", String::from_utf8_lossy(message));
}
}
```
## Integration with `log`
`systemd_journal` can be used to set up the global logger for the
popular [log][docs_log] crate.
[docs_log]: https://docs.rs/crate/log
```rust
fn main() {
systemd_journal::init_logger();
log::info!("Hello, world!");
}
```
Note: this requires enabling the `"log"` feature in `Cargo.toml`:
```toml
[dependencies.systemd-journal]
version = "0.1"
features = ["log"]
```
# License
This project is licensed under the MIT license (see the `LICENSE` file).