Skip to content

Commit 1cd813f

Browse files
authored
KTOR log level can be set (#448)
1 parent 558784f commit 1cd813f

File tree

8 files changed

+30
-33
lines changed

8 files changed

+30
-33
lines changed

examples/tutorial/src/main/kotlin/jp/co/soramitsu/iroha2/Main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fun main(args: Array<String>): Unit = runBlocking {
1515
"9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e",
1616
)
1717

18-
val client = AdminIroha2Client(URL(peerUrl), URL(peerUrl), URL(telemetryUrl), log = true)
18+
val client = AdminIroha2Client(URL(peerUrl), URL(peerUrl), URL(telemetryUrl))
1919
val query = Query(client, admin, adminKeyPair)
2020
query.findAllDomains()
2121
.also { println("ALL DOMAINS: ${it.map { d -> d.id.asString() }}") }

modules/admin-client/src/main/kotlin/jp/co/soramitsu/iroha2/AdminIroha2AsyncClient.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package jp.co.soramitsu.iroha2
22

3+
import io.ktor.client.plugins.logging.LogLevel
34
import jp.co.soramitsu.iroha2.model.IrohaUrls
45
import kotlinx.coroutines.future.future
56

@@ -9,9 +10,9 @@ import kotlinx.coroutines.future.future
910
@Suppress("unused")
1011
class AdminIroha2AsyncClient @JvmOverloads constructor(
1112
urls: List<IrohaUrls>,
12-
log: Boolean = false,
13+
httpLogLevel: LogLevel = LogLevel.NONE,
1314
credentials: String? = null,
14-
) : AdminIroha2Client(urls, log, credentials) {
15+
) : AdminIroha2Client(urls, httpLogLevel, credentials) {
1516

1617
/**
1718
* Send health check request

modules/admin-client/src/main/kotlin/jp/co/soramitsu/iroha2/AdminIroha2Client.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package jp.co.soramitsu.iroha2
22

33
import io.ktor.client.call.body
4+
import io.ktor.client.plugins.logging.LogLevel
45
import io.ktor.client.request.get
56
import io.ktor.client.request.setBody
67
import io.ktor.client.statement.HttpResponse
@@ -18,35 +19,35 @@ import java.net.URL
1819
@Suppress("unused")
1920
open class AdminIroha2Client(
2021
urls: List<IrohaUrls>,
21-
log: Boolean = false,
22+
httpLogLevel: LogLevel = LogLevel.NONE,
2223
credentials: String? = null,
2324
private val balancingHealthCheck: Boolean = true,
24-
) : Iroha2Client(urls, log, credentials) {
25+
) : Iroha2Client(urls, httpLogLevel, credentials) {
2526

2627
constructor(
2728
url: IrohaUrls,
28-
log: Boolean = false,
29+
httpLogLevel: LogLevel = LogLevel.NONE,
2930
credentials: String? = null,
3031
balancingHealthCheck: Boolean = true,
31-
) : this(mutableListOf(url), log, credentials, balancingHealthCheck)
32+
) : this(mutableListOf(url), httpLogLevel, credentials, balancingHealthCheck)
3233

3334
constructor(
3435
apiUrl: URL,
3536
telemetryUrl: URL,
3637
peerUrl: URL,
37-
log: Boolean = false,
38+
httpLogLevel: LogLevel = LogLevel.NONE,
3839
credentials: String? = null,
3940
balancingHealthCheck: Boolean = true,
40-
) : this(IrohaUrls(apiUrl, telemetryUrl, peerUrl), log, credentials, balancingHealthCheck)
41+
) : this(IrohaUrls(apiUrl, telemetryUrl, peerUrl), httpLogLevel, credentials, balancingHealthCheck)
4142

4243
constructor(
4344
apiUrl: String,
4445
telemetryUrl: String,
4546
peerUrl: String,
46-
log: Boolean = false,
47+
httpLogLevel: LogLevel = LogLevel.NONE,
4748
credentials: String? = null,
4849
balancingHealthCheck: Boolean = true,
49-
) : this(URL(apiUrl), URL(telemetryUrl), URL(peerUrl), log, credentials, balancingHealthCheck)
50+
) : this(URL(apiUrl), URL(telemetryUrl), URL(peerUrl), httpLogLevel, credentials, balancingHealthCheck)
5051

5152
/**
5253
* Send metrics request

modules/block/src/test/kotlin/jp/co/soramitsu/iroha2/DeserializerTest.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ class DeserializerTest {
1313
val block = JSON_SERDE.convertValue(node, RawGenesisBlock::class.java)
1414

1515
assert(block.transactions.isNotEmpty())
16-
// genesis.json has 12 instructions ("isi")
17-
// Register -> NewDomain
18-
// Register -> NewAccount (2)
19-
// Register -> NewAssetDefinition
20-
// Grant -> PermissionToken (2)
21-
// Mint -> AssetId (2)
22-
// Register -> Trigger (4)
23-
assert(block.transactions.flatten().size == 12)
2416

2517
val genesis = Genesis(block)
2618
val newJson = removeWhiteSpaceAndReplacePubKey(genesis.asJson())
@@ -93,7 +85,8 @@ class DeserializerTest {
9385

9486
private fun removeWhiteSpaceAndReplacePubKey(json: String): String {
9587
val regex = "(\"ed01)+\\w+\"".toRegex()
96-
return json.replace(System.getProperty("line.separator"), "")
88+
return json
89+
.replace(System.getProperty("line.separator"), "")
9790
.replace(" ", "")
9891
.replace(regex, "publicKey")
9992
}

modules/client/src/main/kotlin/jp/co/soramitsu/iroha2/client/Iroha2AsyncClient.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package jp.co.soramitsu.iroha2.client
22

3+
import io.ktor.client.plugins.logging.LogLevel
34
import jp.co.soramitsu.iroha2.generated.SignedTransaction
45
import jp.co.soramitsu.iroha2.model.IrohaUrls
56
import jp.co.soramitsu.iroha2.query.QueryAndExtractor
@@ -14,11 +15,11 @@ import java.util.concurrent.CompletableFuture
1415
@Suppress("unused")
1516
class Iroha2AsyncClient @JvmOverloads constructor(
1617
urls: List<IrohaUrls>,
17-
log: Boolean = false,
18+
httpLogLevel: LogLevel = LogLevel.NONE,
1819
credentials: String? = null,
1920
eventReadTimeoutInMills: Long = 250,
2021
eventReadMaxAttempts: Int = 10,
21-
) : Iroha2Client(urls, log, credentials, eventReadTimeoutInMills, eventReadMaxAttempts) {
22+
) : Iroha2Client(urls, httpLogLevel, credentials, eventReadTimeoutInMills, eventReadMaxAttempts) {
2223

2324
/**
2425
* Send a request to Iroha2 and extract payload.

modules/client/src/main/kotlin/jp/co/soramitsu/iroha2/client/Iroha2Client.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import io.ktor.client.plugins.auth.Auth
1717
import io.ktor.client.plugins.auth.providers.BasicAuthCredentials
1818
import io.ktor.client.plugins.auth.providers.basic
1919
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
20+
import io.ktor.client.plugins.logging.LogLevel
2021
import io.ktor.client.plugins.logging.Logging
2122
import io.ktor.client.plugins.websocket.WebSockets
2223
import io.ktor.client.plugins.websocket.webSocket
@@ -83,7 +84,7 @@ import kotlin.coroutines.CoroutineContext
8384
@Suppress("unused")
8485
open class Iroha2Client(
8586
open val urls: List<IrohaUrls>,
86-
open val log: Boolean = false,
87+
open val httpLogLevel: LogLevel = LogLevel.NONE,
8788
open val credentials: String? = null,
8889
open val eventReadTimeoutInMills: Long = 250,
8990
open val eventReadMaxAttempts: Int = 10,
@@ -92,23 +93,23 @@ open class Iroha2Client(
9293

9394
constructor(
9495
url: IrohaUrls,
95-
log: Boolean = false,
96+
httpLogLevel: LogLevel = LogLevel.NONE,
9697
credentials: String? = null,
9798
eventReadTimeoutInMills: Long = 250,
9899
eventReadMaxAttempts: Int = 10,
99-
) : this(mutableListOf(url), log, credentials, eventReadTimeoutInMills, eventReadMaxAttempts)
100+
) : this(mutableListOf(url), httpLogLevel, credentials, eventReadTimeoutInMills, eventReadMaxAttempts)
100101

101102
constructor(
102103
apiUrl: URL,
103104
telemetryUrl: URL,
104105
peerUrl: URL,
105-
log: Boolean = false,
106+
httpLogLevel: LogLevel = LogLevel.NONE,
106107
credentials: String? = null,
107108
eventReadTimeoutInMills: Long = 250,
108109
eventReadMaxAttempts: Int = 10,
109110
) : this(
110111
IrohaUrls(apiUrl, telemetryUrl, peerUrl),
111-
log,
112+
httpLogLevel,
112113
credentials,
113114
eventReadTimeoutInMills,
114115
eventReadMaxAttempts,
@@ -118,15 +119,15 @@ open class Iroha2Client(
118119
apiUrl: String,
119120
telemetryUrl: String,
120121
peerUrl: String,
121-
log: Boolean = true,
122+
httpLogLevel: LogLevel = LogLevel.NONE,
122123
credentials: String? = null,
123124
eventReadTimeoutInMills: Long = 250,
124125
eventReadMaxAttempts: Int = 10,
125126
) : this(
126127
URL(apiUrl),
127128
URL(telemetryUrl),
128129
URL(peerUrl),
129-
log,
130+
httpLogLevel,
130131
credentials,
131132
eventReadTimeoutInMills,
132133
eventReadMaxAttempts,
@@ -150,8 +151,8 @@ open class Iroha2Client(
150151
open val client by lazy {
151152
HttpClient(CIO) {
152153
expectSuccess = true
153-
if (log) {
154-
install(Logging)
154+
install(Logging) {
155+
level = httpLogLevel
155156
}
156157
install(WebSockets)
157158
install(ContentNegotiation) {

modules/client/src/test/kotlin/jp/co/soramitsu/iroha2/ExampleTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ExampleTest {
2727
this.genesis = DefaultGenesis::class.createInstance()
2828
}.also { it.start() }
2929

30-
val client = Iroha2Client(container.getApiUrl(), container.getTelemetryUrl(), container.getP2pUrl(), true)
30+
val client = Iroha2Client(container.getApiUrl(), container.getTelemetryUrl(), container.getP2pUrl())
3131

3232
val domainId = "new_domain_name".asDomainId()
3333
client.sendTransaction {

modules/client/src/test/kotlin/jp/co/soramitsu/iroha2/GenesisTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class GenesisTest : IrohaTest<Iroha2Client>() {
3737
this.genesisPath = path
3838
}.also { it.start() }
3939

40-
val client = Iroha2Client(container.getApiUrl(), container.getTelemetryUrl(), container.getP2pUrl(), true)
40+
val client = Iroha2Client(container.getApiUrl(), container.getTelemetryUrl(), container.getP2pUrl())
4141
client.checkAliceAndBobExists()
4242
}
4343

0 commit comments

Comments
 (0)