mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2025-07-17 14:33:27 +02:00
Use the log create instead of println
This commit is contained in:
13
src/geoip.rs
13
src/geoip.rs
@ -3,6 +3,7 @@
|
||||
* that provides the results ready for templating.
|
||||
*/
|
||||
|
||||
use log::{info,warn,error};
|
||||
use maxminddb;
|
||||
use maxminddb::geoip2;
|
||||
|
||||
@ -136,7 +137,7 @@ impl QueryAsn for MMDBCarrier {
|
||||
})
|
||||
},
|
||||
Err(e) => {
|
||||
println!("Error while looking up ASN for {address}: {e}");
|
||||
error!("Error while looking up ASN for {address}: {e}");
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
@ -204,7 +205,7 @@ impl QueryLocation for MMDBCarrier {
|
||||
})
|
||||
},
|
||||
Err(e) => {
|
||||
println!("Error while looking up ASN for {address}: {e}");
|
||||
error!("Error while looking up ASN for {address}: {e}");
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
@ -232,7 +233,7 @@ impl MMDBCarrier {
|
||||
|
||||
pub fn load_database_from_path(&self, path: &Path) -> Result<(),maxminddb::MaxMindDBError> {
|
||||
let mut mmdb = self.mmdb.write();
|
||||
println!("Loading {} from '{}' ...", &self.name, path.display());
|
||||
info!("Loading {} from '{}' ...", &self.name, path.display());
|
||||
match maxminddb::Reader::open_readfile(path) {
|
||||
Ok(reader) => {
|
||||
let wording = if mmdb.is_some() {
|
||||
@ -241,13 +242,13 @@ impl MMDBCarrier {
|
||||
"Loaded new"
|
||||
};
|
||||
*mmdb = Some(reader);
|
||||
println!("{} {} with new one.", wording, &self.name);
|
||||
info!("{} {} with new one.", wording, &self.name);
|
||||
Ok(())
|
||||
},
|
||||
Err(e) => {
|
||||
println!("Error while reading {}: {}", &self.name, &e);
|
||||
error!("Error while reading {}: {}", &self.name, &e);
|
||||
if mmdb.is_some() {
|
||||
println!("Not replacing old database.");
|
||||
warn!("Not replacing old database.");
|
||||
}
|
||||
Err(e)
|
||||
},
|
||||
|
42
src/main.rs
42
src/main.rs
@ -17,12 +17,14 @@ use axum_client_ip::SecureClientIp;
|
||||
use axum_extra::headers;
|
||||
use axum_extra::TypedHeader;
|
||||
use clap::Parser;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize,Serialize};
|
||||
use tower::ServiceBuilder;
|
||||
use tower_http::services::ServeDir;
|
||||
use env_logger::Env;
|
||||
use hickory_resolver::Name;
|
||||
use hickory_resolver::TokioAsyncResolver;
|
||||
use log::{info,warn,error};
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize,Serialize};
|
||||
use tower_http::services::ServeDir;
|
||||
use tower::ServiceBuilder;
|
||||
|
||||
use tokio::signal::unix::{
|
||||
signal,
|
||||
@ -143,6 +145,10 @@ fn match_domain_hidden_list(domain: &String, hidden_list: &Vec<String>) -> bool
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
||||
// Initalize logger:
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||
|
||||
// Parse Command line arguments
|
||||
let cli_args = CliArgs::parse();
|
||||
|
||||
@ -152,9 +158,9 @@ async fn main() {
|
||||
match read_toml_from_file::<config::EchoIpServiceConfig>(&config_path) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
println!("Could not read confuration file!");
|
||||
println!("{e}");
|
||||
println!("Exiting ...");
|
||||
error!("Could not read confuration file!");
|
||||
error!("{e}");
|
||||
error!("Exiting ...");
|
||||
::std::process::exit(1);
|
||||
}
|
||||
}
|
||||
@ -174,7 +180,7 @@ async fn main() {
|
||||
let templating_engine = match template_loader.load_templates() {
|
||||
Ok(t) => t.into(),
|
||||
Err(e) => {
|
||||
println!("{e}");
|
||||
error!("{e}");
|
||||
::std::process::exit(1);
|
||||
}
|
||||
};
|
||||
@ -183,7 +189,7 @@ async fn main() {
|
||||
|
||||
let static_file_directory = template_loader.base_dir()+"/static";
|
||||
|
||||
println!("Static files will be served from: {static_file_directory}");
|
||||
info!("Static files will be served from: {static_file_directory}");
|
||||
|
||||
// Initalize GeoIP Database
|
||||
|
||||
@ -202,19 +208,19 @@ async fn main() {
|
||||
location_db.reload_database().ok();
|
||||
|
||||
// Initalize DNS resolver with os defaults
|
||||
println!("Initalizing dns resolvers ...");
|
||||
info!("Initalizing dns resolvers ...");
|
||||
|
||||
let mut dns_resolver_selectables = Vec::<Selectable>::new();
|
||||
let mut dns_resolver_map: HashMap<Arc<str>,TokioAsyncResolver> = HashMap::new();
|
||||
let mut dns_resolver_aliases: HashMap<Arc<str>,Arc<str>> = HashMap::new();
|
||||
|
||||
if config.dns.enable_system_resolver {
|
||||
println!("Initalizing System resolver ...");
|
||||
info!("Initalizing System resolver ...");
|
||||
let res = TokioAsyncResolver::tokio_from_system_conf();
|
||||
let resolver = match res {
|
||||
Ok(resolver) => resolver,
|
||||
Err(e) => {
|
||||
println!("Error while setting up dns resolver: {e}");
|
||||
info!("Error while setting up dns resolver: {e}");
|
||||
::std::process::exit(1);
|
||||
}
|
||||
};
|
||||
@ -228,7 +234,7 @@ async fn main() {
|
||||
}
|
||||
|
||||
for (key, resolver_config) in &config.dns.resolver {
|
||||
println!("Initalizing {} resolver ...", key);
|
||||
info!("Initalizing {} resolver ...", key);
|
||||
let resolver = TokioAsyncResolver::tokio(
|
||||
resolver_config.to_hickory_resolver_config(),
|
||||
Default::default()
|
||||
@ -270,18 +276,18 @@ async fn main() {
|
||||
let signal_usr1_handlers_state = shared_state.clone();
|
||||
|
||||
task::spawn(async move {
|
||||
println!("Trying to register USR1 signal for reloading geoip databases");
|
||||
info!("Trying to register USR1 signal for reloading geoip databases");
|
||||
let mut signal_stream = match signal(SignalKind::user_defined1()) {
|
||||
Ok(signal_stream) => signal_stream,
|
||||
Err(e) => {
|
||||
println!("Error while registring signal handler: {e}");
|
||||
println!("Continuing without ...");
|
||||
error!("Error while registring signal handler: {e}");
|
||||
warn!("Continuing without geoip reaload signal ...");
|
||||
return;
|
||||
}
|
||||
};
|
||||
loop {
|
||||
if None == signal_stream.recv().await { return; }
|
||||
println!("Received signal USR1, reloading geoip databses!");
|
||||
info!("Received signal USR1, reloading geoip databses!");
|
||||
signal_usr1_handlers_state.location_db.reload_database().ok();
|
||||
signal_usr1_handlers_state.asn_db.reload_database().ok();
|
||||
}
|
||||
@ -313,7 +319,7 @@ async fn main() {
|
||||
)
|
||||
;
|
||||
|
||||
println!("Starting Server on {} ...",listen_on);
|
||||
info!("Starting Server on {} ...",listen_on);
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(&listen_on).await.unwrap();
|
||||
axum::serve(listener, app.into_make_service_with_connect_info::<std::net::SocketAddr>())
|
||||
|
@ -18,6 +18,7 @@ use governor::{
|
||||
RateLimiter,
|
||||
state::keyed::DefaultKeyedStateStore,
|
||||
};
|
||||
use log::debug;
|
||||
|
||||
use std::net::IpAddr;
|
||||
use std::num::NonZeroU32;
|
||||
@ -55,10 +56,10 @@ pub async fn rate_limit_middleware(
|
||||
if limiter.check_key(&IpAddr::V4(std::net::Ipv4Addr::UNSPECIFIED)).is_ok() {
|
||||
let oldlen = limiter.len();
|
||||
if oldlen > 100 {
|
||||
println!("Doing limiter cleanup ...");
|
||||
debug!("Doing limiter cleanup ...");
|
||||
limiter.retain_recent();
|
||||
limiter.shrink_to_fit();
|
||||
println!("Old limiter store size: {oldlen} New limiter store size: {}", limiter.len());
|
||||
debug!("Old limiter store size: {oldlen} New limiter store size: {}", limiter.len());
|
||||
}
|
||||
}
|
||||
next.run(req).await
|
||||
|
@ -17,6 +17,7 @@ use hickory_resolver::{
|
||||
Name,
|
||||
TokioAsyncResolver,
|
||||
};
|
||||
use log::{warn,error};
|
||||
|
||||
use tokio::join;
|
||||
|
||||
@ -91,7 +92,7 @@ pub async fn reverse_lookup(
|
||||
//Ignore, that just happens …
|
||||
}
|
||||
_ => {
|
||||
println!("Reverse lookup on {address} failed: {kind}");
|
||||
error!("Reverse lookup on {address} failed: {kind}");
|
||||
}
|
||||
}
|
||||
None
|
||||
@ -153,7 +154,9 @@ pub fn add_record_to_lookup_result(result: &mut DnsLookupResult, record: &RData)
|
||||
);
|
||||
}
|
||||
},
|
||||
_ => { println!("Tried to add an unkown DNS record to results: {record}"); },
|
||||
_ => {
|
||||
warn!("Tried to add an unkown DNS record to results: {record}");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,18 +194,18 @@ pub fn integrate_lookup_result(dig_result: &mut DnsLookupResult, lookup_result:
|
||||
ResolveErrorKind::Io(..) |
|
||||
ResolveErrorKind::Proto(..) => {
|
||||
dig_result.other_error = true;
|
||||
println!("There was an error while doing a DNS Lookup: {e}");
|
||||
error!("There was an error while doing a DNS Lookup: {e}");
|
||||
},
|
||||
ResolveErrorKind::Timeout => {
|
||||
dig_result.timeout = true;
|
||||
println!("There was a timeout while doing a DNS Lookup.");
|
||||
warn!("There was a timeout while doing a DNS Lookup.");
|
||||
},
|
||||
ResolveErrorKind::NoRecordsFound{response_code, ..} => {
|
||||
match response_code {
|
||||
ResponseCode::NXDomain => dig_result.nxdomain = true,
|
||||
ResponseCode::NoError => {},
|
||||
_ => {
|
||||
println!("The DNS Server returned an error while doing a DNS Lookup: {response_code}");
|
||||
error!("The DNS Server returned an error while doing a DNS Lookup: {response_code}");
|
||||
dig_result.dns_error = true;
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user