Skip to content

Commit f33db5a

Browse files
committed
* Add SLF4J to replace logging to stdout (MR fixes)
1 parent 1b54b94 commit f33db5a

File tree

9 files changed

+25
-24
lines changed

9 files changed

+25
-24
lines changed

core/src/main/java/tel/schich/javacan/platform/Platform.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Helper class to detect and handle various platforms. Currently only Linux is handled.
3838
*/
3939
public class Platform {
40-
private static final Logger LOG = LoggerFactory.getLogger(Platform.class);
40+
private static final Logger LOGGER = LoggerFactory.getLogger(Platform.class);
4141

4242
private static final String LIB_PREFIX = "/native";
4343

@@ -77,7 +77,7 @@ public static void loadBundledLib(String name) {
7777
}
7878

7979
final String sourceLibPath = LIB_PREFIX + "/lib" + name + "-" + archSuffix + ".so";
80-
LOG.trace("Loading native library for arch {} from {}", arch, sourceLibPath);
80+
LOGGER.trace("Loading native library for arch {} from {}", arch, sourceLibPath);
8181

8282
try (InputStream libStream = JavaCAN.class.getResourceAsStream(sourceLibPath)) {
8383
if (libStream == null) {

core/src/test/java/tel/schich/javacan/test/isotp/IsotpCanSocketOptionsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,26 @@
3737
import static tel.schich.javacan.test.CanTestHelper.CAN_INTERFACE;
3838

3939
public class IsotpCanSocketOptionsTest {
40-
private static final Logger LOG = LoggerFactory.getLogger(IsotpCanSocketOptionsTest.class);
40+
private static final Logger LOGGER = LoggerFactory.getLogger(IsotpCanSocketOptionsTest.class);
4141

4242
@Test
4343
void testOptions() throws IOException {
4444
try (final IsotpCanChannel a = CanChannels.newIsotpChannel()) {
4545
IsotpOptions opts = a.getOption(OPTS);
46-
LOG.debug(String.valueOf(opts));
46+
LOGGER.debug(String.valueOf(opts));
4747
IsotpOptions customizedOpts = IsotpOptions.DEFAULT.withPadding(0xAA);
4848
a.setOption(OPTS, customizedOpts);
4949
assertEquals(customizedOpts, a.getOption(OPTS), "What goes in should come out");
5050

5151
IsotpFlowControlOptions flowControlOpts = a.getOption(RECV_FC);
52-
LOG.debug(String.valueOf(flowControlOpts));
52+
LOGGER.debug(String.valueOf(flowControlOpts));
5353
IsotpFlowControlOptions customizedFlowControlOpts = IsotpFlowControlOptions.DEFAULT
5454
.withBlockSize(1);
5555
a.setOption(RECV_FC, customizedFlowControlOpts);
5656
assertEquals(customizedFlowControlOpts, a.getOption(RECV_FC), "What goes in should come out");
5757

5858
IsotpLinkLayerOptions linkLayerOpts = a.getOption(LL_OPTS);
59-
LOG.debug(String.valueOf(linkLayerOpts));
59+
LOGGER.debug(String.valueOf(linkLayerOpts));
6060
IsotpLinkLayerOptions customizedLinkLayerOpts = IsotpLinkLayerOptions.DEFAULT
6161
.withTransmissionFlags(CanFrame.FD_FLAG_BIT_RATE_SWITCH);
6262
a.setOption(LL_OPTS, customizedLinkLayerOpts);

epoll/src/main/java/tel/schich/javacan/util/CanBroker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* Frames can be send either to individual interfaces or all at once.
5959
*/
6060
public class CanBroker extends EventLoop<UnixFileDescriptor, RawCanChannel> {
61-
private static final Logger LOG = LoggerFactory.getLogger(CanBroker.class);
61+
private static final Logger LOGGER = LoggerFactory.getLogger(CanBroker.class);
6262

6363
public static final Duration DEFAULT_TIMEOUT = ofMinutes(1);
6464
private static final CanFilter[] NO_FILTERS = { CanFilter.NONE };
@@ -274,10 +274,10 @@ protected void processEvents(List<IOEvent<UnixFileDescriptor>> events) throws IO
274274
readBuffer.clear();
275275
handler.handle(raw, raw.read(readBuffer));
276276
} else {
277-
LOG.warn("Handler not found for channel: " + ch);
277+
LOGGER.warn("Handler not found for channel: " + ch);
278278
}
279279
} else {
280-
LOG.warn("Unsupported channel: " + ch);
280+
LOGGER.warn("Unsupported channel: " + ch);
281281
}
282282
}
283283
}

epoll/src/main/java/tel/schich/javacan/util/EventLoop.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import java.util.concurrent.ThreadFactory;
4242

4343
public abstract class EventLoop<HandleType, ChannelType extends Channel> implements Closeable {
44-
private static final Logger LOG = LoggerFactory.getLogger(CanBroker.class);
44+
private static final Logger LOGGER = LoggerFactory.getLogger(CanBroker.class);
4545

4646
private final String name;
4747

@@ -207,13 +207,13 @@ protected final boolean poll(Duration timeout) throws IOException {
207207
* @return true if the event loop should continue, false for the event loop to exit
208208
*/
209209
protected boolean handleException(Thread thread, Throwable t, boolean terminal) {
210-
LOG.error("Polling thread failed: " + thread.getName(), t);
211-
LOG.warn("Terminating other threads.");
210+
LOGGER.error("Polling thread failed: " + thread.getName(), t);
211+
LOGGER.warn("Terminating other threads.");
212212

213213
try {
214214
shutdown();
215215
} catch (InterruptedException e) {
216-
LOG.error("Got interrupted while stopping the threads");
216+
LOGGER.error("Got interrupted while stopping the threads");
217217
}
218218

219219
return true;

epoll/src/main/java/tel/schich/javacan/util/IsotpListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* for for each specific channel.
4646
*/
4747
public class IsotpListener extends EventLoop<UnixFileDescriptor, IsotpCanChannel> {
48-
private static final Logger LOG = LoggerFactory.getLogger(CanBroker.class);
48+
private static final Logger LOGGER = LoggerFactory.getLogger(CanBroker.class);
4949

5050
private final ByteBuffer readBuffer = IsotpCanChannel.allocateSufficientMemory();
5151

@@ -126,10 +126,10 @@ protected void processEvents(List<IOEvent<UnixFileDescriptor>> events) throws IO
126126
readBuffer.flip();
127127
handler.handle(isotp, readBuffer.asReadOnlyBuffer());
128128
} else {
129-
LOG.warn("Handler not found for channel: " + ch);
129+
LOGGER.warn("Handler not found for channel: " + ch);
130130
}
131131
} else {
132-
LOG.warn("Unsupported channel: " + ch);
132+
LOGGER.warn("Unsupported channel: " + ch);
133133
}
134134
}
135135
}

epoll/src/test/java/tel/schich/javacan/test/select/EPollSelectorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import static tel.schich.javacan.test.CanTestHelper.runDelayed;
5151

5252
public class EPollSelectorTest {
53-
private static final Logger LOG = LoggerFactory.getLogger(EPollSelectorTest.class);
53+
private static final Logger LOGGER = LoggerFactory.getLogger(EPollSelectorTest.class);
5454

5555
@Test
5656
public void testOpenClose() throws IOException {
@@ -131,12 +131,12 @@ public void testEPollFdReuse() throws IOException, InterruptedException {
131131

132132
private static SelectorRegistration<UnixFileDescriptor, RawCanChannel> configureAndRegisterChannel(IOSelector<UnixFileDescriptor> selector) throws IOException {
133133
final RawCanChannel ch = CanChannels.newRawChannel(CAN_INTERFACE);
134-
LOG.debug("Created channel: " + ch);
134+
LOGGER.debug("Created channel: " + ch);
135135

136136
ch.configureBlocking(false);
137137
ch.setOption(CanSocketOptions.LOOPBACK, true);
138138
SelectorRegistration<UnixFileDescriptor, RawCanChannel> registration = selector.register(ch, SelectorRegistration.Operation.READ);
139-
LOG.debug("Selection key: " + registration);
139+
LOGGER.debug("Selection key: " + registration);
140140

141141
return registration;
142142
}

epoll/src/test/java/tel/schich/javacan/test/util/CanBrokerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import static org.junit.jupiter.api.Assertions.assertNotNull;
4242

4343
class CanBrokerTest {
44-
private static final Logger LOG = LoggerFactory.getLogger(CanBrokerTest.class);
44+
private static final Logger LOGGER = LoggerFactory.getLogger(CanBrokerTest.class);
4545

4646
private static final ThreadFactory FACTORY = r -> {
4747
Thread t = new Thread(r);
@@ -72,7 +72,7 @@ void testLoopback() throws Exception {
7272
});
7373

7474
brokerB.addDevice(CanTestHelper.CAN_INTERFACE, (d, frame) -> {
75-
LOG.debug(String.valueOf(frame));
75+
LOGGER.debug(String.valueOf(frame));
7676
});
7777
brokerB.send(expected);
7878

epoll/src/test/java/tel/schich/javacan/test/util/IsotpListenerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import static tel.schich.javacan.IsotpAddress.*;
4848

4949
class IsotpListenerTest {
50-
private static final Logger LOG = LoggerFactory.getLogger(IsotpListenerTest.class);
50+
private static final Logger LOGGER = LoggerFactory.getLogger(IsotpListenerTest.class);
5151

5252
@Test
5353
void testBroker() throws Exception {
@@ -108,7 +108,7 @@ public PingPing(Lock lock, Condition condition, ByteBuffer buf) {
108108
public void handle(IsotpCanChannel ch, ByteBuffer buffer) {
109109
int length = buffer.remaining();
110110
if (length % 200 == 0) {
111-
LOG.debug(String.format("(%04d) -> %08X#%s%n", length, ch.getTxAddress().getId(), CanUtils.hexDump(buffer)));
111+
LOGGER.debug(String.format("(%04d) -> %08X#%s%n", length, ch.getTxAddress().getId(), CanUtils.hexDump(buffer)));
112112
}
113113
buf.clear();
114114
buf.put(buffer);
@@ -118,7 +118,7 @@ public void handle(IsotpCanChannel ch, ByteBuffer buffer) {
118118
ch.write(buf);
119119
} catch (Exception e) {
120120
assertEquals(IllegalArgumentException.class, e.getClass());
121-
LOG.debug("Failed to send message", e);
121+
LOGGER.debug("Failed to send message", e);
122122
lock.lock();
123123
try {
124124
condition.signalAll();

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<groupId>ch.qos.logback</groupId>
9191
<artifactId>logback-classic</artifactId>
9292
<version>${logback.version}</version>
93+
<scope>test</scope>
9394
</dependency>
9495
</dependencies>
9596
</dependencyManagement>

0 commit comments

Comments
 (0)