Use log4j for logging.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 15 Oct 2014 18:58:21 +0000 (20:58 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 15 Oct 2014 18:58:21 +0000 (20:58 +0200)
pom.xml
src/main/java/net/pterodactylus/irc/Connection.java
src/main/java/net/pterodactylus/irc/DccReceiver.java
src/main/java/net/pterodactylus/xdcc/core/Core.java

diff --git a/pom.xml b/pom.xml
index 509b611..0dcbfee 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                        <artifactId>jewelcli</artifactId>
                        <version>0.8.3</version>
                </dependency>
+               <dependency>
+                       <groupId>log4j</groupId>
+                       <artifactId>log4j</artifactId>
+                       <version>1.2.17</version>
+               </dependency>
        </dependencies>
 
        <properties>
index 336fdae..fb67fe7 100644 (file)
@@ -36,8 +36,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 import javax.net.SocketFactory;
 
 import net.pterodactylus.irc.event.ChannelJoined;
@@ -75,6 +73,7 @@ import com.google.common.primitives.Ints;
 import com.google.common.primitives.Longs;
 import com.google.common.util.concurrent.AbstractExecutionThreadService;
 import com.google.common.util.concurrent.Service;
+import org.apache.log4j.Logger;
 
 /**
  * A connection to an IRC server.
@@ -379,7 +378,7 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                        while (connected) {
                                Reply reply = connectionHandler.readReply();
                                eventBus.post(new ReplyReceived(this, reply));
-                               logger.finest(String.format("<< %s", reply));
+                               logger.trace(String.format("<< %s", reply));
                                String command = reply.command();
                                List<String> parameters = reply.parameters();
 
@@ -480,13 +479,13 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                                                                        char modeSymbol = parameter.charAt(closeParen + modeCharacterIndex);
                                                                        nickPrefixes.put(String.valueOf(modeSymbol), String.valueOf(modeCharacter));
                                                                }
-                                                               logger.fine(String.format("Parsed Prefixes: %s", nickPrefixes));
+                                                               logger.debug(String.format("Parsed Prefixes: %s", nickPrefixes));
                                                        }
                                                } else if (parameter.startsWith("CHANTYPES=")) {
                                                        for (int typeIndex = 10; typeIndex < parameter.length(); ++typeIndex) {
                                                                channelTypes.add(parameter.charAt(typeIndex));
                                                        }
-                                                       logger.fine(String.format("Parsed Channel Types: %s", channelTypes));
+                                                       logger.debug(String.format("Parsed Channel Types: %s", channelTypes));
                                                }
                                        }
 
@@ -515,10 +514,10 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                        }
                        eventBus.post(new ConnectionClosed(this));
                } catch (IOException ioe1) {
-                       logger.log(Level.WARNING, "I/O error", ioe1);
+                       logger.warn("I/O error", ioe1);
                        eventBus.post(new ConnectionClosed(this, ioe1));
                } catch (RuntimeException re1) {
-                       logger.log(Level.SEVERE, "Runtime error", re1);
+                       logger.error("Runtime error", re1);
                        eventBus.post(new ConnectionClosed(this, re1));
                } finally {
                        established = false;
@@ -555,7 +554,7 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                                if (inetAddress.isPresent() && port.isPresent()) {
                                        eventBus.post(new DccSendReceived(this, client, messageWords[2], inetAddress.get(), port.get(), fileSize));
                                } else {
-                                       logger.warning(String.format("Received malformed DCC SEND: “%s”", message));
+                                       logger.warn(String.format("Received malformed DCC SEND: “%s”", message));
                                }
                        } else if (messageWords[1].equalsIgnoreCase("ACCEPT")) {
                                Optional<Integer> port = Optional.fromNullable(Ints.tryParse(messageWords[3]));
@@ -563,7 +562,7 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                                if (port.isPresent()) {
                                        eventBus.post(new DccAcceptReceived(this, client, messageWords[2], port.get(), position));
                                } else {
-                                       logger.warning(String.format("Received malformed DCC ACCEPT: “%s”", message));
+                                       logger.warn(String.format("Received malformed DCC ACCEPT: “%s”", message));
                                }
                        }
                }
@@ -717,7 +716,7 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                                commandBuilder.append(parameter);
                        }
 
-                       logger.finest(String.format(">> %s", commandBuilder));
+                       logger.trace(String.format(">> %s", commandBuilder));
                        outputStream.write((commandBuilder.toString() + "\r\n").getBytes("UTF-8"));
                        outputStream.flush();
                }
index abb018c..e024d4e 100644 (file)
@@ -23,8 +23,6 @@ import java.io.OutputStream;
 import java.net.InetAddress;
 import java.net.Socket;
 import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
 import net.pterodactylus.irc.event.DccDownloadFailed;
 import net.pterodactylus.irc.event.DccDownloadFinished;
@@ -34,6 +32,7 @@ import net.pterodactylus.xdcc.util.io.BandwidthCountingInputStream;
 import com.google.common.eventbus.EventBus;
 import com.google.common.io.Closeables;
 import com.google.common.util.concurrent.AbstractExecutionThreadService;
+import org.apache.log4j.Logger;
 
 /**
  * Service that receives a file offered by a {@link DccSendReceived}.
@@ -196,7 +195,7 @@ public class DccReceiver extends AbstractExecutionThreadService {
                                eventBus.post(new DccDownloadFailed(this, new IOException("Download aborted.")));
                        }
                } catch (IOException ioe1) {
-                       logger.log(Level.WARNING, "I/O error while receiving DCC!", ioe1);
+                       logger.warn("I/O error while receiving DCC!", ioe1);
                        eventBus.post(new DccDownloadFailed(this, ioe1));
                } finally {
                        Closeables.close(inputStream, true);
index d875a5b..eb0036c 100644 (file)
@@ -33,8 +33,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
 import net.pterodactylus.irc.Connection;
 import net.pterodactylus.irc.ConnectionBuilder;
@@ -88,6 +86,7 @@ import com.google.common.eventbus.Subscribe;
 import com.google.common.io.Closeables;
 import com.google.common.util.concurrent.AbstractExecutionThreadService;
 import com.google.inject.Inject;
+import org.apache.log4j.Logger;
 
 /**
  * The core of XDCC Downloader.
@@ -281,7 +280,7 @@ public class Core extends AbstractExecutionThreadService {
                try {
                        connection.sendMessage(bot.name(), "XDCC SEND " + pack.id());
                } catch (IOException ioe1) {
-                       logger.log(Level.WARNING, "Could not send message to bot!", ioe1);
+                       logger.warn("Could not send message to bot!", ioe1);
                }
        }
 
@@ -318,7 +317,7 @@ public class Core extends AbstractExecutionThreadService {
                try {
                        connection.sendMessage(bot.name(), String.format("XDCC %s", (download.get().dccReceiver() != null) ? "CANCEL" : "REMOVE"));
                } catch (IOException ioe1) {
-                       logger.log(Level.WARNING, String.format("Could not cancel DCC from %s (%s)!", bot.name(), bot.network().name()), ioe1);
+                       logger.warn(String.format("Could not cancel DCC from %s (%s)!", bot.name(), bot.network().name()), ioe1);
                }
        }
 
@@ -481,7 +480,7 @@ public class Core extends AbstractExecutionThreadService {
                                        eventBus.post(new GenericMessage(String.format("Trying to join %s on %s...", channel.name(), network.get().name())));
                                        connectionEstablished.connection().joinChannel(channel.name());
                                } catch (IOException ioe1) {
-                                       logger.log(Level.WARNING, String.format("Could not join %s on %s!", channel.name(), network.get().name()), ioe1);
+                                       logger.warn(String.format("Could not join %s on %s!", channel.name(), network.get().name()), ioe1);
                                }
                        }
                }
@@ -654,7 +653,7 @@ public class Core extends AbstractExecutionThreadService {
 
                /* add pack. */
                bot.addPack(pack.get());
-               logger.fine(String.format("Bot %s now has %d packs.", bot, bot.packs().size()));
+               logger.debug(String.format("Bot %s now has %d packs.", bot, bot.packs().size()));
        }
 
        /**
@@ -809,7 +808,7 @@ public class Core extends AbstractExecutionThreadService {
                        File outputFile = new File(temporaryDirectory, dccAcceptReceived.filename());
                        if (outputFile.length() != dccAcceptReceived.position()) {
                                eventBus.post(new GenericError(String.format("Download %s from %s does not start at the right position!")));
-                               logger.log(Level.WARNING, String.format("Download %s from %s: have %d bytes but wants to resume from %d!", dccAcceptReceived.filename(), dccAcceptReceived.source(), outputFile.length(), dccAcceptReceived.position()));
+                               logger.warn(String.format("Download %s from %s: have %d bytes but wants to resume from %d!", dccAcceptReceived.filename(), dccAcceptReceived.source(), outputFile.length(), dccAcceptReceived.position()));
 
                                downloads.removeAll(download.pack().name());
                                return;
@@ -838,7 +837,7 @@ public class Core extends AbstractExecutionThreadService {
                Collection<Download> requestedDownload = FluentIterable.from(downloads.get(dccDownloadFinished.dccReceiver().filename())).filter(FILTER_RUNNING).toSet();
                if (requestedDownload.isEmpty()) {
                        /* this seems wrong. */
