-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement proper logging instead of using println!() everywhere
- Loading branch information
Showing
7 changed files
with
133 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-FileCopyrightText: 2024 Luflosi <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
use env_logger::{Builder, Env}; | ||
use std::io::Write; | ||
|
||
pub fn setup() { | ||
let env = Env::default().filter_or("RUST_LOG", "dyndnsd=info"); | ||
|
||
match std::env::var("RUST_LOG_STYLE") { | ||
Ok(s) if s == "SYSTEMD" => Builder::from_env(env) | ||
.format(|buf, record| { | ||
for line in record.args().to_string().lines() { | ||
writeln!( | ||
buf, | ||
"<{}>{}: {}", | ||
match record.level() { | ||
log::Level::Error => 3, | ||
log::Level::Warn => 4, | ||
log::Level::Info => 6, | ||
log::Level::Debug | log::Level::Trace => 7, | ||
}, | ||
record.target(), | ||
line | ||
)?; | ||
} | ||
Ok(()) | ||
}) | ||
.init(), | ||
_ => env_logger::init_from_env(env), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
// SPDX-FileCopyrightText: 2024 Luflosi <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
mod config; | ||
mod logging; | ||
mod process; | ||
|
||
#[macro_use] | ||
extern crate error_chain; | ||
|
||
use crate::config::Config; | ||
use crate::process::{update, QueryParameters}; | ||
use clap::Parser; | ||
use log::{error, info}; | ||
use warp::Filter; | ||
|
||
mod config; | ||
mod process; | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(version)] | ||
struct Args { | ||
|
@@ -22,16 +24,18 @@ struct Args { | |
|
||
#[tokio::main] | ||
async fn main() { | ||
logging::setup(); | ||
|
||
let args = Args::parse(); | ||
|
||
let config = match Config::read(&args.config) { | ||
Ok(v) => v, | ||
Err(e) => { | ||
eprintln!("ERROR: {e}"); | ||
error!("ERROR: {e}"); | ||
|
||
/////// look at the chain of errors... /////// | ||
for e in e.iter().skip(1) { | ||
eprintln!("caused by: {e}"); | ||
error!("caused by: {e}"); | ||
} | ||
|
||
std::process::exit(1); | ||
|
@@ -45,6 +49,6 @@ async fn main() { | |
.and(warp::query::<QueryParameters>()) | ||
.map(move |q: QueryParameters| update(&config, &q)); | ||
|
||
println!("Listening on {listen}"); | ||
info!("Listening on {listen}"); | ||
warp::serve(update).run(listen).await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters