From 2b0642c32c78f24964e2f4d92dc3a3aa4183abc3 Mon Sep 17 00:00:00 2001 From: Luca Rossetto Date: Sun, 19 Nov 2023 16:48:56 +0100 Subject: [PATCH] Minor logging cleanup --- .../org/vitrivr/engine/index/decode/ImageDecoder.kt | 7 ++++--- .../org/vitrivr/engine/index/decode/VideoDecoder.kt | 8 ++++++-- .../engine/index/enumerate/FileSystemEnumerator.kt | 5 +++-- .../vitrivr/engine/index/exporters/ThumbnailExporter.kt | 4 ++-- .../engine/index/segment/FixedDurationSegmenter.kt | 6 ++++++ 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/decode/ImageDecoder.kt b/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/decode/ImageDecoder.kt index 9f8d39f2..a1c6edf1 100644 --- a/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/decode/ImageDecoder.kt +++ b/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/decode/ImageDecoder.kt @@ -18,9 +18,6 @@ import org.vitrivr.engine.core.source.Source import java.io.IOException import javax.imageio.ImageIO -/** [KLogger] instance. */ -private val logger: KLogger = KotlinLogging.logger {} - /** * A [Decoder] that can decode [ImageContent] from a [Source] of [MediaType.IMAGE]. * @@ -43,6 +40,9 @@ class ImageDecoder : DecoderFactory { */ private class Instance(override val input: Enumerator, private val context: IndexContext) : Decoder { + /** [KLogger] instance. */ + private val logger: KLogger = KotlinLogging.logger {} + /** * Converts this [ImageDecoder] to a [Flow] of [Content] elements. * @@ -54,6 +54,7 @@ class ImageDecoder : DecoderFactory { override fun toFlow(scope: CoroutineScope): Flow = this.input.toFlow(scope).filter { it.type == MediaType.IMAGE }.mapNotNull { source -> + logger.info { "Decoding source ${source.name} (${source.sourceId})" } try { val image = source.newInputStream().use { this.context.contentFactory.newImageContent(ImageIO.read(it)) diff --git a/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/decode/VideoDecoder.kt b/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/decode/VideoDecoder.kt index 6b8111ba..216edfbb 100644 --- a/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/decode/VideoDecoder.kt +++ b/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/decode/VideoDecoder.kt @@ -25,8 +25,6 @@ import org.vitrivr.engine.core.source.MediaType import org.vitrivr.engine.core.source.Source import java.nio.ShortBuffer -/** [KLogger] instance. */ -private val logger: KLogger = KotlinLogging.logger {} /** * A [Decoder] that can decode [ImageContent] and [AudioContent] from a [Source] of [MediaType.VIDEO]. @@ -36,6 +34,7 @@ private val logger: KLogger = KotlinLogging.logger {} * @version 1.0.0 */ class VideoDecoder : DecoderFactory { + override fun newOperator(input: Enumerator, context: IndexContext, parameters: Map): Decoder { val video = parameters["video"]?.let { it.lowercase() == "true" } ?: true val audio = parameters["audio"]?.let { it.lowercase() == "true" } ?: true @@ -48,6 +47,9 @@ class VideoDecoder : DecoderFactory { */ private class Instance(override val input: Enumerator, private val context: IndexContext, private val video: Boolean = true, private val audio: Boolean = true) : Decoder { + /** [KLogger] instance. */ + private val logger: KLogger = KotlinLogging.logger {} + /** The [Java2DFrameConverter] used by this [VideoDecoder] instance. */ private val converter: Java2DFrameConverter by lazy { Java2DFrameConverter() } @@ -66,6 +68,7 @@ class VideoDecoder : DecoderFactory { input.collect { source -> source.newInputStream().use { input -> FFmpegFrameGrabber(input).use { grabber -> + logger.info { "Start decoding source ${source.name} (${source.sourceId})" } try { grabber.start() var frame = grabber.grabFrame(this@Instance.video, this@Instance.audio, true, false, true) @@ -81,6 +84,7 @@ class VideoDecoder : DecoderFactory { } catch (exception: Exception) { logger.error(exception) { "An error occurred while decoding video from source $source. Skipping..." } } + logger.info { "Finished decoding source ${source.name} (${source.sourceId})" } } } } diff --git a/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/enumerate/FileSystemEnumerator.kt b/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/enumerate/FileSystemEnumerator.kt index 875d82f6..c2f9ab64 100644 --- a/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/enumerate/FileSystemEnumerator.kt +++ b/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/enumerate/FileSystemEnumerator.kt @@ -29,14 +29,15 @@ import kotlin.io.path.isRegularFile * @version 1.0.0 */ class FileSystemEnumerator : EnumeratorFactory { + + private val logger: KLogger = KotlinLogging.logger {} + /** * Creates a new [Enumerator] instance from this [FileSystemEnumerator]. * * @param context The [IndexContext] to use. * @param parameters Optional set of parameters. */ - private val logger: KLogger = KotlinLogging.logger {} - override fun newOperator(context: IndexContext, parameters: Map): Enumerator { val path = Path(parameters["path"] ?: throw IllegalArgumentException("Path is required")) val depth = (parameters["depth"] ?: Int.MAX_VALUE.toString()).toInt() diff --git a/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/exporters/ThumbnailExporter.kt b/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/exporters/ThumbnailExporter.kt index a710bf9d..b095f30f 100644 --- a/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/exporters/ThumbnailExporter.kt +++ b/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/exporters/ThumbnailExporter.kt @@ -17,8 +17,6 @@ import org.vitrivr.engine.core.operators.ingest.Exporter import org.vitrivr.engine.core.operators.ingest.ExporterFactory import org.vitrivr.engine.core.source.file.MimeType -private val logger: KLogger = KotlinLogging.logger {} - /** * An [Exporter] that generates thumbnails from videos and images. * @@ -27,6 +25,8 @@ private val logger: KLogger = KotlinLogging.logger {} */ class ThumbnailExporter : ExporterFactory { + private val logger: KLogger = KotlinLogging.logger {} + /** * Creates a new [Exporter] instance from this [ThumbnailExporter]. * diff --git a/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/segment/FixedDurationSegmenter.kt b/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/segment/FixedDurationSegmenter.kt index 9bafae56..e820d756 100644 --- a/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/segment/FixedDurationSegmenter.kt +++ b/vitrivr-engine-index/src/main/kotlin/org/vitrivr/engine/index/segment/FixedDurationSegmenter.kt @@ -1,5 +1,7 @@ package org.vitrivr.engine.index.segment +import io.github.oshai.kotlinlogging.KLogger +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.channels.ProducerScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.sync.Mutex @@ -89,6 +91,9 @@ class FixedDurationSegmenter : SegmenterFactory { /** Reference to the last [Source] encountered by this [FixedDurationSegmenter]. */ private var lastSource: Source? = null + /** [KLogger] instance. */ + private val logger: KLogger = KotlinLogging.logger {} + override suspend fun segment(upstream: Flow>, downstream: ProducerScope) { upstream.collect { content -> this.mutex.lock() @@ -100,6 +105,7 @@ class FixedDurationSegmenter : SegmenterFactory { } this.lastSource = content.source this.lastStartTime = 0 + logger.info { "Starting to segment new source ${lastSource?.name} (${lastSource?.sourceId})" } } this.cache.add(content) val cutOffTime = this.lastStartTime + this.lengthNanos + this.lookAheadNanos