Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to slf4j #279

Merged
merged 10 commits into from
May 18, 2023
7 changes: 2 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,13 @@ configure(
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")

implementation("com.google.guava:guava")
implementation("org.apache.logging.log4j:log4j-api")

testFixturesImplementation("org.apache.logging.log4j:log4j-api")
testFixturesImplementation("com.google.guava:guava")
implementation("org.slf4j:slf4j-api")

testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testImplementation("io.mockk:mockk")
testImplementation("org.assertj:assertj-core")
testImplementation("org.apache.logging.log4j:log4j-core")
testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl")
}

java {
Expand Down
2 changes: 1 addition & 1 deletion examples/cli-chatter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
dependencies {
implementation project(':examples:chatter')

runtimeOnly("org.apache.logging.log4j:log4j-core")
runtimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl")
}

application {
Expand Down
2 changes: 1 addition & 1 deletion examples/pinger/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
dependencies {
implementation project(':libp2p')

runtimeOnly("org.apache.logging.log4j:log4j-core")
runtimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl")
}

application {
Expand Down
1 change: 1 addition & 0 deletions libp2p/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
implementation("org.bouncycastle:bcpkix-jdk15on")

testImplementation(project(":tools:schedulers"))
testImplementation("org.apache.logging.log4j:log4j-core")

testFixturesImplementation("io.netty:netty-transport-classes-epoll")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import io.libp2p.discovery.mdns.impl.constants.DNSRecordClass;
import io.libp2p.discovery.mdns.impl.constants.DNSRecordType;
import io.libp2p.discovery.mdns.impl.constants.DNSResultCode;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.libp2p.discovery.mdns.impl.constants.DNSConstants;
import io.libp2p.discovery.mdns.impl.constants.DNSLabel;
Expand All @@ -27,14 +27,14 @@
* @author Arthur van Hoff, Werner Randelshofer, Pierre Frisch, Daniel Bobbert
*/
public final class DNSIncoming extends DNSMessage {
private static Logger logger = LogManager.getLogger(DNSIncoming.class.getName());
private static Logger logger = LoggerFactory.getLogger(DNSIncoming.class.getName());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why so many spaces before the =? 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That was just copied sources 'as is'. If at some point we will add Java Spotless that would be fixed :)


// This is a hack to handle a bug in the BonjourConformanceTest
// It is sending out target strings that don't follow the "domain name" format.
public static boolean USE_DOMAIN_NAME_FORMAT_FOR_SRV_TARGET = true;

public static class MessageInputStream extends ByteArrayInputStream {
private static Logger logger1 = LogManager.getLogger(MessageInputStream.class.getName());
private static Logger logger1 = LoggerFactory.getLogger(MessageInputStream.class.getName());

final Map<Integer, String> _names;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import io.libp2p.discovery.mdns.impl.constants.DNSRecordClass;
import io.libp2p.discovery.mdns.impl.constants.DNSRecordType;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.libp2p.discovery.mdns.ServiceInfo;
import io.libp2p.discovery.mdns.impl.constants.DNSConstants;
Expand All @@ -20,7 +20,7 @@
* @author Arthur van Hoff, Pierre Frisch
*/
public class DNSQuestion extends DNSEntry {
private static Logger logger = LogManager.getLogger(DNSQuestion.class.getName());
private static Logger logger = LoggerFactory.getLogger(DNSQuestion.class.getName());

/**
* Pointer question.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import io.libp2p.discovery.mdns.impl.constants.DNSRecordClass;
import io.libp2p.discovery.mdns.impl.constants.DNSRecordType;
import io.libp2p.discovery.mdns.impl.util.ByteWrangler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.DataOutputStream;
import java.io.IOException;
Expand All @@ -26,7 +26,7 @@
* @author Arthur van Hoff, Rick Blair, Werner Randelshofer, Pierre Frisch
*/
public abstract class DNSRecord extends DNSEntry {
private static Logger logger = LogManager.getLogger(DNSRecord.class.getName());
private static Logger logger = LoggerFactory.getLogger(DNSRecord.class.getName());

private int _ttl;
private long _created;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import java.net.*;
import java.util.*;

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

/**
* HostInfo information on the local host to be able to cope with change of addresses.
*
* @author Pierre Frisch, Werner Randelshofer
*/
public class HostInfo {
private static Logger logger = LogManager.getLogger(HostInfo.class.getName());
private static Logger logger = LoggerFactory.getLogger(HostInfo.class.getName());

protected String _name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import io.libp2p.discovery.mdns.impl.tasks.Responder;
import io.libp2p.discovery.mdns.impl.tasks.ServiceResolver;
import io.libp2p.discovery.mdns.impl.util.NamedThreadFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.DatagramPacket;
Expand Down Expand Up @@ -46,7 +46,7 @@
* @author Arthur van Hoff, Rick Blair, Jeff Sonstein, Werner Randelshofer, Pierre Frisch, Scott Lewis, Kai Kreuzer, Victor Toni
*/
public class JmDNSImpl extends JmDNS {
private static Logger logger = LogManager.getLogger(JmDNSImpl.class.getName());
private static Logger logger = LoggerFactory.getLogger(JmDNSImpl.class.getName());

/**
* This is the multicast group, we are listening to for multicast DNS messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import io.libp2p.discovery.mdns.ServiceInfo;
import io.libp2p.discovery.mdns.impl.constants.DNSRecordClass;
import io.libp2p.discovery.mdns.impl.util.ByteWrangler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.Inet4Address;
Expand All @@ -30,7 +30,7 @@
* @author Arthur van Hoff, Jeff Sonstein, Werner Randelshofer, Victor Toni
*/
public class ServiceInfoImpl extends ServiceInfo {
private static Logger logger = LogManager.getLogger(ServiceInfoImpl.class.getName());
private static Logger logger = LoggerFactory.getLogger(ServiceInfoImpl.class.getName());

private String _domain;
private String _protocol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
import java.util.concurrent.Future;

import io.libp2p.discovery.mdns.impl.util.NamedThreadFactory;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.libp2p.discovery.mdns.impl.constants.DNSConstants;

/**
* Listen for multicast packets.
*/
class SocketListener implements Runnable {
static Logger logger = LogManager.getLogger(SocketListener.class.getName());
static Logger logger = LoggerFactory.getLogger(SocketListener.class.getName());

private final JmDNSImpl _jmDNSImpl;
private final String _name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
package io.libp2p.discovery.mdns.impl.constants;

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

/**
* DNS Record Class
Expand Down Expand Up @@ -41,7 +41,7 @@ public enum DNSRecordClass {
*/
CLASS_ANY("any", 255);

private static Logger logger = LogManager.getLogger(DNSRecordClass.class.getName());
private static Logger logger = LoggerFactory.getLogger(DNSRecordClass.class.getName());

/**
* Multicast DNS uses the bottom 15 bits to identify the record class...<br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
package io.libp2p.discovery.mdns.impl.constants;

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

/**
* DNS Record Type
Expand Down Expand Up @@ -249,7 +249,7 @@ public enum DNSRecordType {
*/
TYPE_ANY("any", 255);

private static Logger logger = LogManager.getLogger(DNSRecordType.class.getName());
private static Logger logger = LoggerFactory.getLogger(DNSRecordType.class.getName());

private final String _externalName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;

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

import io.libp2p.discovery.mdns.impl.DNSIncoming;
import io.libp2p.discovery.mdns.impl.DNSOutgoing;
Expand All @@ -25,7 +25,7 @@
* The Responder sends a single answer for the specified service infos and for the host name.
*/
public class Responder extends DNSTask {
static Logger logger = LogManager.getLogger(Responder.class.getName());
static Logger logger = LoggerFactory.getLogger(Responder.class.getName());

private final DNSIncoming _in;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import io.libp2p.discovery.mdns.impl.constants.DNSConstants;
import io.libp2p.discovery.mdns.impl.constants.DNSRecordClass;
import io.libp2p.discovery.mdns.impl.constants.DNSRecordType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.concurrent.Future;
Expand All @@ -22,7 +22,7 @@
* The ServiceResolver queries three times consecutively for services of a given type, and then removes itself from the timer.
*/
public class ServiceResolver extends DNSTask {
private static Logger logger = LogManager.getLogger(ServiceResolver.class.getName());
private static Logger logger = LoggerFactory.getLogger(ServiceResolver.class.getName());

private final String _type;
private final int _queryInterval;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.libp2p.core.multiformats

import org.apache.logging.log4j.LogManager
import org.slf4j.LoggerFactory
import java.net.Inet4Address
import java.net.Inet6Address
import java.net.InetAddress
Expand All @@ -13,7 +13,7 @@ class MultiaddrDns {
}

companion object {
private val log = LogManager.getLogger(MultiaddrDns::class.java)
private val log = LoggerFactory.getLogger(MultiaddrDns::class.java)
private val dnsProtocols = arrayOf(Protocol.DNS4, Protocol.DNS6, Protocol.DNSADDR)

fun resolve(addr: Multiaddr, resolver: Resolver = DefaultResolver): List<Multiaddr> {
Expand Down Expand Up @@ -54,7 +54,7 @@ class MultiaddrDns {
}
}
} catch (e: UnknownHostException) {
log.debug(e)
log.debug("Unknown error", e)
return emptyList()
// squash, as this might not be fatal,
// and if it is we'll handle this higher up the call chain
Expand Down
4 changes: 2 additions & 2 deletions libp2p/src/main/kotlin/io/libp2p/etc/util/P2PService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import io.libp2p.etc.types.toVoidCompletableFuture
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.ChannelInboundHandlerAdapter
import io.netty.util.ReferenceCountUtil
import org.apache.logging.log4j.LogManager
import org.slf4j.LoggerFactory
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ScheduledExecutorService

private val logger = LogManager.getLogger(P2PService::class.java)
private val logger = LoggerFactory.getLogger(P2PService::class.java)

/**
* Base class for a service which manages many streams from different peers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import io.libp2p.etc.types.completedExceptionally
import io.libp2p.etc.types.hasCauseOfType
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.ChannelInboundHandlerAdapter
import org.apache.logging.log4j.LogManager
import org.slf4j.LoggerFactory
import java.util.concurrent.CompletableFuture
import java.util.function.Function

typealias MuxChannelInitializer<TData> = (MuxChannel<TData>) -> Unit

private val log = LogManager.getLogger(AbstractMuxHandler::class.java)
private val log = LoggerFactory.getLogger(AbstractMuxHandler::class.java)

abstract class AbstractMuxHandler<TData>() :
ChannelInboundHandlerAdapter() {
Expand Down
4 changes: 2 additions & 2 deletions libp2p/src/main/kotlin/io/libp2p/pubsub/AbstractRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import io.netty.channel.ChannelHandler
import io.netty.handler.codec.protobuf.ProtobufDecoder
import io.netty.handler.codec.protobuf.ProtobufEncoder
import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender
import org.apache.logging.log4j.LogManager
import org.slf4j.LoggerFactory
import pubsub.pb.Rpc
import java.util.Collections.singletonList
import java.util.Optional
Expand All @@ -29,7 +29,7 @@ open class DefaultPubsubMessage(override val protobufMessage: Rpc.Message) : Abs
override val messageId: MessageId = protobufMessage.from.toWBytes() + protobufMessage.seqno.toWBytes()
}

private val logger = LogManager.getLogger(AbstractRouter::class.java)
private val logger = LoggerFactory.getLogger(AbstractRouter::class.java)

/**
* Implements common logic for pubsub routers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.libp2p.core.pubsub.ValidationResult
import io.libp2p.etc.types.*
import io.libp2p.etc.util.P2PService
import io.libp2p.pubsub.*
import org.apache.logging.log4j.LogManager
import org.slf4j.LoggerFactory
import pubsub.pb.Rpc
import java.time.Duration
import java.util.*
Expand Down Expand Up @@ -71,7 +71,7 @@ fun P2PService.PeerHandler.getPeerProtocol(): PubsubProtocol {
return PubsubProtocol.fromProtocol(proto)
}

private val logger = LogManager.getLogger(GossipRouter::class.java)
private val logger = LoggerFactory.getLogger(GossipRouter::class.java)

/**
* Router implementing this protocol: https://github.com/libp2p/specs/tree/master/pubsub/gossipsub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.MessageToMessageCodec
import org.apache.logging.log4j.LogManager
import org.slf4j.LoggerFactory
import java.io.IOException
import java.security.GeneralSecurityException

private val logger = LogManager.getLogger(NoiseXXSecureChannel::class.java.name)
private val logger = LoggerFactory.getLogger(NoiseXXSecureChannel::class.java.name)

class NoiseXXCodec(val aliceCipher: CipherState, val bobCipher: CipherState) :
MessageToMessageCodec<ByteBuf, ByteBuf>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import io.netty.channel.SimpleChannelInboundHandler
import io.netty.handler.codec.LengthFieldBasedFrameDecoder
import io.netty.handler.codec.LengthFieldPrepender
import io.netty.handler.timeout.ReadTimeoutHandler
import org.apache.logging.log4j.LogManager
import org.slf4j.LoggerFactory
import spipe.pb.Spipe
import java.util.concurrent.CompletableFuture

enum class Role(val intVal: Int) { INIT(HandshakeState.INITIATOR), RESP(HandshakeState.RESPONDER) }

private val log = LogManager.getLogger(NoiseXXSecureChannel::class.java)
private val log = LoggerFactory.getLogger(NoiseXXSecureChannel::class.java)
const val HandshakeNettyHandlerName = "HandshakeNettyHandler"
const val HandshakeReadTimeoutNettyHandlerName = "HandshakeReadTimeoutNettyHandler"
const val NoiseCodeNettyHandlerName = "NoiseXXCodec"
Expand Down
Loading