Skip to content

Commit

Permalink
add logging examples
Browse files Browse the repository at this point in the history
  • Loading branch information
amarziali committed Aug 17, 2022
1 parent b37bb60 commit 44bc045
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.36</version>
<scope>runtime</scope>
</dependency>

</dependencies>
<build>
Expand Down
20 changes: 12 additions & 8 deletions src/test/java/com/hurence/opc/da/OpcDaTemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.junit.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;

import java.net.URI;
import java.time.Duration;
Expand All @@ -51,6 +52,10 @@
*/
@Ignore
public class OpcDaTemplateTest {
static {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
}

private final Logger logger = LoggerFactory.getLogger(OpcDaTemplateTest.class);

Expand Down Expand Up @@ -132,12 +137,12 @@ public void testSampling_Poll() throws Exception {
.withRefreshInterval(Duration.ofMillis(300));

List<Timed<OpcData>> received = Flowable.combineLatest(
Flowable.interval(10, TimeUnit.MILLISECONDS),
opcDaOperations.createSession(sessionProfile).toFlowable()
.flatMap(session -> session.stream("Square Waves.Real8", Duration.ofMillis(10))
.doFinally(session::close)
Flowable.interval(10, TimeUnit.MILLISECONDS),
opcDaOperations.createSession(sessionProfile).toFlowable()
.flatMap(session -> session.stream("Square Waves.Real8", Duration.ofMillis(10))
.doFinally(session::close)

), (a, b) -> b)
), (a, b) -> b)
.sample(10, TimeUnit.MILLISECONDS)
.timeInterval()
.limit(100)
Expand Down Expand Up @@ -285,8 +290,8 @@ public void listenToAll() throws Exception {
try (OpcDaSession session = opcDaOperations.createSession(sessionProfile).blockingGet()) {
List<OpcTagInfo> tagList = opcDaOperations.browseTags().toList().blockingGet();
Flowable.merge(Flowable.fromArray(tagList.toArray(new OpcTagInfo[tagList.size()]))
.map(tagInfo -> session.stream(tagInfo.getId(), Duration.ofMillis(100)))
)
.map(tagInfo -> session.stream(tagInfo.getId(), Duration.ofMillis(100)))
)
.doOnNext(data -> logger.info("{}", data))
.limit(1000)
.subscribeOn(Schedulers.io())
Expand Down Expand Up @@ -419,7 +424,6 @@ public void testAutoReconnect() throws Exception {
subscriber.assertComplete();
subscriber.assertValueCount(50);
subscriber.dispose();

}


Expand Down
16 changes: 16 additions & 0 deletions src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>

<logger name="rpc" level="warn" />

<root level="info">
<appender-ref ref="CONSOLE"/>
</root>

</configuration>

0 comments on commit 44bc045

Please sign in to comment.