Skip to content

Commit

Permalink
updated kotlin-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
beneschwab committed May 9, 2024
1 parent 11669b8 commit 280729c
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 55 deletions.
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object DependencyVersions {
const val mockk = "1.13.10"

// logging libraries
const val kotlinLogging = "3.0.5"
const val kotlinLogging = "6.0.9"
const val slf4jSimple = "2.0.13"

// object creation libraries
Expand Down Expand Up @@ -75,7 +75,7 @@ object Dependencies {
const val mockk = "io.mockk:mockk:${DependencyVersions.mockk}"

// logging libraries
const val kotlinLogging = "io.github.microutils:kotlin-logging:${DependencyVersions.kotlinLogging}"
const val kotlinLogging = "io.github.oshai:kotlin-logging-jvm:${DependencyVersions.kotlinLogging}"
const val slf4jSimple = "org.slf4j:slf4j-simple:${DependencyVersions.slf4jSimple}"

// object creation libraries
Expand Down
6 changes: 3 additions & 3 deletions rtron-io/src/main/kotlin/io/rtron/io/logging/ProgressBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.rtron.io.logging

import mu.KotlinLogging
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlin.math.roundToInt
import kotlin.time.Duration
import kotlin.time.DurationUnit
Expand Down Expand Up @@ -59,10 +59,10 @@ class ProgressBar(
private fun printUpdate() {
val elapsedTime = getElapsedTime()
if (elapsedTime > PRINT_AFTER && (getElapsedTimeSinceLastUpdate() > PRINT_AT_LEAST || isCompleted())) {
logger.info(
logger.info {
"$taskName $currentStatus/$completion ${getProgressPercent().roundToInt()}% " +
"[ET $elapsedTime, ETA ${getEstimatedTimeOfArrival()}]"
)
}
lastPrintUpdateTime = System.currentTimeMillis()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package io.rtron.main.processor

import arrow.core.getOrElse
import com.charleskorn.kaml.Yaml
import io.github.oshai.kotlinlogging.KotlinLogging
import io.rtron.io.issues.getTextSummary
import io.rtron.io.serialization.serializeToJsonFile
import io.rtron.main.project.processAllFiles
Expand All @@ -34,7 +35,6 @@ import io.rtron.transformer.modifiers.opendrive.cropper.OpendriveCropper
import io.rtron.transformer.modifiers.opendrive.offset.adder.OpendriveOffsetAdder
import io.rtron.transformer.modifiers.opendrive.offset.resolver.OpendriveOffsetResolver
import io.rtron.transformer.modifiers.opendrive.remover.OpendriveObjectRemover
import mu.KotlinLogging
import java.nio.file.Path
import kotlin.io.path.Path
import kotlin.io.path.createDirectories
Expand All @@ -58,29 +58,29 @@ class OpendriveToCitygmlProcessor(
outputSubDirectoryPath.createDirectories()
// check if parameters are valid
parameters.isValid().onLeft { issues ->
issues.forEach { logger.warn("Parameters are not valid: $it") }
issues.forEach { logger.warn { "Parameters are not valid: $it" } }
return@processAllFiles
}
// write the parameters as yaml file
val parametersText = Yaml.default.encodeToString(OpendriveToCitygmlParameters.serializer(), parameters)
(outputSubDirectoryPath / PARAMETERS_PATH).toFile().writeText(parametersText)

// validate schema of OpenDRIVE model
val opendriveSchemaValidatorReport = OpendriveValidator.validateFromFile(inputFilePath).getOrElse { logger.warn(it.message); return@processAllFiles }
val opendriveSchemaValidatorReport = OpendriveValidator.validateFromFile(inputFilePath).getOrElse { logger.warn { it.message }; return@processAllFiles }
opendriveSchemaValidatorReport.serializeToJsonFile(outputSubDirectoryPath / OPENDRIVE_SCHEMA_VALIDATOR_REPORT_PATH)
if (opendriveSchemaValidatorReport.validationProcessAborted()) {
return@processAllFiles
}
// read of OpenDRIVE model
val opendriveModel = OpendriveReader.readFromFile(inputFilePath)
.getOrElse { logger.warn(it.message); return@processAllFiles }
.getOrElse { logger.warn { it.message }; return@processAllFiles }

// evaluate OpenDRIVE model
val opendriveEvaluator = OpendriveEvaluator(parameters.deriveOpendriveEvaluatorParameters())
val opendriveEvaluatorResult = opendriveEvaluator.evaluate(opendriveModel)
opendriveEvaluatorResult.second.serializeToJsonFile(outputSubDirectoryPath / OPENDRIVE_EVALUATOR_REPORT_PATH)
val modifiedOpendriveModel = opendriveEvaluatorResult.first.handleEmpty {
logger.warn(opendriveEvaluatorResult.second.getTextSummary())
logger.warn { opendriveEvaluatorResult.second.getTextSummary() }
return@processAllFiles
}

Expand All @@ -99,7 +99,7 @@ class OpendriveToCitygmlProcessor(
val opendriveCroppedResult = opendriveCropper.modify(opendriveOffsetResolvedResult.first)
opendriveCroppedResult.second.serializeToJsonFile(outputSubDirectoryPath / OPENDRIVE_CROP_REPORT_PATH)
val opendriveCropped = opendriveCroppedResult.first.handleEmpty {
logger.warn("OpendriveCropper: ${opendriveCroppedResult.second.message}")
logger.warn { "OpendriveCropper: ${opendriveCroppedResult.second.message}" }
return@processAllFiles
}

Expand All @@ -117,7 +117,7 @@ class OpendriveToCitygmlProcessor(
val roadspacesModelResult = opendrive2RoadspacesTransformer.transform(opendriveRemovedObjectResult.first)
roadspacesModelResult.second.serializeToJsonFile(outputSubDirectoryPath / OPENDRIVE_TO_ROADSPACES_REPORT_PATH)
val roadspacesModel = roadspacesModelResult.first.handleEmpty {
logger.warn("Opendrive2RoadspacesTransformer: ${roadspacesModelResult.second.conversion.getTextSummary()}")
logger.warn { "Opendrive2RoadspacesTransformer: ${roadspacesModelResult.second.conversion.getTextSummary()}" }
return@processAllFiles
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package io.rtron.main.processor

import arrow.core.getOrElse
import com.charleskorn.kaml.Yaml
import io.github.oshai.kotlinlogging.KotlinLogging
import io.rtron.io.issues.getTextSummary
import io.rtron.io.serialization.serializeToJsonFile
import io.rtron.main.project.processAllFiles
Expand All @@ -31,7 +32,6 @@ import io.rtron.transformer.converter.opendrive2roadspaces.Opendrive2RoadspacesT
import io.rtron.transformer.converter.roadspaces2citygml.Roadspaces2CitygmlTransformer
import io.rtron.transformer.evaluator.opendrive.OpendriveEvaluator
import io.rtron.transformer.evaluator.roadspaces.RoadspacesEvaluator
import mu.KotlinLogging
import java.nio.file.Path
import kotlin.io.path.Path
import kotlin.io.path.div
Expand All @@ -55,25 +55,25 @@ class ValidateOpendriveProcessor(
(outputDirectoryPath / PARAMETERS_PATH).toFile().writeText(parametersText)

// validate schema of OpenDRIVE model
val opendriveSchemaValidatorReport = OpendriveValidator.validateFromFile(inputFilePath).getOrElse { logger.warn(it.message); return@processAllFiles }
val opendriveSchemaValidatorReport = OpendriveValidator.validateFromFile(inputFilePath).getOrElse { logger.warn { it.message }; return@processAllFiles }
opendriveSchemaValidatorReport.serializeToJsonFile(outputDirectoryPath / OPENDRIVE_SCHEMA_VALIDATOR_REPORT_PATH)
if (opendriveSchemaValidatorReport.validationProcessAborted()) {
return@processAllFiles
}
// read of OpenDRIVE model
val opendriveModel = OpendriveReader.readFromFile(inputFilePath)
.getOrElse { logger.warn(it.message); return@processAllFiles }
.getOrElse { logger.warn { it.message }; return@processAllFiles }

// evaluate OpenDRIVE model
val opendriveEvaluator = OpendriveEvaluator(parameters.deriveOpendriveEvaluatorParameters())
val opendriveEvaluatorResult = opendriveEvaluator.evaluate(opendriveModel)
opendriveEvaluatorResult.second.serializeToJsonFile(outputDirectoryPath / OPENDRIVE_EVALUATOR_REPORT_PATH)
if (opendriveEvaluatorResult.second.containsFatalErrors()) {
logger.warn(opendriveEvaluatorResult.second.getTextSummary())
logger.warn { opendriveEvaluatorResult.second.getTextSummary() }
return@processAllFiles
}
val modifiedOpendriveModel = opendriveEvaluatorResult.first.handleEmpty {
logger.warn(opendriveEvaluatorResult.second.getTextSummary())
logger.warn { opendriveEvaluatorResult.second.getTextSummary() }
return@processAllFiles
}

Expand All @@ -88,7 +88,7 @@ class ValidateOpendriveProcessor(
val roadspacesModelResult = opendrive2RoadspacesTransformer.transform(modifiedOpendriveModel)
roadspacesModelResult.second.serializeToJsonFile(outputDirectoryPath / OPENDRIVE_TO_ROADSPACES_REPORT_PATH)
val roadspacesModel = roadspacesModelResult.first.handleEmpty {
logger.warn(roadspacesModelResult.second.conversion.getTextSummary())
logger.warn { roadspacesModelResult.second.conversion.getTextSummary() }
return@processAllFiles
}

Expand Down
14 changes: 7 additions & 7 deletions rtron-main/src/main/kotlin/io/rtron/main/project/ProjectDSL.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.rtron.main.project

import io.github.oshai.kotlinlogging.KotlinLogging
import io.rtron.io.files.walk
import mu.KotlinLogging
import java.nio.file.Path
import kotlin.io.path.isDirectory
import kotlin.io.path.isRegularFile
Expand All @@ -39,15 +39,15 @@ fun processAllFiles(inputDirectoryPath: Path, withFilenameEndings: Set<String>,
val logger = KotlinLogging.logger {}

if (!inputDirectoryPath.isDirectory()) {
logger.error("Provided directory does not exist: $inputDirectoryPath")
logger.error { "Provided directory does not exist: $inputDirectoryPath" }
return
}
if (withFilenameEndings.isEmpty()) {
logger.error("No extensions have been provided.")
logger.error { "No extensions have been provided." }
return
}
if (outputDirectoryPath.isRegularFile()) {
logger.error("Output directory must not be a file: $outputDirectoryPath")
logger.error { "Output directory must not be a file: $outputDirectoryPath" }
return
}

Expand All @@ -60,7 +60,7 @@ fun processAllFiles(inputDirectoryPath: Path, withFilenameEndings: Set<String>,
.sorted()

if (inputFilePaths.isEmpty()) {
logger.error("No files have been found with $withFilenameEndings as extension in input directory: $outputDirectoryPath")
logger.error { "No files have been found with $withFilenameEndings as extension in input directory: $outputDirectoryPath" }
return
}

Expand All @@ -70,13 +70,13 @@ fun processAllFiles(inputDirectoryPath: Path, withFilenameEndings: Set<String>,
val inputFileRelativePath = inputDirectoryPath.relativize(currentPath)
val projectOutputDirectoryPath = outputDirectoryPath.resolve(inputFileRelativePath)

logger.info("Starting project (${index + 1}/$totalNumber): $inputFileRelativePath")
logger.info { "Starting project (${index + 1}/$totalNumber): $inputFileRelativePath" }

val timeElapsed = measureTime {
val project = Project(currentPath, projectOutputDirectoryPath)
project.apply(process)
}

logger.info("Completed project after $timeElapsed." + System.lineSeparator())
logger.info { "Completed project after $timeElapsed." + System.lineSeparator() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package io.rtron.math.analysis

import io.github.oshai.kotlinlogging.KotlinLogging
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.doubles.plusOrMinus
import io.kotest.matchers.shouldBe
import io.rtron.math.std.DBL_EPSILON
import mu.KotlinLogging
import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVRecord
import java.io.FileReader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.rtron.math.geometry.euclidean.twod.curve

import io.github.oshai.kotlinlogging.KotlinLogging
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.doubles.plusOrMinus
import io.kotest.matchers.shouldBe
Expand All @@ -26,7 +27,6 @@ import io.rtron.math.std.DBL_EPSILON_1
import io.rtron.math.std.DBL_EPSILON_2
import io.rtron.math.std.DBL_EPSILON_3
import io.rtron.math.std.PI
import mu.KotlinLogging
import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVRecord
import java.io.FileReader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.rtron.math.geometry.euclidean.twod.curve

import io.github.oshai.kotlinlogging.KotlinLogging
import io.kotest.assertions.arrow.core.shouldBeRight
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.doubles.plusOrMinus
Expand All @@ -33,7 +34,6 @@ import io.rtron.math.std.DBL_EPSILON_6
import io.rtron.math.std.DBL_EPSILON_8
import io.rtron.math.transform.Affine2D
import io.rtron.math.transform.AffineSequence2D
import mu.KotlinLogging
import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVRecord
import java.io.FileReader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package io.rtron.readerwriter.citygml

import io.github.oshai.kotlinlogging.KotlinLogging
import io.rtron.io.files.getFileSizeToDisplay
import io.rtron.io.files.outputStreamDirectOrCompressed
import io.rtron.model.citygml.CitygmlModel
import mu.KotlinLogging
import org.citygml4j.xml.CityGMLContext
import org.citygml4j.xml.module.citygml.CoreModule
import java.io.OutputStream
Expand All @@ -40,7 +40,7 @@ object CitygmlWriter {
writeToStream(model, version, outputStream)
outputStream.close()

logger.info("Completed writing of file ${filePath.fileName} (around ${filePath.getFileSizeToDisplay()}).")
logger.info { "Completed writing of file ${filePath.fileName} (around ${filePath.getFileSizeToDisplay()})." }
}

fun writeToStream(model: CitygmlModel, version: CitygmlVersion, outputStream: OutputStream) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package io.rtron.readerwriter.opendrive
import arrow.core.Either
import arrow.core.left
import arrow.core.raise.either
import io.github.oshai.kotlinlogging.KotlinLogging
import io.rtron.io.files.CompressedFileExtension
import io.rtron.io.files.getFileSizeToDisplay
import io.rtron.io.files.inputStreamFromDirectOrCompressedFile
Expand All @@ -30,7 +31,6 @@ import io.rtron.readerwriter.opendrive.reader.mapper.opendrive16.Opendrive16Mapp
import io.rtron.readerwriter.opendrive.version.OpendriveVersion
import io.rtron.readerwriter.opendrive.version.OpendriveVersionUtils
import io.rtron.std.BaseException
import mu.KotlinLogging
import org.mapstruct.factory.Mappers
import java.io.InputStream
import java.nio.file.Path
Expand Down Expand Up @@ -59,7 +59,7 @@ object OpendriveReader {
fileInputStream.close()

val opendriveModel = opendriveModelResult.bind()
logger.info("Completed read-in of file ${filePath.fileName} (around ${filePath.getFileSizeToDisplay()}).")
logger.info { "Completed read-in of file ${filePath.fileName} (around ${filePath.getFileSizeToDisplay()})." }
opendriveModel
}
fun readFromStream(opendriveVersion: OpendriveVersion, inputStream: InputStream): Either<OpendriveReaderException, OpendriveModel> =
Expand All @@ -75,7 +75,7 @@ object OpendriveReader {
OpendriveVersion.V1_7 -> OpendriveVersion.V1_6
}
if (opendriveVersion != unmarshallerOpendriveVersion) {
logger.warn("No dedicated reader available for OpenDRIVE $opendriveVersion. Using reader for OpenDRIVE $unmarshallerOpendriveVersion as fallback.")
logger.warn { "No dedicated reader available for OpenDRIVE $opendriveVersion. Using reader for OpenDRIVE $unmarshallerOpendriveVersion as fallback." }
}

val unmarshaller = OpendriveUnmarshaller.of(unmarshallerOpendriveVersion).bind()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import arrow.core.Either
import arrow.core.getOrElse
import arrow.core.left
import arrow.core.raise.either
import io.github.oshai.kotlinlogging.KotlinLogging
import io.rtron.io.files.inputStreamFromDirectOrCompressedFile
import io.rtron.io.issues.IssueList
import io.rtron.readerwriter.opendrive.reader.OpendriveUnmarshaller
import io.rtron.readerwriter.opendrive.report.SchemaValidationIssue
import io.rtron.readerwriter.opendrive.report.SchemaValidationReport
import io.rtron.readerwriter.opendrive.version.OpendriveVersion
import io.rtron.readerwriter.opendrive.version.OpendriveVersionUtils
import mu.KotlinLogging
import java.io.InputStream
import java.nio.file.Path

Expand All @@ -49,13 +49,17 @@ object OpendriveValidator {
fun validateFromStream(opendriveVersion: OpendriveVersion, inputStream: InputStream): Either<OpendriveReaderException, SchemaValidationReport> = either {
val issueList = runValidation(opendriveVersion, inputStream)
.getOrElse {
logger.warn("Schema validation was aborted due the following error: ${it.message}")
return@either SchemaValidationReport(opendriveVersion, completedSuccessfully = false, validationAbortIssue = it.message)
logger.warn { "Schema validation was aborted due the following error: ${it.message}" }
return@either SchemaValidationReport(
opendriveVersion,
completedSuccessfully = false,
validationAbortIssue = it.message
)
}
if (!issueList.isEmpty()) {
logger.warn("Schema validation for OpenDRIVE $opendriveVersion found ${issueList.size} incidents.")
logger.warn { "Schema validation for OpenDRIVE $opendriveVersion found ${issueList.size} incidents." }
} else {
logger.info("Schema validation report for OpenDRIVE $opendriveVersion: Everything ok.")
logger.info { "Schema validation report for OpenDRIVE $opendriveVersion: Everything ok." }
}

SchemaValidationReport(opendriveVersion, issueList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package io.rtron.readerwriter.opendrive

import arrow.core.Either
import arrow.core.raise.either
import io.github.oshai.kotlinlogging.KotlinLogging
import io.rtron.io.files.getFileSizeToDisplay
import io.rtron.io.files.outputStreamDirectOrCompressed
import io.rtron.model.opendrive.OpendriveModel
import io.rtron.readerwriter.opendrive.writer.OpendriveMarshaller
import io.rtron.std.BaseException
import mu.KotlinLogging
import java.io.OutputStream
import java.nio.file.Path

Expand All @@ -39,7 +39,7 @@ object OpendriveWriter {
writeToStream(model, outputStream)
outputStream.close()

logger.info("Completed writing of file ${filePath.fileName} (around ${filePath.getFileSizeToDisplay()}).")
logger.info { "Completed writing of file ${filePath.fileName} (around ${filePath.getFileSizeToDisplay()})." }
}

fun writeToStream(model: OpendriveModel, outputStream: OutputStream) {
Expand Down
Loading

0 comments on commit 280729c

Please sign in to comment.