Changed logging in DNS-server.

This commit is contained in:
Revertron
2021-02-25 14:14:25 +01:00
parent e75bbf21cc
commit 6a3d7c6ab6
+11 -10
View File
@@ -11,6 +11,7 @@ use std::thread::Builder;
use derive_more::{Display, Error, From}; use derive_more::{Display, Error, From};
use rand::random; use rand::random;
use log::{error, warn, debug};
use crate::dns::buffer::{BytePacketBuffer, PacketBuffer, StreamPacketBuffer, VectorPacketBuffer}; use crate::dns::buffer::{BytePacketBuffer, PacketBuffer, StreamPacketBuffer, VectorPacketBuffer};
use crate::dns::context::ServerContext; use crate::dns::context::ServerContext;
@@ -30,7 +31,7 @@ macro_rules! return_or_report {
match $x { match $x {
Ok(res) => res, Ok(res) => res,
Err(_) => { Err(_) => {
println!($message); debug!($message);
return; return;
} }
} }
@@ -42,7 +43,7 @@ macro_rules! ignore_or_report {
match $x { match $x {
Ok(_) => {} Ok(_) => {}
Err(_) => { Err(_) => {
println!($message); debug!($message);
return; return;
} }
}; };
@@ -123,7 +124,7 @@ pub fn execute_query(context: Arc<ServerContext>, request: &DnsPacket) -> DnsPac
rescode rescode
} }
Err(err) => { Err(err) => {
println!("Failed to resolve {:?} {}: {:?}", question.qtype, question.name, err); error!("Failed to resolve {:?} {}: {:?}", question.qtype, question.name, err);
ResultCode::SERVFAIL ResultCode::SERVFAIL
} }
}; };
@@ -182,7 +183,7 @@ impl DnsServer for DnsUdpServer {
let socket_clone = match socket.try_clone() { let socket_clone = match socket.try_clone() {
Ok(x) => x, Ok(x) => x,
Err(e) => { Err(e) => {
println!("Failed to clone socket when starting UDP server: {:?}", e); warn!("Failed to clone socket when starting UDP server: {:?}", e);
continue; continue;
} }
}; };
@@ -204,7 +205,7 @@ impl DnsServer for DnsUdpServer {
{ {
Some(x) => x, Some(x) => x,
None => { None => {
println!("Not expected to happen!"); debug!("Not expected to happen!");
continue; continue;
} }
}; };
@@ -244,7 +245,7 @@ impl DnsServer for DnsUdpServer {
let (_, src) = match socket.recv_from(&mut req_buffer.buf) { let (_, src) = match socket.recv_from(&mut req_buffer.buf) {
Ok(x) => x, Ok(x) => x,
Err(e) => { Err(e) => {
println!("Failed to read from UDP socket: {:?}", e); debug!("Failed to read from UDP socket: {:?}", e);
continue; continue;
} }
}; };
@@ -253,7 +254,7 @@ impl DnsServer for DnsUdpServer {
let request = match DnsPacket::from_buffer(&mut req_buffer) { let request = match DnsPacket::from_buffer(&mut req_buffer) {
Ok(x) => x, Ok(x) => x,
Err(e) => { Err(e) => {
println!("Failed to parse UDP query packet: {:?}", e); debug!("Failed to parse UDP query packet: {:?}", e);
continue; continue;
} }
}; };
@@ -265,7 +266,7 @@ impl DnsServer for DnsUdpServer {
self.request_cond.notify_one(); self.request_cond.notify_one();
} }
Err(e) => { Err(e) => {
println!("Failed to send UDP request for processing: {}", e); debug!("Failed to send UDP request for processing: {}", e);
} }
} }
} }
@@ -346,7 +347,7 @@ impl DnsServer for DnsTcpServer {
let stream = match wrap_stream { let stream = match wrap_stream {
Ok(stream) => stream, Ok(stream) => stream,
Err(err) => { Err(err) => {
println!("Failed to accept TCP connection: {:?}", err); warn!("Failed to accept TCP connection: {:?}", err);
continue; continue;
} }
}; };
@@ -356,7 +357,7 @@ impl DnsServer for DnsTcpServer {
match self.senders[thread_no].send(stream) { match self.senders[thread_no].send(stream) {
Ok(_) => {} Ok(_) => {}
Err(e) => { Err(e) => {
println!("Failed to send TCP request for processing on thread {}: {}", thread_no, e); warn!("Failed to send TCP request for processing on thread {}: {}", thread_no, e);
} }
} }
} }