From: Robert Varga Date: Fri, 15 May 2015 20:33:45 +0000 (+0200) Subject: Fix Logger use X-Git-Tag: release/lithium~31 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=272138f7081efbd9796a2a661c92c88727935235;p=openflowjava.git Fix Logger use Cleanup use of Loggers so we do not concatenate strings, and also check if the logging leve is enabled before embarking on creating large strings. Change-Id: I9f0f513f8cd4857ab7064ed5b824a01b026b831f Signed-off-by: Robert Varga --- diff --git a/openflow-protocol-api/pom.xml b/openflow-protocol-api/pom.xml index faf463ac..34c9e9c0 100644 --- a/openflow-protocol-api/pom.xml +++ b/openflow-protocol-api/pom.xml @@ -65,7 +65,6 @@ org.apache.maven.plugins maven-antrun-plugin - 1.7 prepare-package diff --git a/openflow-protocol-impl/pom.xml b/openflow-protocol-impl/pom.xml index 23d0e9fb..ec72b1d8 100644 --- a/openflow-protocol-impl/pom.xml +++ b/openflow-protocol-impl/pom.xml @@ -81,7 +81,6 @@ org.apache.maven.plugins maven-jar-plugin - 2.5 diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFDatagramPacketDecoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFDatagramPacketDecoder.java index 670f552c..3a083eea 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFDatagramPacketDecoder.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFDatagramPacketDecoder.java @@ -10,7 +10,6 @@ package org.opendaylight.openflowjava.protocol.impl.core; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; - import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer; import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory; import org.opendaylight.openflowjava.util.ByteBufUtils; @@ -28,15 +27,15 @@ public class OFDatagramPacketDecoder extends SimpleChannelInboundHandler { private static final Logger LOGGER = LoggerFactory.getLogger(OFDecoder.class); + private final StatisticsCounters statisticsCounter; + + // TODO: make this final? private DeserializationFactory deserializationFactory; - private StatisticsCounters statisticsCounter; + /** * Constructor of class */ public OFDecoder() { LOGGER.trace("Creating OF 1.3 Decoder"); + // TODO: pass as argument statisticsCounter = StatisticsCounters.getInstance(); } @@ -44,12 +48,11 @@ public class OFDecoder extends MessageToMessageDecoder { statisticsCounter.incrementCounter(CounterEventTypes.US_RECEIVED_IN_OFJAVA); if (LOGGER.isDebugEnabled()) { LOGGER.debug("VersionMessageWrapper received"); - LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(msg.getMessageBuffer())); + LOGGER.debug("<< {}", ByteBufUtils.byteBufToHexString(msg.getMessageBuffer())); } - DataObject dataObject = null; try { - dataObject = deserializationFactory.deserialize(msg.getMessageBuffer(), + final DataObject dataObject = deserializationFactory.deserialize(msg.getMessageBuffer(), msg.getVersion()); if (dataObject == null) { LOGGER.warn("Translated POJO is null"); @@ -58,9 +61,8 @@ public class OFDecoder extends MessageToMessageDecoder { out.add(dataObject); statisticsCounter.incrementCounter(CounterEventTypes.US_DECODE_SUCCESS); } - } catch(Exception e) { - LOGGER.warn("Message deserialization failed"); - LOGGER.warn(e.getMessage(), e); + } catch (Exception e) { + LOGGER.warn("Message deserialization failed", e); statisticsCounter.incrementCounter(CounterEventTypes.US_DECODE_FAIL); } finally { msg.getMessageBuffer().release(); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java index 5c3b7616..f4ec8825 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java @@ -67,8 +67,8 @@ public class OFFrameDecoder extends ByteToMessageDecoder { int readableBytes = bb.readableBytes(); if (readableBytes < LENGTH_OF_HEADER) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("skipping bytebuf - too few bytes for header: " + readableBytes + " < " + LENGTH_OF_HEADER ); - LOGGER.debug("bb: " + ByteBufUtils.byteBufToHexString(bb)); + LOGGER.debug("skipping bytebuf - too few bytes for header: {} < {}", readableBytes, LENGTH_OF_HEADER); + LOGGER.debug("bb: {}", ByteBufUtils.byteBufToHexString(bb)); } return; } @@ -78,9 +78,8 @@ public class OFFrameDecoder extends ByteToMessageDecoder { if (readableBytes < length) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("skipping bytebuf - too few bytes for msg: " + - readableBytes + " < " + length); - LOGGER.debug("bytebuffer: " + ByteBufUtils.byteBufToHexString(bb)); + LOGGER.debug("skipping bytebuf - too few bytes for msg: {} < {}", readableBytes, length); + LOGGER.debug("bytebuffer: {}", ByteBufUtils.byteBufToHexString(bb)); } return; } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpChannelInitializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpChannelInitializer.java index 8282f078..43277eaa 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpChannelInitializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/TcpChannelInitializer.java @@ -58,8 +58,8 @@ public class TcpChannelInitializer extends ProtocolChannelInitializer :" + port); + LOGGER.debug("Incoming connection from (remote address): {}:{} --> :{}", + switchAddress.toString(), remotePort, port); if (!getSwitchConnectionHandler().accept(switchAddress)) { ch.disconnect(); @@ -72,7 +72,7 @@ public class TcpChannelInitializer extends ProtocolChannelInitializer actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, diff --git a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/IntegrationTest.java b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/IntegrationTest.java index 3eedff52..54ccb37e 100644 --- a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/IntegrationTest.java +++ b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/IntegrationTest.java @@ -69,7 +69,7 @@ public class IntegrationTest { LOGGER.debug("\n starting test -------------------------------"); String currentDir = System.getProperty("user.dir"); - LOGGER.debug("Current dir using System:" +currentDir); + LOGGER.debug("Current dir using System: {}", currentDir); startupAddress = InetAddress.getLocalHost(); tlsConfiguration = null; if (protocol.equals(TransportProtocol.TLS)) { @@ -221,7 +221,7 @@ public class IntegrationTest { TransportProtocol protocol, ClientType clientType) throws ExecutionException { List clientsHorde = new ArrayList<>(); for (int i = 0; i < amountOfCLients; i++) { - LOGGER.debug("startup address in createclient: " + startupAddress.getHostAddress()); + LOGGER.debug("startup address in createclient: {}", startupAddress.getHostAddress()); OFClient sc = null; if (clientType == ClientType.SIMPLE) { if (protocol.equals(TransportProtocol.TCP)) { diff --git a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/MockPlugin.java b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/MockPlugin.java index f09da22c..dadfa73c 100644 --- a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/MockPlugin.java +++ b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/MockPlugin.java @@ -61,12 +61,12 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan public MockPlugin() { LOGGER.trace("Creating MockPlugin"); finishedFuture = SettableFuture.create(); - LOGGER.debug("mockPlugin: "+System.identityHashCode(this)); + LOGGER.debug("mockPlugin: {}", System.identityHashCode(this)); } @Override public void onSwitchConnected(ConnectionAdapter connection) { - LOGGER.debug("onSwitchConnected: " + connection); + LOGGER.debug("onSwitchConnected: {}", connection); this.adapter = connection; connection.setMessageListener(this); connection.setSystemListener(this); @@ -75,25 +75,25 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan @Override public boolean accept(InetAddress switchAddress) { - LOGGER.debug("MockPlugin.accept(): " + switchAddress.toString()); + LOGGER.debug("MockPlugin.accept(): {}", switchAddress.toString()); return true; } @Override public void onEchoRequestMessage(final EchoRequestMessage notification) { - LOGGER.debug("MockPlugin.onEchoRequestMessage() adapter: "+adapter); + LOGGER.debug("MockPlugin.onEchoRequestMessage() adapter: {}", adapter); new Thread(new Runnable() { @Override public void run() { - LOGGER.debug("MockPlugin.onEchoRequestMessage().run() started adapter: "+adapter); + LOGGER.debug("MockPlugin.onEchoRequestMessage().run() started adapter: {}", adapter); EchoReplyInputBuilder replyBuilder = new EchoReplyInputBuilder(); replyBuilder.setVersion((short) 4); replyBuilder.setXid(notification.getXid()); EchoReplyInput echoReplyInput = replyBuilder.build(); adapter.echoReply(echoReplyInput); LOGGER.debug("adapter.EchoReply(Input) sent : ", echoReplyInput.toString()); - LOGGER.debug("MockPlugin.onEchoRequestMessage().run() finished adapter: "+adapter); + LOGGER.debug("MockPlugin.onEchoRequestMessage().run() finished adapter: {}", adapter); } }).start(); } @@ -151,11 +151,10 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan if (rpcResult.isSuccessful()) { byte[] byteArray = rpcResult.getResult().getDatapathId() .toByteArray(); - LOGGER.debug("DatapathId: " + Arrays.toString(byteArray)); + LOGGER.debug("DatapathId: {}", Arrays.toString(byteArray)); } else { RpcError rpcError = rpcResult.getErrors().iterator().next(); - LOGGER.warn("rpcResult failed: " - + rpcError.getCause().getMessage(), rpcError.getCause()); + LOGGER.warn("rpcResult failed", rpcError.getCause()); } } catch (InterruptedException | ExecutionException | TimeoutException e) { LOGGER.error("getSwitchFeatures() exception caught: ", e.getMessage(), e); @@ -164,7 +163,7 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan protected void shutdown() { try { - LOGGER.debug("MockPlugin.shutdown() sleeping 5... : "+System.identityHashCode(this)); + LOGGER.debug("MockPlugin.shutdown() sleeping 5... : {}", System.identityHashCode(this)); Thread.sleep(500); if (adapter != null) { Future disconnect = adapter.disconnect(); @@ -186,14 +185,14 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan @Override public void onPacketInMessage(PacketInMessage notification) { LOGGER.debug("PacketIn message received"); - LOGGER.debug("BufferId: " + notification.getBufferId()); - LOGGER.debug("TotalLength: " + notification.getTotalLen()); - LOGGER.debug("Reason: " + notification.getReason()); - LOGGER.debug("TableId: " + notification.getTableId()); - LOGGER.debug("Cookie: " + notification.getCookie()); - LOGGER.debug("Class: " + notification.getMatch().getMatchEntry().get(0).getOxmClass()); - LOGGER.debug("Field: " + notification.getMatch().getMatchEntry().get(0).getOxmMatchField()); - LOGGER.debug("Datasize: " + notification.getData().length); + LOGGER.debug("BufferId: {}", notification.getBufferId()); + LOGGER.debug("TotalLength: {}", notification.getTotalLen()); + LOGGER.debug("Reason: {}", notification.getReason()); + LOGGER.debug("TableId: {}", notification.getTableId()); + LOGGER.debug("Cookie: {}", notification.getCookie()); + LOGGER.debug("Class: {}", notification.getMatch().getMatchEntry().get(0).getOxmClass()); + LOGGER.debug("Field: {}", notification.getMatch().getMatchEntry().get(0).getOxmMatchField()); + LOGGER.debug("Datasize: {}", notification.getData().length); } @Override @@ -204,7 +203,7 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan @Override public void onDisconnectEvent(DisconnectEvent notification) { - LOGGER.debug("disconnection occured: "+notification.getInfo()); + LOGGER.debug("disconnection occured: {}", notification.getInfo()); } /** @@ -216,7 +215,7 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan @Override public void onSwitchIdleEvent(SwitchIdleEvent notification) { - LOGGER.debug("MockPlugin.onSwitchIdleEvent() switch status: "+notification.getInfo()); + LOGGER.debug("MockPlugin.onSwitchIdleEvent() switch status: {}", notification.getInfo()); idleCounter ++; } diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java index b7cf3de0..57865d88 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java @@ -45,7 +45,7 @@ public class ScenarioHandler extends Thread { public void run() { int freezeCounter = 0; while (!scenario.isEmpty()) { - LOGGER.debug("Running event #" + eventNumber); + LOGGER.debug("Running event #{}", eventNumber); ClientEvent peek = scenario.peekLast(); if (peek instanceof WaitForMessageEvent) { LOGGER.debug("WaitForMessageEvent"); @@ -69,7 +69,7 @@ public class ScenarioHandler extends Thread { freezeCounter++; } if (freezeCounter > 2) { - LOGGER.warn("Scenario freezed: " + freezeCounter); + LOGGER.warn("Scenario frozen: {}", freezeCounter); break; } try { diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java index c5765272..3f456d12 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java @@ -43,8 +43,11 @@ public class SendEvent implements ClientEvent { ByteBuf buffer = ctx.alloc().buffer(); buffer.writeBytes(msgToSend); ctx.writeAndFlush(buffer); - LOGGER.debug(">> " + ByteBufUtils.bytesToHexString(msgToSend)); - LOGGER.debug("message sent"); + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(">> {}", ByteBufUtils.bytesToHexString(msgToSend)); + LOGGER.debug("message sent"); + } return true; } diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java index b097b1d1..5e98e3d6 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java @@ -115,8 +115,7 @@ public class SimpleClient implements OFClient { int port; SimpleClient sc; if (args.length != 3) { - LOGGER.error("Usage: " + SimpleClient.class.getSimpleName() - + " "); + LOGGER.error("Usage: {} ", SimpleClient.class.getSimpleName()); LOGGER.error("Trying to use default setting."); InetAddress ia = InetAddress.getLocalHost(); InetAddress[] all = InetAddress.getAllByName(ia.getHostName()); @@ -147,4 +146,4 @@ public class SimpleClient implements OFClient { public void setScenarioHandler(ScenarioHandler scenario) { this.scenarioHandler = scenario; } -} \ No newline at end of file +} diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientFramer.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientFramer.java index a1ade557..1420ad8d 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientFramer.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientFramer.java @@ -46,14 +46,13 @@ public class SimpleClientFramer extends ByteToMessageDecoder { @Override protected void decode(ChannelHandlerContext chc, ByteBuf bb, List list) throws Exception { if (bb.readableBytes() < LENGTH_OF_HEADER) { - LOGGER.debug("skipping bb - too few data for header: " + bb.readableBytes()); + LOGGER.debug("skipping bb - too few data for header: {}", bb.readableBytes()); return; } int length = bb.getUnsignedShort(bb.readerIndex() + LENGTH_INDEX_IN_HEADER); if (bb.readableBytes() < length) { - LOGGER.debug("skipping bb - too few data for msg: " + - bb.readableBytes() + " < " + length); + LOGGER.debug("skipping bb - too few data for msg: {} < {}", bb.readableBytes(), length); return; } LOGGER.debug("OF Protocol message received, type:{}", bb.getByte(bb.readerIndex() + 1)); diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java index 01e114bf..acc53834 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java @@ -43,7 +43,7 @@ public class SimpleClientHandler extends ChannelInboundHandlerAdapter { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf bb = (ByteBuf) msg; if (LOGGER.isDebugEnabled()) { - LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(bb)); + LOGGER.debug("<< {}", ByteBufUtils.byteBufToHexString(bb)); } int length = bb.getUnsignedShort(bb.readerIndex() + LENGTH_INDEX_IN_HEADER); LOGGER.trace("SimpleClientHandler - start of read"); diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/UdpSimpleClient.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/UdpSimpleClient.java index e9d69da1..e9d4644e 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/UdpSimpleClient.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/UdpSimpleClient.java @@ -111,8 +111,7 @@ public class UdpSimpleClient implements OFClient { int port; UdpSimpleClient sc; if (args.length != 2) { - LOGGER.error("Usage: " + UdpSimpleClient.class.getSimpleName() - + " "); + LOGGER.error("Usage: {} ", UdpSimpleClient.class.getSimpleName()); LOGGER.error("Trying to use default setting."); InetAddress ia = InetAddress.getLocalHost(); InetAddress[] all = InetAddress.getAllByName(ia.getHostName()); @@ -147,4 +146,4 @@ public class UdpSimpleClient implements OFClient { public void setSecuredClient(boolean securedClient) { // TODO: Finish implementation when DTLS is supported } -} \ No newline at end of file +} diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/UdpSimpleClientFramer.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/UdpSimpleClientFramer.java index d5f8e7be..be73d27c 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/UdpSimpleClientFramer.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/UdpSimpleClientFramer.java @@ -48,14 +48,13 @@ public class UdpSimpleClientFramer extends MessageToMessageDecoder list) throws Exception { ByteBuf bb = msg.content(); if (bb.readableBytes() < LENGTH_OF_HEADER) { - LOGGER.debug("skipping bb - too few data for header: " + bb.readableBytes()); + LOGGER.debug("skipping bb - too few data for header: {}", bb.readableBytes()); return; } int length = bb.getUnsignedShort(bb.readerIndex() + LENGTH_INDEX_IN_HEADER); if (bb.readableBytes() < length) { - LOGGER.debug("skipping bb - too few data for msg: " + - bb.readableBytes() + " < " + length); + LOGGER.debug("skipping bb - too few data for msg: {} < {}", bb.readableBytes(), length); return; } LOGGER.debug("OF Protocol message received, type:{}", bb.getByte(bb.readerIndex() + 1)); @@ -65,4 +64,4 @@ public class UdpSimpleClientFramer extends MessageToMessageDecoder