Add debug logging
This commit is contained in:
parent
926c20e8b2
commit
686174b9cb
3 changed files with 41 additions and 3 deletions
21
.github/workflows/bld.yml
vendored
21
.github/workflows/bld.yml
vendored
|
@ -9,12 +9,13 @@ env:
|
|||
|
||||
jobs:
|
||||
build-bld-project:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
java-version: [17, 21, 24]
|
||||
kotlin-version: [1.9.25, 2.1.20]
|
||||
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- name: Checkout source repository
|
||||
|
@ -28,6 +29,19 @@ jobs:
|
|||
distribution: "zulu"
|
||||
java-version: ${{ matrix.java-version }}
|
||||
|
||||
- name: Download dependencies [bld example]
|
||||
working-directory: examples/bld
|
||||
run: ./bld download
|
||||
|
||||
- name: Compile and run [bld examples]
|
||||
working-directory: examples/bld
|
||||
run: ./bld compile run
|
||||
|
||||
- name: Run example [bld examples]
|
||||
working-directory: examples/gradle
|
||||
if: matrix.java-version != '24'
|
||||
run: ./gradlew run
|
||||
|
||||
- name: Download dependencies
|
||||
run: ./bld download
|
||||
|
||||
|
@ -39,11 +53,12 @@ jobs:
|
|||
|
||||
- name: Remove pom.xml
|
||||
if: success() && matrix.java-version == env.COVERAGE_JDK && matrix.kotlin-version == env.COVERAGE_KOTLIN
|
||||
run: rm -rf pom.xml
|
||||
run: rm -rf pom.xmlAdd debug logging
|
||||
|
||||
- name: SonarCloud Scan
|
||||
uses: sonarsource/sonarcloud-github-action@master
|
||||
if: success() && matrix.java-version == env.COVERAGE_JDK && matrix.kotlin-version == env.COVERAGE_KOTLIN
|
||||
&& martix.os == 'unbuntu-latest'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
|
|
|
@ -42,6 +42,8 @@ import java.math.BigDecimal
|
|||
import java.text.NumberFormat
|
||||
import java.time.LocalDate
|
||||
import java.util.*
|
||||
import java.util.logging.Level
|
||||
import java.util.logging.Logger
|
||||
|
||||
/**
|
||||
* Retrieves and holds a cryptocurrency price.
|
||||
|
@ -57,6 +59,9 @@ open class CryptoPrice(val base: String, val currency: String, val amount: BigDe
|
|||
// Coinbase API URL
|
||||
private const val COINBASE_API_URL = "https://api.coinbase.com/v2/"
|
||||
|
||||
/** The logger instance. **/
|
||||
val logger: Logger by lazy { Logger.getLogger(CryptoPrice::class.java.simpleName) }
|
||||
|
||||
/**
|
||||
* Converts JSON data object to [CryptoPrice].
|
||||
*
|
||||
|
@ -105,6 +110,9 @@ open class CryptoPrice(val base: String, val currency: String, val amount: BigDe
|
|||
id = "empty_response",
|
||||
message = "Empty response."
|
||||
)
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(body)
|
||||
}
|
||||
try {
|
||||
val json = JSONObject(body)
|
||||
if (response.isSuccessful) {
|
||||
|
|
|
@ -42,9 +42,12 @@ import net.thauvin.erik.crypto.CryptoPrice.Companion.sellPrice
|
|||
import net.thauvin.erik.crypto.CryptoPrice.Companion.spotPrice
|
||||
import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice
|
||||
import org.json.JSONObject
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import java.math.BigDecimal
|
||||
import java.time.LocalDate
|
||||
import java.util.*
|
||||
import java.util.logging.ConsoleHandler
|
||||
import java.util.logging.Level
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
@ -239,4 +242,16 @@ class CryptoPriceTest {
|
|||
assertEquals(json, price.toString(), "toString()")
|
||||
assertEquals(price.toString(), price.toJson(""), "toString() = toJson('')")
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@BeforeAll
|
||||
fun beforeAll() {
|
||||
with(CryptoPrice.logger) {
|
||||
addHandler(ConsoleHandler().apply { level = Level.FINE })
|
||||
level = Level.FINE
|
||||
useParentHandlers = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue