mirror of
https://github.com/msfjarvis/clipboard-substitutor
synced 2025-08-14 22:27:03 +05:30
refactor(logging): extract tracing infrastructure to its own module
This commit is contained in:
parent
f9ce850414
commit
26b0b06759
2 changed files with 38 additions and 27 deletions
32
src/main.rs
32
src/main.rs
|
@ -1,11 +1,12 @@
|
|||
mod clipboard;
|
||||
mod config;
|
||||
mod logging;
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use dirs::config_dir;
|
||||
use tracing::debug;
|
||||
|
||||
|
@ -16,7 +17,9 @@ fn main() -> Result<()> {
|
|||
if check_for_version_arg() {
|
||||
return Ok(());
|
||||
}
|
||||
configure_tracing();
|
||||
if let Err(e) = logging::init() {
|
||||
bail!(e)
|
||||
};
|
||||
let config_path = get_config_path()?;
|
||||
let config_str =
|
||||
std::fs::read_to_string(config_path.as_path()).unwrap_or_default();
|
||||
|
@ -42,31 +45,6 @@ fn print_version() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "journald"))]
|
||||
fn configure_tracing() {
|
||||
use tracing::Level;
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
|
||||
let subscriber = FmtSubscriber::builder()
|
||||
.with_max_level(Level::TRACE)
|
||||
.finish();
|
||||
|
||||
tracing::subscriber::set_global_default(subscriber)
|
||||
.expect("setting default subscriber failed");
|
||||
}
|
||||
|
||||
#[cfg(feature = "journald")]
|
||||
fn configure_tracing() {
|
||||
use tracing_journald::Layer;
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::Registry;
|
||||
|
||||
let subscriber =
|
||||
Registry::default().with(Layer::new().unwrap().with_field_prefix(None));
|
||||
tracing::subscriber::set_global_default(subscriber)
|
||||
.expect("setting default subscriber failed");
|
||||
}
|
||||
|
||||
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