spfl4j logging
This commit is contained in:
parent
ff2c16ea7b
commit
2eb5a6ae03
@ -9,7 +9,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.aitrainer"
|
||||
version = "0.0.3"
|
||||
version = "0.0.4"
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
repositories {
|
||||
@ -22,13 +22,17 @@ dependencies {
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||
implementation("org.apache.logging.log4j:log4j-core:2.13.3")
|
||||
implementation("org.apache.logging.log4j:log4j-api:2.13.3")
|
||||
implementation("org.slf4j:slf4j-api:1.7.30")
|
||||
|
||||
|
||||
runtimeOnly("mysql:mysql-connector-java")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test") {
|
||||
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
|
||||
}
|
||||
testImplementation("junit:junit:4.13")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5:1.3.72")
|
||||
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.aitrainer.api
|
||||
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder
|
||||
@ -10,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
class ApiApplication
|
||||
|
||||
private val logger = LoggerFactory.getLogger(ApiApplication::class.simpleName)
|
||||
@Override
|
||||
fun configure(application: SpringApplicationBuilder): SpringApplicationBuilder {
|
||||
return application.sources(ApiApplication::class.java)
|
||||
@ -18,11 +19,12 @@ class ApiApplication
|
||||
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
logger.info(" ---- Start aitrainer API")
|
||||
SpringApplication.run(ApiApplication::class.java, *args)
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping( "/")
|
||||
fun hello(): String {
|
||||
return "Hello Aitrainer API";
|
||||
return "Hello Aitrainer API"
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package com.aitrainer.api.controller
|
||||
|
||||
import com.aitrainer.api.model.ExerciseType
|
||||
import com.aitrainer.api.repository.ExerciseTypeRepository
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import javax.validation.Valid
|
||||
@ -9,17 +11,27 @@ import javax.validation.Valid
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
class ExerciseTypeController ( private val exerciseTypeRepository: ExerciseTypeRepository ) {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@GetMapping("/exercise_type")
|
||||
fun getAllExerciseType(): List<ExerciseType> =
|
||||
exerciseTypeRepository.findAll()
|
||||
fun getAllExerciseType(): List<ExerciseType> {
|
||||
val list: List<ExerciseType> = exerciseTypeRepository.findAll()
|
||||
logger.info("Get All exercise types: $list")
|
||||
return list
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/exercise_type")
|
||||
fun createNewExerciseType(@Valid @RequestBody exerciseType: ExerciseType): ExerciseType =
|
||||
exerciseTypeRepository.save(exerciseType)
|
||||
fun createNewExerciseType(@Valid @RequestBody exerciseType: ExerciseType): ExerciseType {
|
||||
logger.info("Create new exercise type: $exerciseType")
|
||||
return exerciseTypeRepository.save(exerciseType)
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/exercise_type/{id}")
|
||||
fun getExerciseTypeById(@PathVariable(value = "id") exerciseTypeId: Long): ResponseEntity<ExerciseType> {
|
||||
logger.info("Get exercise type by id: $exerciseTypeId")
|
||||
return exerciseTypeRepository.findById(exerciseTypeId).map { exerciseType ->
|
||||
ResponseEntity.ok(exerciseType)
|
||||
}.orElse(ResponseEntity.notFound().build())
|
||||
@ -35,7 +47,7 @@ class ExerciseTypeController ( private val exerciseTypeRepository: ExerciseTypeR
|
||||
@PutMapping("/exercise_type/{id}")
|
||||
fun updateExerciseTypesById(@PathVariable(value = "id") exerciseTypeId: Long,
|
||||
@Valid @RequestBody newExerciseType: ExerciseType): ResponseEntity<ExerciseType> {
|
||||
|
||||
logger.info("Update exercise type by id: $exerciseTypeId with object $newExerciseType")
|
||||
return exerciseTypeRepository.findById(exerciseTypeId).map { existingExerciseType ->
|
||||
val updatedExerciseType: ExerciseType = existingExerciseType
|
||||
.copy(name = newExerciseType.name,
|
||||
|
@ -10,4 +10,6 @@ spring.datasource.password = andio2009
|
||||
|
||||
|
||||
# The SQL dialect makes Hibernate generate better SQL for the chosen database
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
|
||||
logging.config=classpath:logback-spring.xml
|
||||
logging.file=logs
|
41
src/main/resources/logback-spring.xml
Normal file
41
src/main/resources/logback-spring.xml
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<property resource="application.properties"/>
|
||||
|
||||
<appender name="FILE"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${logging.file}/aitrainer.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${logging.file}/aitrainer.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%level] [%thread] [%logger:%line] %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%level] [%thread] [%logger:%line] %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<!-- <logger name="org.springframework" level="DEBUG" /> -->
|
||||
<logger name="com.aitrainer" level="INFO" />
|
||||
<logger name="org.hibernate" level="INFO" />
|
||||
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="FILE" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
34
src/main/resources/simplelogger.properties
Normal file
34
src/main/resources/simplelogger.properties
Normal file
@ -0,0 +1,34 @@
|
||||
# SLF4J's SimpleLogger configuration file
|
||||
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
|
||||
|
||||
# Default logging detail level for all instances of SimpleLogger.
|
||||
# Must be one of ("trace", "debug", "info", "warn", or "error").
|
||||
# If not specified, defaults to "info".
|
||||
org.slf4j.simpleLogger.defaultLogLevel=debug
|
||||
|
||||
# Logging detail level for a SimpleLogger instance named "xxxxx".
|
||||
# Must be one of ("trace", "debug", "info", "warn", or "error").
|
||||
# If not specified, the default logging detail level is used.
|
||||
#org.slf4j.simpleLogger.log.xxxxx=
|
||||
|
||||
# Set to true if you want the current date and time to be included in output messages.
|
||||
# Default is false, and will output the number of milliseconds elapsed since startup.
|
||||
org.slf4j.simpleLogger.showDateTime=true
|
||||
|
||||
# The date and time format to be used in the output messages.
|
||||
# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
|
||||
# If the format is not specified or is invalid, the default format is used.
|
||||
# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
|
||||
#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z
|
||||
|
||||
# Set to true if you want to output the current thread name.
|
||||
# Defaults to true.
|
||||
#org.slf4j.simpleLogger.showThreadName=true
|
||||
|
||||
# Set to true if you want the Logger instance name to be included in output messages.
|
||||
# Defaults to true.
|
||||
#org.slf4j.simpleLogger.showLogName=true
|
||||
|
||||
# Set to true if you want the last component of the name to be included in output messages.
|
||||
# Defaults to false.
|
||||
org.slf4j.simpleLogger.showShortLogName=true
|
@ -1,8 +1,8 @@
|
||||
package com.aitrainer.api.test
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
|
||||
import java.sql.*
|
||||
import java.sql.Connection
|
||||
import java.sql.DriverManager
|
||||
import java.util.*
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertTrue
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.aitrainer.api.test
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import com.aitrainer.api.repository.CustomerRepository
|
||||
import com.aitrainer.api.model.Customer
|
||||
import com.aitrainer.api.repository.CustomerRepository
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
|
||||
@SpringBootTest
|
||||
class CustomerTests {
|
||||
|
@ -3,12 +3,14 @@ package com.aitrainer.api.test
|
||||
import com.aitrainer.api.model.ExerciseType
|
||||
import com.aitrainer.api.repository.ExerciseTypeRepository
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@SpringBootTest
|
||||
class ExerciseTypeTest {
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
@Autowired
|
||||
private lateinit var exerciseTypeRepository: ExerciseTypeRepository
|
||||
@ -17,18 +19,31 @@ class ExerciseTypeTest {
|
||||
@Test
|
||||
fun testGet() {
|
||||
val id: Long = 7
|
||||
val extype: ExerciseType = exerciseTypeRepository.findById( id ).orElse(null)
|
||||
assertEquals( extype.name, "4x10m-es ingafutás")
|
||||
val extype: ExerciseType = exerciseTypeRepository.findById(id).orElse(null)
|
||||
assertEquals(extype.name, "4x10m-es ingafutás")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetAll() {
|
||||
val exerciseTypes: List<ExerciseType> = exerciseTypeRepository.findAll()
|
||||
assertEquals(exerciseTypes[0].exerciseTypeId, 1)
|
||||
assertEquals(exerciseTypes[0].name, "Melső fekvőtámasz 1 perc")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInsert(){
|
||||
val newEx = ExerciseType( "Húzodszkodás", " A legtöbb húzodszkodást 24 óra alatt John Ort érte el 7600-al 2016-ban. ", null )
|
||||
logger.info("Add 'Húzodzkodás 2")
|
||||
val newEx = ExerciseType( "Húzodzkodás 2", " A legtöbb húzodszkodást 24 óra alatt John Ort érte el 7600-al 2016-ban. ", null )
|
||||
val savedEx: ExerciseType = exerciseTypeRepository.save(newEx)
|
||||
assertEquals(savedEx.name, "Húzodszkodás")
|
||||
assertEquals(savedEx.name, "Húzodzkodás 2")
|
||||
|
||||
this.insertedId = savedEx.exerciseTypeId
|
||||
|
||||
logger.info("Find 'Húzodzkodás 2")
|
||||
val extype: ExerciseType = exerciseTypeRepository.findById( savedEx.exerciseTypeId ).orElse(null)
|
||||
assertEquals( extype.name, "Húzodszkodás")
|
||||
|
||||
assertEquals( extype.name, "Húzodzkodás 2")
|
||||
|
||||
logger.info("Delete 'Húzodzkodás 2")
|
||||
exerciseTypeRepository.delete(extype)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user