mirror of
https://github.com/msfjarvis/clipboard-substitutor
synced 2025-08-14 17:47:02 +05:30
feat(logging): add a journald feature to log to systemd
This commit is contained in:
parent
28fa08a67b
commit
139e833d04
3 changed files with 26 additions and 0 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -93,6 +93,7 @@ dependencies = [
|
|||
"serde_derive",
|
||||
"toml",
|
||||
"tracing",
|
||||
"tracing-journald",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
|
@ -510,6 +511,17 @@ dependencies = [
|
|||
"valuable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-journald"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36a63bcca9cab23195673d7c3c7db8aff5fc062b82cd1e51c396d9dc26968c3c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"tracing-core",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.1.2"
|
||||
|
|
|
@ -20,7 +20,11 @@ serde = "1.0.136"
|
|||
serde_derive = "1.0.136"
|
||||
toml = "0.5.8"
|
||||
tracing = "0.1.32"
|
||||
tracing-journald = { version = "0.2.3", optional = true }
|
||||
tracing-subscriber = { version = "0.3.9", features = ["env-filter"] }
|
||||
|
||||
[dev-dependencies]
|
||||
assay = "0.1.1"
|
||||
|
||||
[features]
|
||||
journald = ["tracing-journald"]
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -10,6 +10,8 @@ use anyhow::{anyhow, Result};
|
|||
use clipboard::{ClipboardContext, ClipboardProvider};
|
||||
use dirs::config_dir;
|
||||
use tracing::{debug, error, Level};
|
||||
#[cfg(journald)]
|
||||
use tracing_journald::Subscriber;
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
|
||||
use crate::config::{Act, Match, Replacements};
|
||||
|
@ -47,6 +49,7 @@ fn print_version() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(not(journald))]
|
||||
fn configure_tracing() {
|
||||
let subscriber = FmtSubscriber::builder()
|
||||
.with_max_level(Level::TRACE)
|
||||
|
@ -56,6 +59,13 @@ fn configure_tracing() {
|
|||
.expect("setting default subscriber failed");
|
||||
}
|
||||
|
||||
#[cfg(journald)]
|
||||
fn configure_tracing() {
|
||||
let sub = Registry::default()
|
||||
.with(Subscriber::new().unwrap().with_field_prefix(None));
|
||||
tracing::collect::with_default(sub, f);
|
||||
}
|
||||
|
||||
fn get_config_path() -> Result<PathBuf> {
|
||||
let mut config_path =
|
||||
config_dir().ok_or_else(|| anyhow!("Failed to get config dir"))?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue