Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Rework cmdline #6

Merged
merged 8 commits into from
Mar 14, 2019
Merged

Rework cmdline #6

merged 8 commits into from
Mar 14, 2019

Conversation

rain-on
Copy link
Contributor

@rain-on rain-on commented Mar 13, 2019

Rework commandline to be a "config" struct, and move the actually application construction into the EthFirewall class.

@rain-on rain-on requested review from jframe and CjHare March 13, 2019 01:51
Copy link
Contributor

@CjHare CjHare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely moving things in a better direction

private static final Logger LOG = LoggerFactory.getLogger(EthFirewallConfig.class);

private final EthFirewallConfig config;
private RunnerBuilder runnerBuilder;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't the RunnerBuilder be final too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


public RunnerBuilder() {}

public TransactionSigner getTransactionSigner() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have getters in the RunnerBuilder? ...are they solely for testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its a bit unwarranted ....

return serverOptions;
}

public void setTransactionSigner(TransactionSigner transactionSigner) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit; method arguments can be final

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, they should.


public final class EthFirewall {
private static final int ERROR_EXIT_CODE = 1;

private static final Logger LOG = LoggerFactory.getLogger(EthFirewallCommandLineConfig.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log class is wrong, should be EthFirewall.class. Maybe we should have just used log4j directly instead of slf4j

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - happy to keep trying with slf4j

byte[] fileContent = Files.readAllBytes(Paths.get(config.getPasswordFilePath()));
return Optional.of(new String(fileContent, Charsets.UTF_8));
} catch (IOException ex) {
return Optional.empty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we should log this exception

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (but only at debug level).


Level getLogLevel();

String getPasswordFilePath();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use Path to for the password file path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@CjHare CjHare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember now, don't be using SLF4J

import io.vertx.core.http.HttpServerOptions;
import io.vertx.ext.web.client.WebClientOptions;
import org.apache.logging.log4j.core.config.Configurator;
import org.slf4j.Logger;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall something about Log4j2 vs SLF4j now ...as of mid 2018 there's no value brought by SLF4J
https://stackoverflow.com/questions/41498021/is-it-worth-to-use-slf4j-with-log4j2/41500347#41500347
https://stackoverflow.com/questions/41633278/can-we-use-all-features-of-log4j2-if-we-use-it-along-with-slf4j-api/41635246#41635246

SLF4J It's actually an interesting story, as it was created by a disgruntled Log4J contributor who wanted to move things in a new scary direction of abstraction (which after being proven right, Log4J adopted)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log4j2.x has adopted all features of SLF4J
https://en.wikipedia.org/wiki/SLF4J
...I mean Wikipedia wouldn't tell a lie 😉

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The single reason to use SLF4J over Log4J (or any other specific implementation) is that the backend is pluggable. For a standalone product that's pretty irrelevant but as soon as the code is embedded in another app a pluggable logging framework is pretty much essential.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh and because SLF4J's API works properly if you do:

} catch (Exception e) {
  LOG.error(e);
}

whereas Log4j will lose the stack trace.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no reason not to continue using slf4j unless it causes problems. It also plays nicer with logging from dependent libraries as it has bridges for most logging frameworks and many open source frameworks use it anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajsutton @jframe since Log4j2 the backend is also pluggable, the default being Log4j but also supported is SLF4J, Apache Commons etc
https://logging.apache.org/log4j/2.x/index.html

@rain-on rain-on merged commit a2d80d8 into Consensys:master Mar 14, 2019
@rain-on rain-on deleted the rework_cmdline branch March 14, 2019 02:19
sambacha pushed a commit to freight-trust/ethsigner that referenced this pull request Oct 3, 2020
Remove bintray publish CI step as not needed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants