spfl4j logging

This commit is contained in:
Bossanyi Tibor
2020-05-20 15:36:04 +02:00
parent ff2c16ea7b
commit 2eb5a6ae03
9 changed files with 132 additions and 22 deletions
@@ -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,
+3 -1
View File
@@ -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
View 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>
@@ -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