-                       logger.warning("Download finished but could not be located.");
+                       logger.warn("Download finished but could not be located.");
                        return;
                }
                Download download = requestedDownload.iterator().next();
@@ -852,7 +851,7 @@ public class Core extends AbstractExecutionThreadService {
                        downloads.removeAll(download.pack().name());
                } catch (IOException ioe1) {
                        /* TODO - handle all the errors. */
-                       logger.log(Level.WARNING, String.format("Could not move file %s to directory %s.", download.filename(), finalDirectory), ioe1);
+                       logger.warn(String.format("Could not move file %s to directory %s.", download.filename(), finalDirectory), ioe1);
                }
        }
 
@@ -869,7 +868,7 @@ public class Core extends AbstractExecutionThreadService {
                Collection<Download> requestedDownload = FluentIterable.from(downloads.get(dccDownloadFailed.dccReceiver().filename())).filter(FILTER_RUNNING).toSet();
                if (requestedDownload.isEmpty()) {
                        /* this seems wrong. */
-                       logger.warning("Download finished but could not be located.");
+                       logger.warn("Download finished but could not be located.");
                        return;
                }
                Download download = requestedDownload.iterator().next();
@@ -886,7 +885,7 @@ public class Core extends AbstractExecutionThreadService {
 
        @Subscribe
        public void replyReceived(ReplyReceived replyReceived) {
-               logger.log(Level.FINEST, String.format("%s: %s", replyReceived.connection().hostname(), replyReceived.reply()));
+               logger.trace(String.format("%s: %s", replyReceived.connection().hostname(), replyReceived.reply()));
        }
 
        //