Skip to content

Commit

Permalink
Minor logging cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaro committed Nov 19, 2023
1 parent 8df9ae6 commit 2b0642c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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].
*
Expand All @@ -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.
*
Expand All @@ -54,6 +54,7 @@ class ImageDecoder : DecoderFactory {
override fun toFlow(scope: CoroutineScope): Flow<ImageContent> = 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand All @@ -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<String, String>): Decoder {
val video = parameters["video"]?.let { it.lowercase() == "true" } ?: true
val audio = parameters["audio"]?.let { it.lowercase() == "true" } ?: true
Expand All @@ -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() }

Expand All @@ -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)
Expand All @@ -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})" }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>): Enumerator {
val path = Path(parameters["path"] ?: throw IllegalArgumentException("Path is required"))
val depth = (parameters["depth"] ?: Int.MAX_VALUE.toString()).toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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].
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<ContentElement<*>>, downstream: ProducerScope<Retrievable>) {
upstream.collect { content ->
this.mutex.lock()
Expand All @@ -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
Expand Down

0 comments on commit 2b0642c

Please sign in to comment.