Adds Logback config and updates logging

This commit is contained in:
aarbit 2024-06-06 21:18:13 -05:00
parent e190c3a533
commit 0404cff354
4 changed files with 19 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package net.halfbinary.prettyplayerapi.controller
import com.mpatric.mp3agic.Mp3File
import io.github.oshai.kotlinlogging.KotlinLogging
import net.halfbinary.prettyplayerapi.model.TrackInfo
import net.halfbinary.prettyplayerapi.service.MusicService
import org.springframework.web.bind.annotation.CrossOrigin
@ -8,6 +9,8 @@ import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController
private val logger = KotlinLogging.logger {}
@RestController
@CrossOrigin
class TrackController(private val musicService: MusicService) {
@ -17,6 +20,7 @@ class TrackController(private val musicService: MusicService) {
val trackFile = Mp3File(file)
trackFile.id3v2Tag.artist
trackFile.id3v2Tag.apply {
logger.debug { "Getting track $trackNumber. $title by $artist on $album" }
return TrackInfo(album, artist, title)
}
}

View File

@ -37,6 +37,7 @@ class AlbumCacheService(private val albumRepository: AlbumRepository) {
}
suspend fun cacheAlbums(refresh: Boolean = false) {
logger.debug { "Starting the cache process with refresh set to $refresh" }
createAlbumArtRootDir()
val list = getAlbumRootDir()
.walkTopDown()
@ -56,6 +57,7 @@ class AlbumCacheService(private val albumRepository: AlbumRepository) {
}
albumRepository.albumCache = convertAlbumListToMapForCache(list)
//TODO: Write cache to file for later reading...or get a DB going?
logger.info { "Albums cached: ${albumRepository.albumCache.size}" }
}
@ -83,8 +85,8 @@ class AlbumCacheService(private val albumRepository: AlbumRepository) {
}
suspend fun getAndWriteAlbumImageFile(file: File, folderHash: String, folder: Path, refresh: Boolean = false) {
logger.info { "Checking album $folder with hash $folderHash" }
val hashedFile = File("$ALBUM_ART_ROOT_DIR/$folderHash.jpg")
logger.info { "Looking at $hashedFile" }
if(refresh || !hashedFile.exists()) {
logger.debug { "No image for $folder, making one..." }
val imageByteStream = Mp3File(file).id3v2Tag.albumImage.inputStream()
@ -93,7 +95,7 @@ class AlbumCacheService(private val albumRepository: AlbumRepository) {
val outputImage = BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB)
outputImage.graphics.drawImage(scaledImage, 0, 0, null)
ImageIO.write(outputImage, "jpg", hashedFile)
logger.debug { "Wrote new image file." }
logger.trace { "Wrote new image file for $folder with hash $folderHash" }
}
}

View File

@ -17,7 +17,6 @@ class StartupService(private val albumCacheService: AlbumCacheService) {
suspend fun onStartup() {
coroutineScope {
launch {
logger.info { "Starting up..." }
albumCacheService.doAlbumCache()
}
}

View File

@ -0,0 +1,11 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="net.halfbinary.prettyplayerapi" level="debug" />
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>