feat: use Logger for logging
This commit is contained in:
@@ -108,13 +108,14 @@ public final class Toad implements AutoCloseable {
|
||||
Optional<IOException> ioException = Optional.empty();
|
||||
Config.Msg.Builder msg = Config.Msg.builder();
|
||||
Optional<DatagramChannel> channel = Optional.empty();
|
||||
Optional<java.util.logging.Level> logLevel = Optional.empty();
|
||||
u8 concurrency = Toad.defaultConfig().concurrency;
|
||||
|
||||
Builder() {}
|
||||
|
||||
public Client buildClient() throws IOException {
|
||||
if (this.ioException.isEmpty()) {
|
||||
var cfg = new Config(this.concurrency, this.msg.build());
|
||||
var cfg = new Config(this.logLevel, this.concurrency, this.msg.build());
|
||||
var toad = new Toad(cfg, this.channel.get());
|
||||
return new Client(toad);
|
||||
} else {
|
||||
@@ -131,6 +132,11 @@ public final class Toad implements AutoCloseable {
|
||||
return this.address(new InetSocketAddress(port));
|
||||
}
|
||||
|
||||
public Builder logLevel(java.util.logging.Level level) {
|
||||
this.logLevel = Optional.of(level);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder address(InetSocketAddress addr) {
|
||||
try {
|
||||
DatagramChannel channel = DatagramChannel.open(
|
||||
@@ -157,10 +163,16 @@ public final class Toad implements AutoCloseable {
|
||||
|
||||
public static final class Config {
|
||||
|
||||
final Optional<java.util.logging.Level> logLevel;
|
||||
final u8 concurrency;
|
||||
final Msg msg;
|
||||
|
||||
Config(u8 concurrency, Msg msg) {
|
||||
Config(
|
||||
Optional<java.util.logging.Level> logLevel,
|
||||
u8 concurrency,
|
||||
Msg msg
|
||||
) {
|
||||
this.logLevel = logLevel;
|
||||
this.concurrency = concurrency;
|
||||
this.msg = msg;
|
||||
}
|
||||
@@ -173,6 +185,10 @@ public final class Toad implements AutoCloseable {
|
||||
};
|
||||
}
|
||||
|
||||
public java.util.logging.Level logLevel() {
|
||||
return this.logLevel.orElse(java.util.logging.Level.INFO);
|
||||
}
|
||||
|
||||
public InetSocketAddress addr() {
|
||||
return this.addr();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import dev.toad.msg.option.ContentFormat
|
||||
import dev.toad.msg.option.Accept
|
||||
import mock.java.nio.channels.Mock
|
||||
import java.net.InetSocketAddress
|
||||
import java.util.logging.Logger
|
||||
import java.util.logging.Level
|
||||
import java.util.ArrayList
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.concurrent.TimeUnit
|
||||
@@ -14,23 +16,12 @@ class E2E extends munit.FunSuite {
|
||||
|
||||
val mock = Mock.Channel()
|
||||
|
||||
val ack = dev.toad.msg.build.Message
|
||||
.builder()
|
||||
.addr(InetSocketAddress("127.0.0.1", 1111))
|
||||
.`type`(Type.ACK)
|
||||
.code(Code.EMPTY)
|
||||
.id(Id(2))
|
||||
.token(Token(Array(1)))
|
||||
.option(ContentFormat.TEXT)
|
||||
.payload("foobar")
|
||||
.build
|
||||
|
||||
val resp = dev.toad.msg.build.Message
|
||||
.builder()
|
||||
.addr(InetSocketAddress("127.0.0.1", 1111))
|
||||
.`type`(Type.NON)
|
||||
.`type`(Type.ACK)
|
||||
.code(Code.OK_CONTENT)
|
||||
.id(Id(3))
|
||||
.id(Id(2))
|
||||
.token(Token(Array(1)))
|
||||
.option(ContentFormat.TEXT)
|
||||
.payload("foobar")
|
||||
@@ -46,7 +37,7 @@ class E2E extends munit.FunSuite {
|
||||
.option(Accept.TEXT)
|
||||
.build
|
||||
|
||||
val client = Toad.builder.channel(mock).buildClient
|
||||
val client = Toad.builder.channel(mock).logLevel(Level.INFO).buildClient
|
||||
val respFuture = client.send(req)
|
||||
|
||||
var bufs = ArrayList[ByteBuffer]()
|
||||
|
||||
Reference in New Issue
Block a user