Skip to content

Commit

Permalink
Introduce SLF4J for logging (hyperledger#3285)
Browse files Browse the repository at this point in the history
* Bump SLF4J version

Signed-off-by: Diego López León <[email protected]>

* Replace log4j2 API with SLF4j API

Signed-off-by: Diego López León <[email protected]>

* Replace usage of LogManager#getFormatterLogger

This is for keeping compatibility with SLF4J. If neccesary, a specific formatter can be created for the RlpBlockImporter class

Signed-off-by: Diego López León <[email protected]>

* Unset the default logging value for the retesteth

This is because it's not possible to resolve the root logger level into a Log4J2 field

Signed-off-by: Diego López León <[email protected]>

* Prevent creation of Logger context outside SLF4J

org.hyperledger.besu.cli.BesuCommand#setAllLevels was taken from
https://github.com/apache/logging-log4j2/blob/rel%2F2.17.1/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java#L309

Signed-off-by: Diego López León <[email protected]>

* Add FATAL level deprecation message

Signed-off-by: Diego López León <[email protected]>

* [Sonar] Fix java:S2139

Exceptions should be either logged or rethrown but not both

Signed-off-by: Diego López León <[email protected]>

* [Sonar] Fix java:S3457

Printf-style format strings should be used correctly

Signed-off-by: Diego López León <[email protected]>

* Add changelog

Signed-off-by: Diego López León <[email protected]>
  • Loading branch information
diega authored Jan 25, 2022
1 parent e7ccb33 commit ed1329c
Show file tree
Hide file tree
Showing 404 changed files with 1,501 additions and 1,393 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Re-order external services (e.g JsonRpcHttpService) to start before blocks start processing [#3118](https://github.com/hyperledger/besu/pull/3118)
- Stream JSON RPC responses to avoid creating big JSON strings in memory [#3076](https://github.com/hyperledger/besu/pull/3076)
- Ethereum Classic Mystique Hard Fork [#3256](https://github.com/hyperledger/besu/pull/3256)
- Move into SLF4J as logging facade [#3285](https://github.com/hyperledger/besu/pull/3285)

### Bug Fixes
- Make 'to' field optional in eth_call method according to the spec [#3177](https://github.com/hyperledger/besu/pull/3177)
Expand Down
3 changes: 0 additions & 3 deletions acceptance-tests/dsl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ dependencies {
implementation 'io.reactivex.rxjava2:rxjava'
implementation 'io.vertx:vertx-core'
implementation 'junit:junit'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.apache.logging.log4j:log4j-slf4j-impl'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-io'
implementation 'org.apache.tuweni:tuweni-units'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import org.junit.After;
import org.junit.Rule;
import org.junit.rules.TestName;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AcceptanceTestBase {

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

protected final Accounts accounts;
protected final AccountTransactions accountTransactions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

import java.util.Optional;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ExitedWithCode implements Condition {

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

private final int code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.hyperledger.besu.tests.acceptance.dsl.node;

import static java.util.Collections.unmodifiableList;
import static org.apache.logging.log4j.LogManager.getLogger;
import static org.apache.tuweni.io.file.Files.copyResource;

import org.hyperledger.besu.cli.config.NetworkName;
Expand Down Expand Up @@ -66,10 +65,11 @@
import com.google.common.base.MoreObjects;
import com.google.common.io.MoreFiles;
import com.google.common.io.RecursiveDeleteOption;
import org.apache.logging.log4j.Logger;
import org.awaitility.Awaitility;
import org.awaitility.core.ConditionTimeoutException;
import org.java_websocket.exceptions.WebsocketNotConnectedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.web3j.protocol.Web3jService;
import org.web3j.protocol.core.JsonRpc2_0Web3j;
import org.web3j.protocol.http.HttpService;
Expand All @@ -81,7 +81,7 @@
public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable {

private static final String LOCALHOST = "127.0.0.1";
private static final Logger LOG = getLogger();
private static final Logger LOG = LoggerFactory.getLogger(BesuNode.class);

private final Path homeDirectory;
private KeyPair keyPair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

public class ProcessBesuNodeRunner implements BesuNodeRunner {

private static final Logger LOG = LogManager.getLogger();
private static final Logger LOG = LoggerFactory.getLogger(ProcessBesuNodeRunner.class);
private static final Logger PROCESS_LOG =
LogManager.getLogger("org.hyperledger.besu.SubProcessLog");
LoggerFactory.getLogger("org.hyperledger.besu.SubProcessLog");

private final Map<String, Process> besuProcesses = new HashMap<>();
private final ExecutorService outputProcessorExecutor = Executors.newCachedThreadPool();
Expand Down Expand Up @@ -410,7 +410,7 @@ public void startNode(final BesuNode node) {
waitForFile(dataDir, "besu.ports");
waitForFile(dataDir, "besu.networks");
}
ThreadContext.remove("node");
MDC.remove("node");
}

private boolean isNotAliveOrphan(final String name) {
Expand All @@ -422,7 +422,7 @@ private void printOutput(final BesuNode node, final Process process) {
try (final BufferedReader in =
new BufferedReader(new InputStreamReader(process.getInputStream(), UTF_8))) {

ThreadContext.put("node", node.getName());
MDC.put("node", node.getName());

String line = in.readLine();
while (line != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@
import java.util.stream.Collectors;

import io.vertx.core.Vertx;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import picocli.CommandLine;
import picocli.CommandLine.Model.CommandSpec;

public class ThreadBesuNodeRunner implements BesuNodeRunner {

private static final Logger LOG = LogManager.getLogger();
private static final Logger LOG = LoggerFactory.getLogger(ThreadBesuNodeRunner.class);
private final Map<String, Runner> besuRunners = new HashMap<>();

private final Map<Node, BesuPluginContextImpl> besuPluginContextMap = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -111,10 +111,10 @@ private BesuPluginContextImpl buildPluginContext(
@Override
public void startNode(final BesuNode node) {

if (ThreadContext.containsKey("node")) {
LOG.error("ThreadContext node is already set to {}", ThreadContext.get("node"));
if (MDC.get("node") != null) {
LOG.error("ThreadContext node is already set to {}", MDC.get("node"));
}
ThreadContext.put("node", node.getName());
MDC.put("node", node.getName());

if (!node.getRunCommand().isEmpty()) {
throw new UnsupportedOperationException("commands are not supported with thread runner");
Expand Down Expand Up @@ -229,7 +229,7 @@ public void startNode(final BesuNode node) {
runner.startEthereumMainLoop();

besuRunners.put(node.getName(), runner);
ThreadContext.remove("node");
MDC.remove("node");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
import java.util.Map;
import java.util.Optional;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Cluster implements AutoCloseable {
private static final Logger LOG = LogManager.getLogger();
private static final Logger LOG = LoggerFactory.getLogger(Cluster.class);

private final Map<String, RunnableNode> nodes = new HashMap<>();
private final BesuNodeRunner besuNodeRunner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import java.util.Optional;
import java.util.stream.Collectors;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PrivacyCluster {
private static final Logger LOG = LogManager.getLogger();
private static final Logger LOG = LoggerFactory.getLogger(PrivacyCluster.class);
private final NetConditions net;
private final BesuNodeRunner besuNodeRunner;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
import java.util.stream.Collectors;

import io.vertx.core.Vertx;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.awaitility.Awaitility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.Network;

public class PrivacyNode implements AutoCloseable {

private static final Logger LOG = LogManager.getLogger();
private static final Logger LOG = LoggerFactory.getLogger(PrivacyNode.class);
private static final int MAX_OPEN_FILES = 1024;
private static final long CACHE_CAPACITY = 8388608;
private static final int MAX_BACKGROUND_COMPACTIONS = 4;
Expand Down
4 changes: 2 additions & 2 deletions acceptance-tests/test-plugins/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

dependencies {
api 'org.slf4j:slf4j-api'

implementation project(':besu')
implementation project(':crypto')
implementation project(':datatypes')
Expand All @@ -8,8 +10,6 @@ dependencies {
implementation project(':plugin-api')
implementation 'com.google.auto.service:auto-service'
implementation 'info.picocli:picocli'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.logging.log4j:log4j-core'

testImplementation 'org.assertj:assertj-core'
testImplementation 'junit:junit'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import java.nio.file.Files;

import com.google.auto.service.AutoService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Option;

@AutoService(BesuPlugin.class)
public class BadCLIOptionsPlugin implements BesuPlugin {
private static final Logger LOG = LogManager.getLogger();
private static final Logger LOG = LoggerFactory.getLogger(BadCLIOptionsPlugin.class);

@Option(names = "--poorly-named-option")
String poorlyNamedOption = "nothing";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import java.util.concurrent.atomic.AtomicInteger;

import com.google.auto.service.AutoService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@AutoService(BesuPlugin.class)
public class TestBesuEventsPlugin implements BesuPlugin {
private static final Logger LOG = LogManager.getLogger();
private static final Logger LOG = LoggerFactory.getLogger(TestBesuEventsPlugin.class);

private BesuContext context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import org.hyperledger.besu.plugin.services.PicoCLIOptions;

import com.google.auto.service.AutoService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Option;

@AutoService(BesuPlugin.class)
public class TestPermissioningPlugin implements BesuPlugin {
private static final Logger LOG = LogManager.getLogger();
private static final Logger LOG = LoggerFactory.getLogger(TestPermissioningPlugin.class);

private static final String aliceNode =
"09b02f8a5fddd222ade4ea4528faefc399623af3f736be3c44f03e2df22fb792f3931a4d9573d333ca74343305762a753388c3422a86d98b713fc91c1ea04842";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
import java.util.Collections;

import com.google.auto.service.AutoService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Option;

@AutoService(BesuPlugin.class)
public class TestPicoCLIPlugin implements BesuPlugin {
private static final Logger LOG = LogManager.getLogger();
private static final Logger LOG = LoggerFactory.getLogger(TestPicoCLIPlugin.class);

@Option(
names = {"--Xplugin-test-option"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import org.hyperledger.besu.tests.acceptance.plugins.privacy.TestSigningPrivateMarkerTransactionFactory;

import com.google.auto.service.AutoService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Option;

@AutoService(BesuPlugin.class)
public class TestPrivacyServicePlugin implements BesuPlugin {
private static final Logger LOG = LogManager.getLogger();
private static final Logger LOG = LoggerFactory.getLogger(TestPrivacyServicePlugin.class);

PrivacyPluginService pluginService;
BesuContext context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

import java.util.Optional;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestPrivacyPluginPayloadProvider implements PrivacyPluginPayloadProvider {
private static final Logger LOG = LogManager.getLogger();
private static final Logger LOG = LoggerFactory.getLogger(TestPrivacyPluginPayloadProvider.class);
private String prefix;

public void setPluginPayloadPrefix(final String prefix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
package org.hyperledger.besu.tests.acceptance.plugins.privacy;

import static org.apache.logging.log4j.LogManager.getLogger;
import static org.hyperledger.besu.datatypes.Address.extract;

import org.hyperledger.besu.crypto.KeyPair;
Expand All @@ -31,13 +30,15 @@
import org.hyperledger.besu.plugin.data.UnsignedPrivateMarkerTransaction;
import org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory;

import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestSigningPrivateMarkerTransactionFactory implements PrivateMarkerTransactionFactory {

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

KeyPair aliceFixedSigningKey;
Address sender;
Expand Down
5 changes: 3 additions & 2 deletions besu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jar {
}

dependencies {
api 'org.slf4j:slf4j-api'

implementation project(':config')
implementation project(':pki')
implementation project(':consensus:clique')
Expand Down Expand Up @@ -56,6 +58,7 @@ dependencies {
implementation project(':plugin-api')
implementation project(':plugins:rocksdb')
implementation project(':services:kvstore')
implementation project(':util')

implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
Expand All @@ -64,7 +67,6 @@ dependencies {
implementation 'info.picocli:picocli'
implementation 'io.vertx:vertx-core'
implementation 'io.vertx:vertx-web'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-config'
Expand All @@ -74,7 +76,6 @@ dependencies {
implementation 'org.xerial.snappy:snappy-java'
implementation 'net.consensys.services:quorum-mainnet-launcher'

runtimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl'
runtimeOnly 'org.apache.logging.log4j:log4j-jul'
runtimeOnly 'com.splunk.logging:splunk-library-javalogging'
runtimeOnly 'org.fusesource.jansi:jansi' // for color logging in windows
Expand Down
Loading

0 comments on commit ed1329c

Please sign in to comment.