Skip to content

Commit

Permalink
reduce logging levels (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
keepsimple1 authored Nov 30, 2024
1 parent 8042d94 commit 99483b7
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 134 deletions.
10 changes: 5 additions & 5 deletions src/dns_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This is an internal implementation, not visible to the public API.
#[cfg(feature = "logging")]
use crate::log::debug;
use crate::log::trace;
use crate::{
dns_parser::{
current_time_millis, split_sub_domain, DnsAddress, DnsPointer, DnsRecordBox, DnsSrv, RRType,
Expand Down Expand Up @@ -218,7 +218,7 @@ impl DnsCache {
}

if should_flush {
debug!("FLUSH one record: {:?}", &r);
trace!("FLUSH one record: {:?}", &r);
let new_expire = now + 1000;
r.set_expire(new_expire);

Expand Down Expand Up @@ -282,7 +282,7 @@ impl DnsCache {
let expired = addr.get_record().is_expired(now);
if expired {
if let Some(addr_record) = addr.any().downcast_ref::<DnsAddress>() {
debug!("evict expired ADDR: {:?}", addr_record);
trace!("evict expired ADDR: {:?}", addr_record);
removed
.entry(addr.get_name().to_string())
.or_insert_with(HashSet::new)
Expand Down Expand Up @@ -317,7 +317,7 @@ impl DnsCache {
srv_records.retain(|srv| {
let expired = srv.get_record().is_expired(now);
if expired {
debug!("expired SRV: {}: {:?}", ty_domain, srv);
trace!("expired SRV: {}: {:?}", ty_domain, srv);
expired_instances
.entry(ty_domain.to_string())
.or_insert_with(HashSet::new)
Expand All @@ -339,7 +339,7 @@ impl DnsCache {
let expired = x.get_record().is_expired(now);
if expired {
if let Some(dns_ptr) = x.any().downcast_ref::<DnsPointer>() {
debug!("expired PTR: domain:{ty_domain} record: {:?}", dns_ptr);
trace!("expired PTR: domain:{ty_domain} record: {:?}", dns_ptr);
expired_instances
.entry(ty_domain.to_string())
.or_insert_with(HashSet::new)
Expand Down
31 changes: 16 additions & 15 deletions src/dns_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! [DnsOutPacket] is the encoded one packet for [DnsOutgoing].
#[cfg(feature = "logging")]
use crate::log::debug;
use crate::log::trace;
use crate::{
service_info::{decode_txt, valid_ip_on_intf, DnsRegistry},
Error, Result, ServiceInfo,
Expand Down Expand Up @@ -248,9 +248,10 @@ impl DnsRecord {
return false;
}

debug!(
trace!(
"{} qtype {} is due to refresh",
&self.entry.name, self.entry.ty
&self.entry.name,
self.entry.ty
);

// From RFC 6762 section 5.2:
Expand Down Expand Up @@ -1252,7 +1253,7 @@ impl DnsOutgoing {

// o All address records (type "A" and "AAAA") named in the SRV rdata.
pub(crate) fn add_additional_answer(&mut self, answer: impl DnsRecordExt + 'static) {
debug!("add_additional_answer: {:?}", &answer);
trace!("add_additional_answer: {:?}", &answer);
self.additionals.push(Box::new(answer));
}

Expand All @@ -1272,9 +1273,9 @@ impl DnsOutgoing {
msg: &DnsIncoming,
answer: impl DnsRecordExt + Send + 'static,
) -> bool {
debug!("Check for add_answer");
trace!("Check for add_answer");
if answer.suppressed_by(msg) {
debug!("my answer is suppressed by incoming msg");
trace!("my answer is suppressed by incoming msg");
self.known_answer_count += 1;
return false;
}
Expand All @@ -1291,7 +1292,7 @@ impl DnsOutgoing {
now: u64,
) -> bool {
if now == 0 || !answer.get_record().is_expired(now) {
debug!("add_answer push: {:?}", &answer);
trace!("add_answer push: {:?}", &answer);
self.answers.push((Box::new(answer), now));
return true;
}
Expand All @@ -1313,7 +1314,7 @@ impl DnsOutgoing {
) {
let intf_addrs = service.get_addrs_on_intf(intf);
if intf_addrs.is_empty() {
debug!("No addrs on LAN of intf {:?}", intf);
trace!("No addrs on LAN of intf {:?}", intf);
return;
}

Expand All @@ -1340,12 +1341,12 @@ impl DnsOutgoing {
);

if !ptr_added {
debug!("answer was not added for msg {:?}", msg);
trace!("answer was not added for msg {:?}", msg);
return;
}

if let Some(sub) = service.get_subtype() {
debug!("Adding subdomain {}", sub);
trace!("Adding subdomain {}", sub);
self.add_additional_answer(DnsPointer::new(
sub,
RRType::PTR,
Expand Down Expand Up @@ -1560,7 +1561,7 @@ impl DnsIncoming {

self.offset = MSG_HEADER_LEN;

debug!(
trace!(
"read_header: id {}, {} questions {} answers {} authorities {} additionals",
self.id,
self.num_questions,
Expand All @@ -1572,7 +1573,7 @@ impl DnsIncoming {
}

fn read_questions(&mut self) -> Result<()> {
debug!("read_questions: {}", &self.num_questions);
trace!("read_questions: {}", &self.num_questions);
for i in 0..self.num_questions {
let name = self.read_name()?;

Expand Down Expand Up @@ -1619,7 +1620,7 @@ impl DnsIncoming {

/// Decodes a sequence of RR records (in answers, authorities and additionals).
fn read_rr_records(&mut self, count: u16) -> Result<Vec<DnsRecordBox>> {
debug!("read_rr_records: {}", count);
trace!("read_rr_records: {}", count);
let mut rr_records = Vec::new();

// RFC 1035: https://datatracker.ietf.org/doc/html/rfc1035#section-3.2.1
Expand Down Expand Up @@ -1746,10 +1747,10 @@ impl DnsIncoming {
};

if let Some(record) = rec {
debug!("read_rr_records: {:?}", &record);
trace!("read_rr_records: {:?}", &record);
rr_records.push(record);
} else {
debug!("Unsupported DNS record type: {} name: {}", ty, &name);
trace!("Unsupported DNS record type: {} name: {}", ty, &name);
self.offset += rdata_len;
}

Expand Down
Loading

0 comments on commit 99483b7

Please sign in to comment.