Skip to content

Commit

Permalink
improve logging, update logging config
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdeliso committed Jan 2, 2019
1 parent 8c13d8d commit 71dc38c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/java/name/maxdeliso/teflon/Arguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@SuppressWarnings({"unused"})
class Arguments {
@Parameter(names = {"--mode", "-m"}, description = "the run mode, one of L[ist interfaces] or R[un]")
private String mode;
private String mode = "R";

@Parameter(names = {"--help", "-h"}, help = true)
private boolean help;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/name/maxdeliso/teflon/Teflon.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public static void main(String[] args) {
final Optional<String> modeOpt = ofNullable(arguments.getMode());

if (arguments.isHelp() || modeOpt.isEmpty()) {
jc.usage();
final StringBuilder sb = new StringBuilder();
jc.usage(sb);
LOG.error(sb.toString());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Optional<Config> loadFromFile(String path) {
try (final var fileReader = new FileReader(path)) {
return Optional.ofNullable(gson.fromJson(fileReader, Config.class));
} catch (final IOException ioe) {
LOG.warn("failed to load config", ioe);
LOG.error("failed to load config", ioe);
return Optional.empty();
}
}
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/name/maxdeliso/teflon/di/TeflonModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import name.maxdeliso.teflon.data.Message;
import name.maxdeliso.teflon.net.NetSelector;
import name.maxdeliso.teflon.ui.MainFrame;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Singleton;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
Expand All @@ -21,10 +24,10 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import javax.inject.Singleton;

@Module
public class TeflonModule {
private static final Logger LOG = LoggerFactory.getLogger(TeflonModule.class);

private static final String CONFIG_PATH = "teflon.json";

@Provides
Expand All @@ -48,10 +51,12 @@ JsonMessageMarshaller provideJSONMessageMarshaller(final Gson gson) {
@Provides
@Singleton
Config provideConfig(final ConfigLoader configLoader) {
return configLoader
.loadFromFile(CONFIG_PATH)
.orElseThrow(() -> new IllegalArgumentException(
"failed to locate and load config file at: " + CONFIG_PATH));
return configLoader.loadFromFile(CONFIG_PATH)
.orElseThrow(() -> {
final String errorMesage = "failed to locate config file at: " + CONFIG_PATH;
LOG.error(errorMesage);
return new IllegalArgumentException(errorMesage);
});
}

@Provides
Expand Down Expand Up @@ -80,6 +85,7 @@ InetAddress provideInetAddress(final Config config) {
// NOTE: this causes a DNS Query to run
return InetAddress.getByName(config.getMulticastGroup());
} catch (UnknownHostException uhe) {
LOG.error("failed to process multicast group from config", uhe);
throw new RuntimeException(uhe);
}
}
Expand All @@ -92,6 +98,7 @@ NetworkInterface provideNetworkInterface(final Config config) {
// NOTE: this invokes some platform specific code
return NetworkInterface.getByName(config.getInterfaceName());
} catch (SocketException se) {
LOG.error("failed to process interface name from config", se);
throw new RuntimeException(se);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</RollingFile>
</Appenders>
<Loggers>
<Logger level="DEBUG" name="name.maxdeliso.teflon" additivity="false">
<Logger level="DEBUG" name="name.maxdeliso.teflon" additivity="true">
<AppenderRef ref="teflon" />
</Logger>
<Root level="INFO">
Expand Down

0 comments on commit 71dc38c

Please sign in to comment.