Skip to content

Commit

Permalink
replaced slf4j with klogging
Browse files Browse the repository at this point in the history
  • Loading branch information
Montagon committed Apr 10, 2024
1 parent e02d3c7 commit 6ce5403
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 37 deletions.
1 change: 0 additions & 1 deletion server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ dependencies {
implementation(libs.ktor.server.cors)
implementation(libs.ktor.server.request.validation)
implementation(libs.ktor.server.status.pages)
implementation(libs.logback)
implementation(libs.suspendApp.core)
implementation(libs.suspendApp.ktor)
implementation(libs.uuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.xebia.functional.xef.server.http.routes.xefRoutes
import com.xebia.functional.xef.server.services.hikariDataSource
import com.xebia.functional.xef.server.services.vectorStoreService
import com.xebia.functional.xef.store.migrations.runDatabaseMigrations
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO
import io.ktor.client.plugins.auth.Auth
Expand All @@ -30,13 +31,12 @@ import io.ktor.server.resources.Resources
import io.ktor.server.routing.routing
import kotlinx.coroutines.awaitCancellation
import org.jetbrains.exposed.sql.Database
import org.slf4j.LoggerFactory

object Server {
@JvmStatic
fun main(args: Array<String>) = SuspendApp {
resourceScope {
val logger = LoggerFactory.getLogger("xef-server")
val logger = KotlinLogging.logger("xef-server")

val config = ConfigFactory.load("database.conf").resolve()
val xefDBConfig = XefDatabaseConfig.load("xef-database", config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import com.xebia.functional.xef.server.services.OrganizationRepositoryService
import com.xebia.functional.xef.server.services.ProjectRepositoryService
import com.xebia.functional.xef.server.services.TokenRepositoryService
import com.xebia.functional.xef.server.services.UserRepositoryService
import io.github.oshai.kotlinlogging.KLogger
import io.ktor.server.routing.*
import org.slf4j.Logger

fun Routing.xefRoutes(logger: Logger) {
fun Routing.xefRoutes(logger: KLogger) {
userRoutes(UserRepositoryService(logger))
organizationRoutes(OrganizationRepositoryService(logger))
projectsRoutes(ProjectRepositoryService(logger))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import com.xebia.functional.xef.server.db.tables.Organization
import com.xebia.functional.xef.server.db.tables.User
import com.xebia.functional.xef.server.models.*
import com.xebia.functional.xef.server.models.exceptions.XefExceptions.*
import io.github.oshai.kotlinlogging.KLogger
import kotlinx.datetime.Clock
import org.jetbrains.exposed.sql.SizedCollection
import org.jetbrains.exposed.sql.transactions.transaction
import org.slf4j.Logger

class OrganizationRepositoryService(private val logger: Logger) {
class OrganizationRepositoryService(private val logger: KLogger) {
fun createOrganization(data: OrganizationRequest, token: Token): OrganizationSimpleResponse {
logger.info("Creating organization with name: ${data.name}")
logger.info { "Creating organization with name: ${data.name}" }
return transaction {
// Getting the user from the token
val user = token.getUser()
Expand All @@ -30,7 +30,7 @@ class OrganizationRepositoryService(private val logger: Logger) {
}

fun getOrganizations(token: Token): List<OrganizationFullResponse> {
logger.info("Getting organizations")
logger.info { "Getting organizations" }
return transaction {
// Getting the user from the token
val user = token.getUser()
Expand All @@ -41,7 +41,7 @@ class OrganizationRepositoryService(private val logger: Logger) {
}

fun getOrganization(token: Token, id: Int): OrganizationFullResponse {
logger.info("Getting organizations")
logger.info { "Getting organizations" }
return transaction {
// Getting the user from the token
val user = token.getUser()
Expand All @@ -53,7 +53,7 @@ class OrganizationRepositoryService(private val logger: Logger) {
}

fun getUsersInOrganization(token: Token, id: Int): List<UserResponse> {
logger.info("Getting users in organization")
logger.info { "Getting users in organization" }
return transaction {
// Getting the user from the token
val user = token.getUser()
Expand All @@ -71,7 +71,7 @@ class OrganizationRepositoryService(private val logger: Logger) {
data: OrganizationUpdateRequest,
id: Int
): OrganizationFullResponse {
logger.info("Updating organization with name: ${data.name}")
logger.info { "Updating organization with name: ${data.name}" }
return transaction {
// Getting the user from the token
val user = token.getUser()
Expand All @@ -95,7 +95,7 @@ class OrganizationRepositoryService(private val logger: Logger) {
}

fun deleteOrganization(token: Token, id: Int) {
logger.info("Deleting organization with id: $id")
logger.info { "Deleting organization with id: $id" }
transaction {
val user = token.getUser()
val organization =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import com.xebia.functional.xef.store.VectorStore
import com.xebia.functional.xef.store.postgresql.PGDistanceStrategy
import com.xebia.functional.xef.store.postgresql.addNewCollection
import com.xebia.functional.xef.store.postgresql.connection
import io.github.oshai.kotlinlogging.KLogger
import javax.sql.DataSource
import kotlinx.uuid.UUID
import kotlinx.uuid.generateUUID
import org.slf4j.Logger

class PostgresVectorStoreService(
private val logger: Logger,
private val logger: KLogger,
private val dataSource: DataSource,
private val collectionName: String,
private val vectorSize: Int,
Expand All @@ -33,7 +33,7 @@ class PostgresVectorStoreService(
bind(uuid.toString())
bind(collectionName)
}
.also { logger.info("Created collection $collectionName") }
.also { logger.info { "Created collection $collectionName" } }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package com.xebia.functional.xef.server.services
import com.xebia.functional.xef.server.db.tables.*
import com.xebia.functional.xef.server.models.*
import com.xebia.functional.xef.server.models.exceptions.XefExceptions.*
import io.github.oshai.kotlinlogging.KLogger
import kotlinx.datetime.Clock
import org.jetbrains.exposed.sql.transactions.transaction
import org.slf4j.Logger

class ProjectRepositoryService(private val logger: Logger) {
class ProjectRepositoryService(private val logger: KLogger) {
fun createProject(data: ProjectRequest, token: Token): ProjectSimpleResponse {
logger.info("Creating project with name: ${data.name}")
logger.info { "Creating project with name: ${data.name}" }
return transaction {
val user = token.getUser()

Expand All @@ -30,7 +30,7 @@ class ProjectRepositoryService(private val logger: Logger) {
}

fun getProjects(token: Token): List<ProjectFullResponse> {
logger.info("Getting projects")
logger.info { "Getting projects" }
return transaction {
val user = token.getUser()

Expand All @@ -43,7 +43,7 @@ class ProjectRepositoryService(private val logger: Logger) {
}

fun getProject(token: Token, id: Int): ProjectFullResponse {
logger.info("Getting project")
logger.info { "Getting project" }
return transaction {
val user = token.getUser()

Expand All @@ -58,7 +58,7 @@ class ProjectRepositoryService(private val logger: Logger) {
}

fun getProjectsByOrganization(token: Token, orgId: Int): List<ProjectSimpleResponse> {
logger.info("Getting projects")
logger.info { "Getting projects" }
return transaction {
val user = token.getUser()

Expand All @@ -71,7 +71,7 @@ class ProjectRepositoryService(private val logger: Logger) {
}

fun updateProject(token: Token, data: ProjectUpdateRequest, id: Int): ProjectFullResponse {
logger.info("Updating project with name: ${data.name}")
logger.info { "Updating project with name: ${data.name}" }
return transaction {
val user = token.getUser()

Expand Down Expand Up @@ -101,7 +101,7 @@ class ProjectRepositoryService(private val logger: Logger) {
}

fun deleteProject(token: Token, id: Int) {
logger.info("Deleting project with id: $id")
logger.info { "Deleting project with id: $id" }
transaction {
val user = token.getUser()
val project = Project.findById(id) ?: throw ProjectException("Project not found")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import com.xebia.functional.xef.server.db.tables.XefTokens
import com.xebia.functional.xef.server.db.tables.XefTokensTable
import com.xebia.functional.xef.server.models.*
import com.xebia.functional.xef.server.models.exceptions.XefExceptions.*
import io.github.oshai.kotlinlogging.KLogger
import java.util.UUID
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.transactions.transaction
import org.slf4j.Logger

class TokenRepositoryService(private val logger: Logger) {
class TokenRepositoryService(private val logger: KLogger) {
fun createToken(data: TokenRequest, userToken: Token): TokenSimpleResponse {
return transaction {
val user = userToken.getUser()

val project =
Project.findById(data.projectId) ?: throw OrganizationsException("Project not found")

logger.info("Creating token with name ${data.name} from project ${project.name}")
logger.info { "Creating token with name ${data.name} from project ${project.name}" }

if (user.organizations.none { it.id == project.orgId }) {
throw OrganizationsException(
Expand All @@ -43,7 +43,7 @@ class TokenRepositoryService(private val logger: Logger) {
}

fun getTokens(userToken: Token): List<TokenFullResponse> {
logger.info("Getting tokens")
logger.info { "Getting tokens" }
return transaction {
val user = userToken.getUser()

Expand All @@ -64,7 +64,7 @@ class TokenRepositoryService(private val logger: Logger) {
}

fun getTokensByProject(userToken: Token, projectId: Int): List<TokenFullResponse> {
logger.info("Getting tokens by project")
logger.info { "Getting tokens by project" }
return transaction {
val user = userToken.getUser()

Expand All @@ -78,7 +78,7 @@ class TokenRepositoryService(private val logger: Logger) {
}

fun updateToken(userToken: Token, data: TokenUpdateRequest, id: Int): TokenFullResponse {
logger.info("Updating token with name: ${data.name}")
logger.info { "Updating token with name: ${data.name}" }
return transaction {
val user = userToken.getUser()

Expand All @@ -102,7 +102,7 @@ class TokenRepositoryService(private val logger: Logger) {
}

fun deleteToken(userToken: Token, id: Int) {
logger.info("Deleting token: $id")
logger.info { "Deleting token: $id" }
transaction {
val user = userToken.getUser()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import com.xebia.functional.xef.server.models.LoginResponse
import com.xebia.functional.xef.server.models.RegisterRequest
import com.xebia.functional.xef.server.models.exceptions.XefExceptions.UserException
import com.xebia.functional.xef.server.utils.HashUtils
import io.github.oshai.kotlinlogging.KLogger
import kotlinx.uuid.UUID
import kotlinx.uuid.generateUUID
import org.jetbrains.exposed.sql.transactions.transaction
import org.slf4j.Logger

class UserRepositoryService(private val logger: Logger) {
class UserRepositoryService(private val logger: KLogger) {

fun register(request: RegisterRequest): LoginResponse {
logger.info("Registering user ${request.email}")
logger.info { "Registering user ${request.email}" }

return transaction {
if (User.find { UsersTable.email eq request.email }.count() > 0) {
Expand All @@ -38,7 +38,7 @@ class UserRepositoryService(private val logger: Logger) {
}

fun login(request: LoginRequest): LoginResponse {
logger.info("Login user ${request.email}")
logger.info { "Login user ${request.email}" }
return transaction {
val user =
User.find { UsersTable.email eq request.email }.firstOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import com.typesafe.config.Config
import com.xebia.functional.xef.store.VectorStore
import com.xebia.functional.xef.store.config.PostgreSQLVectorStoreConfig
import com.xebia.functional.xef.store.migrations.runDatabaseMigrations
import io.github.oshai.kotlinlogging.KLogger
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.hocon.Hocon
import org.slf4j.Logger

enum class XefVectorStoreType {
PSQL,
Expand All @@ -27,7 +27,7 @@ enum class XefVectorStoreType {
suspend fun ResourceScope.vectorStoreService(
configNamespace: String,
config: Config,
logger: Logger
logger: KLogger
): VectorStoreService =
withContext(Dispatchers.IO) {
val vectorStoreConfig = config.getConfig(configNamespace)
Expand Down

0 comments on commit 6ce5403

Please sign in to comment.