-
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 #16 from f-lab-edu/feat/4-logging-file-output
[Feat][#4] logging 기능 구현
- Loading branch information
Showing
22 changed files
with
355 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ build/ | |
.kotlin | ||
|
||
### Mac OS ### | ||
.DS_Store | ||
.DS_Store | ||
logs |
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,12 @@ | ||
FROM openjdk:17-alpine | ||
|
||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup | ||
|
||
WORKDIR /app | ||
COPY build/libs/app.jar /app/app.jar | ||
|
||
RUN chown -R appuser:appgroup /app | ||
|
||
USER appuser | ||
|
||
ENTRYPOINT ["java", "-jar", "/app/app.jar"] |
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
37 changes: 37 additions & 0 deletions
37
game-server/src/main/kotlin/game/server/config/CustomJsonProvider.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,37 @@ | ||
package game.server.config | ||
|
||
import ch.qos.logback.classic.spi.ILoggingEvent | ||
import com.fasterxml.jackson.core.JsonGenerator | ||
import game.server.dto.request.ApiRequest | ||
import game.server.dto.response.ApiResponse | ||
import game.server.dto.response.ErrorResponse | ||
import net.logstash.logback.composite.AbstractJsonProvider | ||
|
||
class CustomJsonProvider : AbstractJsonProvider<ILoggingEvent>() { | ||
|
||
override fun writeTo(generator: JsonGenerator, event: ILoggingEvent) { | ||
val message = event.argumentArray?.firstOrNull() | ||
|
||
try { | ||
when (message) { | ||
is ApiResponse<*> -> { | ||
generator.writeStringField("messageType", message.messageType) | ||
generator.writeStringField("type", message.type) | ||
generator.writeBooleanField("success", message.success) | ||
generator.writeObjectField("data", message.data) | ||
if (message is ErrorResponse<*>) generator.writeStringField("message", message.message) | ||
} | ||
is ApiRequest<*> -> { | ||
generator.writeStringField("messageType", message.messageType) | ||
generator.writeStringField("type", message.type) | ||
generator.writeObjectField("data", message.data) | ||
} | ||
else -> { | ||
generator.writeStringField("message", event.formattedMessage) | ||
} | ||
} | ||
} catch (e: Exception) { | ||
generator.writeStringField("error", e.message) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package game.server.dto | ||
|
||
import game.server.domain.Position | ||
|
||
|
||
data class EnemyInfoResponse( | ||
val enemyId: String, | ||
|
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
game-server/src/main/kotlin/game/server/dto/request/ApiRequest.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,12 @@ | ||
package game.server.dto.request | ||
|
||
sealed class ApiRequest<T>( | ||
open val type: String, | ||
val messageType: String = "request", | ||
open val data: T? | ||
) | ||
|
||
data class Request<T>( | ||
override val type: String, | ||
override val data: T | ||
) : ApiRequest<T>(type = type, data = data) |
7 changes: 4 additions & 3 deletions
7
...tlin/game/server/dto/PlayerMoveRequest.kt → ...rver/dto/request/PlayerMoveRequestData.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,10 @@ | ||
package game.server.dto | ||
package game.server.dto.request | ||
|
||
import game.server.domain.Position | ||
import game.server.dto.Direction | ||
|
||
data class PlayerMoveRequest( | ||
data class PlayerMoveRequestData( | ||
val currentPosition: Position, | ||
val direction: Direction, | ||
val speed: Int | ||
) : Request | ||
) |
26 changes: 21 additions & 5 deletions
26
game-server/src/main/kotlin/game/server/dto/response/ApiResponse.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,8 +1,24 @@ | ||
package game.server.dto.response | ||
|
||
sealed class ApiResponse { | ||
abstract val type: String | ||
} | ||
sealed class ApiResponse<T>( | ||
open val type: String, | ||
open val success: Boolean = true, | ||
open val messageType: String = "response", | ||
open val data: T? | ||
) | ||
|
||
data class Success<T>(override val type: String, val success: Boolean = true, val data: T) : ApiResponse() | ||
data class Error(override val type: String, val success: Boolean = false, val message: String) : ApiResponse() | ||
data class Response<T>( | ||
override val type: String, | ||
override val success: Boolean = true, | ||
override val data: T | ||
) : ApiResponse<T>(type = type, data = data) | ||
|
||
data class ErrorResponse<T>( | ||
override val type: String = "error", | ||
override val success: Boolean = false, | ||
val message: String, | ||
) : ApiResponse<T>( | ||
type = type, | ||
success = success, | ||
data = null | ||
) |
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
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
8 changes: 5 additions & 3 deletions
8
game-server/src/main/kotlin/game/server/handler/RequestHandler.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,8 +1,10 @@ | ||
package game.server.handler | ||
|
||
import game.server.dto.Request | ||
import com.fasterxml.jackson.core.type.TypeReference | ||
import game.server.dto.request.Request | ||
import game.server.dto.response.ApiResponse | ||
|
||
interface RequestHandler<T : Request> { | ||
fun handle(request: T): ApiResponse | ||
interface RequestHandler<D, R> { | ||
val requestTypeReference: TypeReference<Request<D>> | ||
fun handle(request: Request<D>): ApiResponse<R> | ||
} |
7 changes: 3 additions & 4 deletions
7
game-server/src/main/kotlin/game/server/handler/RequestHandlerFactory.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,16 +1,15 @@ | ||
package game.server.handler | ||
|
||
import game.server.dto.Request | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class RequestHandlerFactory( | ||
private val handlers: Map<String, RequestHandler<*>> | ||
private val handlers: Map<String, RequestHandler<*, *>> | ||
) { | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T : Request> getHandler(type: String): RequestHandler<T> { | ||
return handlers[type] as? RequestHandler<T> | ||
fun <D, R> getHandler(type: String): RequestHandler<D, R> { | ||
return handlers[type] as RequestHandler<D, R>? | ||
?: throw IllegalArgumentException("Unknown request type: $type") | ||
} | ||
} |
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
Oops, something went wrong.