-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from yourssu/shon
[FEAT] shon
- Loading branch information
Showing
16 changed files
with
298 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ARG ELK_VERSION | ||
FROM docker.elastic.co/elasticsearch/elasticsearch:${ELK_VERSION} | ||
RUN elasticsearch-plugin install analysis-nori |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
version: '3.7' | ||
services: | ||
es: | ||
build: | ||
# 도커파일의 위치 알려주기 | ||
context: . | ||
# 인자 넣어주기 | ||
args: | ||
ELK_VERSION: 7.15.2 | ||
container_name: es | ||
environment: | ||
- node.name=single-node | ||
- cluster.name=backtony | ||
- discovery.type=single-node | ||
ports: | ||
- 9200:9200 | ||
- 9300:9300 | ||
networks: | ||
- es-bridge | ||
|
||
kibana: | ||
container_name: kibana | ||
image: docker.elastic.co/kibana/kibana:7.15.2 | ||
environment: | ||
SERVER_NAME: kibana | ||
ELASTICSEARCH_HOSTS: http://es:9200 | ||
ports: | ||
- 5601:5601 | ||
# Elasticsearch Start Dependency | ||
depends_on: | ||
- es | ||
networks: | ||
- es-bridge | ||
|
||
networks: | ||
es-bridge: | ||
driver: bridge |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/com/yourssu/yls/app/controller/LoggingController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.yourssu.yls.app.controller | ||
|
||
import com.yourssu.yls.app.request.LoggingRequest | ||
import com.yourssu.yls.domain.service.LoggingService | ||
import com.yourssu.yls.global.dto.ResponseDTO | ||
import jakarta.validation.Valid | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/log") | ||
class LoggingController( | ||
private val loggingService: LoggingService, | ||
) { | ||
@PostMapping("/write") | ||
fun writeLog( | ||
@RequestBody @Valid request: LoggingRequest, | ||
): ResponseDTO<Void> { | ||
loggingService.writeLog(request) | ||
|
||
return ResponseDTO.success("logging 저장 성공: 성공적으로 저장되었습니다.") | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/yourssu/yls/app/request/LoggingRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.yourssu.yls.app.request | ||
|
||
import jakarta.validation.constraints.NotBlank | ||
import jakarta.validation.constraints.NotNull | ||
|
||
class LoggingRequest( | ||
@field:NotBlank | ||
val user: String, | ||
@field:NotNull | ||
val event: EventRequest, | ||
) | ||
|
||
class EventRequest( | ||
@field:NotBlank | ||
val platform: String, | ||
@field:NotBlank | ||
val screen: String, | ||
@field:NotBlank | ||
val name: String, | ||
@field:NotBlank | ||
val keyword: String, | ||
@field:NotBlank | ||
val resultID: String, | ||
) |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/yourssu/yls/app/response/LoggingResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.yourssu.yls.app.response | ||
|
||
class LoggingResponse( | ||
val user: String, | ||
val timestamp: String, | ||
val event: EventResponse, | ||
) | ||
|
||
class EventResponse( | ||
val platform: String, | ||
val screen: String, | ||
val name: String, | ||
val keyword: String, | ||
val resultID: String, | ||
) |
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/com/yourssu/yls/domain/model/document/LogDocument.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.yourssu.yls.domain.model.document | ||
|
||
import com.yourssu.yls.domain.model.nested.EventVO | ||
import org.springframework.data.annotation.Id | ||
import org.springframework.data.elasticsearch.annotations.Document | ||
import org.springframework.data.elasticsearch.annotations.Field | ||
import org.springframework.data.elasticsearch.annotations.FieldType | ||
|
||
// @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssZ", timezone = "GMT+8") | ||
// @JsonSerialize(using = LocalDateTimeSerializer::class) | ||
// @JsonDeserialize(using = LocalDateTimeDeserializer::class) | ||
|
||
@Document(indexName = "logs") | ||
class LogDocument( | ||
@Id | ||
private val id: String? = null, | ||
val user: String, | ||
// @Field(type = FieldType.Date, format = [DateFormat.date_time]) | ||
val timestamp: String, | ||
@Field(type = FieldType.Nested) | ||
val event: EventVO, | ||
) |
6 changes: 3 additions & 3 deletions
6
.../kotlin/com/yourssu/yls/common/EventVO.kt → ...ourssu/yls/domain/model/nested/EventVO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package com.yourssu.yls.common | ||
package com.yourssu.yls.domain.model.nested | ||
|
||
data class EventVO( | ||
val platform: String, | ||
val screen: String, | ||
val name: String, | ||
val keyword: String, | ||
val resultID: String | ||
) | ||
val resultID: String, | ||
) |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/yourssu/yls/domain/model/repository/LoggingRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.yourssu.yls.domain.model.repository | ||
|
||
import com.yourssu.yls.domain.model.document.LogDocument | ||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository | ||
|
||
interface LoggingRepository : ElasticsearchRepository<LogDocument, String> |
49 changes: 49 additions & 0 deletions
49
src/main/kotlin/com/yourssu/yls/domain/service/LogAssembler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.yourssu.yls.domain.service | ||
|
||
import com.yourssu.yls.app.request.LoggingRequest | ||
import com.yourssu.yls.app.response.EventResponse | ||
import com.yourssu.yls.app.response.LoggingResponse | ||
import com.yourssu.yls.domain.model.document.LogDocument | ||
import com.yourssu.yls.domain.model.nested.EventVO | ||
import java.time.LocalDateTime | ||
|
||
class LogAssembler { | ||
companion object { | ||
fun writeDto(logDocument: LogDocument): LoggingResponse { | ||
val eventDocument = logDocument.event | ||
val eventRequest = | ||
EventResponse( | ||
platform = eventDocument.platform, | ||
screen = eventDocument.screen, | ||
name = eventDocument.name, | ||
keyword = eventDocument.keyword, | ||
resultID = eventDocument.resultID, | ||
) | ||
|
||
return LoggingResponse( | ||
user = logDocument.user, | ||
timestamp = logDocument.timestamp.toString(), | ||
event = eventRequest, | ||
) | ||
} | ||
|
||
fun writeDocument(loggingRequest: LoggingRequest): LogDocument { | ||
val requestEvent = loggingRequest.event | ||
val eventVO = | ||
EventVO( | ||
platform = requestEvent.platform, | ||
screen = requestEvent.screen, | ||
name = requestEvent.name, | ||
keyword = requestEvent.keyword, | ||
resultID = requestEvent.resultID, | ||
) | ||
|
||
return LogDocument( | ||
user = loggingRequest.user, | ||
// 수정 | ||
timestamp = LocalDateTime.now().toString(), | ||
event = eventVO, | ||
) | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/yourssu/yls/domain/service/LoggingService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.yourssu.yls.domain.service | ||
|
||
import com.yourssu.yls.app.request.LoggingRequest | ||
import com.yourssu.yls.domain.model.document.LogDocument | ||
import com.yourssu.yls.domain.model.repository.LoggingRepository | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class LoggingService( | ||
private val loggingRepository: LoggingRepository, | ||
) { | ||
@Transactional | ||
fun writeLog(request: LoggingRequest) { | ||
val logDocument: LogDocument = LogAssembler.writeDocument(request) | ||
|
||
loggingRepository.save(logDocument) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/yourssu/yls/global/config/ElasticsearchConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.yourssu.yls.global.config | ||
|
||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.data.elasticsearch.client.ClientConfiguration | ||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchConfiguration | ||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories | ||
|
||
@Configuration | ||
@EnableElasticsearchRepositories | ||
class ElasticsearchConfig : ElasticsearchConfiguration() { | ||
override fun clientConfiguration(): ClientConfiguration { | ||
return ClientConfiguration | ||
.builder() | ||
.connectedTo("localhost:9200") | ||
.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.yourssu.yls.global.dto | ||
|
||
class ResponseDTO<T>( | ||
val success: Boolean, | ||
val message: String?, | ||
val result: T?, | ||
) { | ||
companion object { | ||
fun <T> success( | ||
message: String, | ||
result: T, | ||
): ResponseDTO<T> { | ||
return ResponseDTO( | ||
success = true, | ||
message = message, | ||
result = result, | ||
) | ||
} | ||
|
||
fun <T> success(message: String): ResponseDTO<T> { | ||
return ResponseDTO( | ||
success = true, | ||
message = message, | ||
result = null, | ||
) | ||
} | ||
|
||
fun <T> success(result: T): ResponseDTO<T> { | ||
return ResponseDTO( | ||
success = true, | ||
message = null, | ||
result = result, | ||
) | ||
} | ||
|
||
fun <T> fail( | ||
message: String, | ||
result: T, | ||
): ResponseDTO<T> { | ||
return ResponseDTO( | ||
success = false, | ||
message = message, | ||
result = result, | ||
) | ||
} | ||
|
||
fun <T> fail(message: String): ResponseDTO<T> { | ||
return ResponseDTO( | ||
success = false, | ||
message = message, | ||
result = null, | ||
) | ||
} | ||
|
||
fun <T> fail(result: T): ResponseDTO<T> { | ||
return ResponseDTO( | ||
success = false, | ||
message = null, | ||
result = result, | ||
) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
server: | ||
port: 8080 | ||
|
||
spring: | ||
output: | ||
ansi: | ||
enabled: always | ||
|
||
logging: | ||
file: | ||
name: ${log-path} # slf4j를 사용할 때 생기는 로그 파일 경로 | ||
level: | ||
org.hibernate.SQL: debug | ||
org.hibernate.type: trace |