feature #10: first implementation of logger

This commit is contained in:
2019-07-17 17:37:11 +02:00
parent 09c20fc385
commit 32127b7e19
4 changed files with 52 additions and 0 deletions

View File

@@ -9,6 +9,8 @@ import com.github.jasync.sql.db.postgresql.PostgreSQLConnectionBuilder
import com.github.jasync.sql.db.util.length
import fr.postgresjson.entity.EntityI
import fr.postgresjson.serializer.Serializer
import fr.postgresjson.utils.LoggerDelegate
import org.slf4j.Logger
import java.util.concurrent.CompletableFuture
@@ -31,6 +33,7 @@ class Connection(
): Executable {
private lateinit var connection: ConnectionPool<PostgreSQLConnection>
private val serializer = Serializer()
private val logger: Logger? by LoggerDelegate()
fun connect(): ConnectionPool<PostgreSQLConnection> {
if (!::connection.isInitialized || !connection.isConnected()) {
@@ -132,6 +135,7 @@ class Connection(
select(sql, object: TypeReference<List<R>>() {}, values)
override fun exec(sql: String, values: List<Any?>): CompletableFuture<QueryResult> {
logger?.debug(sql, values)
return connect().sendPreparedStatement(sql, compileArgs(values))
}

View File

@@ -0,0 +1,11 @@
package fr.postgresjson.utils
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
internal class LoggerDelegate<in R : Any> : ReadOnlyProperty<R, Logger> {
override fun getValue(thisRef: R, property: KProperty<*>)
= LoggerFactory.getLogger(thisRef.javaClass.packageName)
}