Skip to content
Permalink
Browse files

Use Slf4j for logs

Closes #72
  • Loading branch information...
ibauersachs committed Sep 2, 2019
1 parent 512b61a commit 9de972d76615b012bdba240fd98434a7f58e12c7
11 pom.xml
@@ -198,6 +198,17 @@
</build>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.28</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
@@ -9,6 +9,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;

/**
* A cache of DNS records. The cache obeys TTLs, so items are purged after their validity period is
@@ -20,6 +21,7 @@
* @see Credibility
* @author Brian Wellington
*/
@Slf4j
public class Cache {

private interface Element {
@@ -604,7 +606,6 @@ public SetResponse addMessage(Message in) {
boolean completed = false;
RRset[] answers, auth, addl;
SetResponse response = null;
boolean verbose = Options.check("verbosecache");
HashSet<Name> additionalNames;

if ((rcode != Rcode.NOERROR && rcode != Rcode.NXDOMAIN) || question == null) {
@@ -720,9 +721,7 @@ public SetResponse addMessage(Message in) {
cred = getCred(Section.ADDITIONAL, isAuth);
addRRset(rRset, cred);
}
if (verbose) {
System.out.println("addMessage: " + response);
}
log.debug("addMessage: {}", response);
return (response);
}

@@ -8,8 +8,10 @@
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import lombok.extern.slf4j.Slf4j;
import org.xbill.DNS.utils.hexdump;

@Slf4j
class Client {

protected long endTime;
@@ -52,8 +54,8 @@ protected static void blockUntil(SelectionKey key, long endTime) throws IOExcept

protected static void verboseLog(
String prefix, SocketAddress local, SocketAddress remote, byte[] data) {
if (Options.check("verbosemsg")) {
System.err.println(hexdump.dump(prefix, data));
if (log.isDebugEnabled()) {
log.debug(hexdump.dump(prefix, data));
}
if (packetLogger != null) {
packetLogger.log(prefix, local, remote, data);
@@ -2,13 +2,16 @@

package org.xbill.DNS;

import lombok.extern.slf4j.Slf4j;

/**
* DNS Name Compression object.
*
* @see Message
* @see Name
* @author Brian Wellington
*/
@Slf4j
public class Compression {

private static class Entry {
@@ -20,7 +23,6 @@
private static final int TABLE_SIZE = 17;
private static final int MAX_POINTER = 0x3FFF;
private Entry[] table;
private boolean verbose = Options.check("verbosecompression");

/** Creates a new Compression object. */
public Compression() {
@@ -43,9 +45,7 @@ public void add(int pos, Name name) {
entry.pos = pos;
entry.next = table[row];
table[row] = entry;
if (verbose) {
System.err.println("Adding " + name + " at " + pos);
}
log.debug("Adding {} at {}", name, pos);
}

/**
@@ -62,9 +62,7 @@ public int get(Name name) {
pos = entry.pos;
}
}
if (verbose) {
System.err.println("Looking for " + name + ", found " + pos);
}
log.debug("Looking for {}, found {}", name, pos);
return pos;
}
}
@@ -8,6 +8,7 @@
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;

/**
* An implementation of Resolver that can send queries to multiple servers, sending the queries
@@ -16,6 +17,7 @@
* @see Resolver
* @author Brian Wellington
*/
@Slf4j
public class ExtendedResolver implements Resolver {

private static class Resolution implements ResolverListener {
@@ -137,9 +139,7 @@ public void startAsync(ResolverListener listener) {
*/
@Override
public void receiveMessage(Object id, Message m) {
if (Options.check("verbose")) {
System.err.println("ExtendedResolver: " + "received message");
}
log.debug("received message");
synchronized (this) {
if (done) {
return;
@@ -160,9 +160,7 @@ public void receiveMessage(Object id, Message m) {
*/
@Override
public void handleException(Object id, Exception e) {
if (Options.check("verbose")) {
System.err.println("ExtendedResolver: got " + e);
}
log.debug("resolving failed", e);
synchronized (this) {
outstanding--;
if (done) {
@@ -9,6 +9,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;

/**
* The Lookup object issues queries to caching DNS servers. The input consists of a name, an
@@ -25,6 +26,7 @@
* @see ResolverConfig
* @author Brian Wellington
*/
@Slf4j
public final class Lookup {

private static Resolver defaultResolver;
@@ -40,7 +42,6 @@
private Name name;
private int type;
private int dclass;
private boolean verbose;
private int iterations;
private boolean foundAlias;
private boolean done;
@@ -232,7 +233,6 @@ public Lookup(Name name, int type, int dclass) {
this.cache = getDefaultCache(dclass);
}
this.credibility = Credibility.NORMAL;
this.verbose = Options.check("verbose");
this.result = -1;
}

@@ -436,9 +436,9 @@ private void processResponse(Name name, SetResponse response) {

private void lookup(Name current) {
SetResponse sr = cache.lookupRecords(current, type, credibility);
if (verbose) {
System.err.println("lookup " + current + " " + Type.string(type));
System.err.println(sr);
if (log.isDebugEnabled()) {
log.debug("lookup {} {}", current, Type.string(type));
log.debug(sr.toString());
}
processResponse(current, sr);
if (done || doneCurrent) {
@@ -451,6 +451,8 @@ private void lookup(Name current) {
try {
response = resolver.send(query);
} catch (IOException e) {
log.debug("Lookup failed", e);

// A network error occurred. Press on.
if (e instanceof InterruptedIOException) {
timedout = true;
@@ -479,9 +481,9 @@ private void lookup(Name current) {
if (sr == null) {
sr = cache.lookupRecords(current, type, credibility);
}
if (verbose) {
System.err.println("queried " + current + " " + Type.string(type));
System.err.println(sr);
if (log.isDebugEnabled()) {
log.debug("queried {} {}", current, Type.string(type));
log.debug(sr.toString());
}
processResponse(current, sr);
}
@@ -5,12 +5,14 @@
import java.io.IOException;
import java.io.Serializable;
import java.text.DecimalFormat;
import lombok.extern.slf4j.Slf4j;

/**
* A representation of a domain name. It may either be absolute (fully qualified) or relative.
*
* @author Brian Wellington
*/
@Slf4j
public class Name implements Comparable, Serializable {

private static final long serialVersionUID = -7257019940971525644L;
@@ -369,9 +371,7 @@ public Name(DNSInput in) throws WireParseException {
case LABEL_COMPRESSION:
pos = in.readU8();
pos += ((len & ~LABEL_MASK) << 8);
if (Options.check("verbosecompression")) {
System.err.println("currently " + in.current() + ", pointer to " + pos);
}
log.debug("currently {}, pointer to {}", in.current(), pos);

if (pos >= in.current() - 2) {
throw new WireParseException("bad compression");
@@ -381,9 +381,7 @@ public Name(DNSInput in) throws WireParseException {
savedState = true;
}
in.jump(pos);
if (Options.check("verbosecompression")) {
System.err.println("current name '" + this + "', seeking to " + pos);
}
log.debug("current name '{}', seeking to {}", this, pos);
break;
default:
throw new WireParseException("bad label type");
@@ -8,14 +8,9 @@

/**
* Boolean options:<br>
* bindttl - Print TTLs in BIND format<br>
* BINDTTL - Print TTLs in BIND format<br>
* multiline - Print records in multiline format<br>
* noprintin - Don't print the class of a record if it's IN<br>
* verbose - Turn on general debugging statements<br>
* verbosemsg - Print all messages sent or received by SimpleResolver<br>
* verbosecompression - Print messages related to name compression<br>
* verbosesec - Print messages related to signature verification<br>
* verbosecache - Print messages related to cache lookups<br>
* noPrintIN - Don't print the class of a record if it's IN<br>
* <br>
* Valued options:<br>
* tsigfudge=n - Sets the default TSIG fudge value (in seconds)<br>
@@ -15,6 +15,7 @@
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import lombok.extern.slf4j.Slf4j;

/**
* A class that tries to locate name servers and the search path to be appended to unqualified
@@ -40,6 +41,7 @@
* @author <a href="mailto:yannick@meudal.net">Yannick Meudal</a>
* @author <a href="mailto:arnt@gulbrandsen.priv.no">Arnt Gulbrandsen</a>
*/
@Slf4j
public class ResolverConfig {

public static final String DNS_SERVER_PROP = "dns.server";
@@ -81,17 +83,13 @@ private void addServer(String server, List<String> list) {
if (list.contains(server)) {
return;
}
if (Options.check("verbose")) {
System.out.println("adding server " + server);
}
log.debug("adding server {}", server);
list.add(server);
}

private void addSearch(String search, List<Name> list) {
Name name;
if (Options.check("verbose")) {
System.out.println("adding search " + search);
}
log.debug("adding search {}", search);
try {
name = Name.fromString(search, Name.root);
} catch (TextParseException e) {
@@ -108,9 +106,7 @@ private int parseNdots(String token) {
try {
int ndots = Integer.parseInt(token);
if (ndots >= 0) {
if (Options.check("verbose")) {
System.out.println("setting ndots " + token);
}
log.debug("setting ndots {}", token);
return ndots;
}
} catch (NumberFormatException e) {
@@ -7,6 +7,7 @@
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.List;
import lombok.extern.slf4j.Slf4j;

/**
* An implementation of Resolver that sends one query to one server. SimpleResolver handles TCP
@@ -17,6 +18,7 @@
* @see OPTRecord
* @author Brian Wellington
*/
@Slf4j
public class SimpleResolver implements Resolver {

/** The default port to send queries to */
@@ -178,9 +180,6 @@ private Message parseMessage(byte[] b) throws WireParseException {
try {
return (new Message(b));
} catch (IOException e) {
if (Options.check("verbose")) {
e.printStackTrace();
}
if (!(e instanceof WireParseException)) {
e = new WireParseException("Error parsing message");
}
@@ -193,9 +192,7 @@ private void verifyTSIG(Message query, Message response, byte[] b, TSIG tsig) {
return;
}
int error = tsig.verify(response, b, query.getTSIG());
if (Options.check("verbose")) {
System.err.println("TSIG verify: " + Rcode.TSIGstring(error));
}
log.debug("TSIG verify: {}", Rcode.TSIGstring(error));
}

private void applyEDNS(Message query) {
@@ -224,10 +221,7 @@ private int maxUDPSize(Message query) {
*/
@Override
public Message send(Message query) throws IOException {
if (Options.check("verbose")) {
System.err.println(
"Sending to " + address.getAddress().getHostAddress() + ":" + address.getPort());
}
log.debug("Sending to {}:{}", address.getAddress().getHostAddress(), address.getPort());

if (query.getHeader().getOpcode() == Opcode.QUERY) {
Record question = query.getQuestion();
@@ -277,9 +271,7 @@ public Message send(Message query) throws IOException {
if (tcp) {
throw new WireParseException(error);
} else {
if (Options.check("verbose")) {
System.err.println(error);
}
log.debug(error);
continue;
}
}

0 comments on commit 9de972d

Please sign in to comment.
You can’t perform that action at this time.