Skip to content

Commit

Permalink
♻️ 스케줄러 예외 메시지 로깅 방식 수정 (#255)
Browse files Browse the repository at this point in the history
* ♻️ 예외 메시지 로깅 수정

* ♻️ .gitignore 파일 수정

* ♻️ 예외 처리 방식 수정 - ex 그대로 받아서 전달
  • Loading branch information
semi-cloud authored Nov 12, 2024
1 parent 88525ed commit 11116df
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ application/src/main/resources/static

application-dev.yml
application-local.yml
application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AwsS3Client(
).withCannedAcl(CannedAccessControlList.PublicRead)
)
} catch (e: CommonException) {
logger.error(e.message, ResponseCode.BAD_REQUEST, e.stackTraceToString())
logger.error(e.message, ResponseCode.BAD_REQUEST, e)
}
return uuid
}
Expand Down
3 changes: 3 additions & 0 deletions application/src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spring:
profiles:
active: test
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ class Logger(
logger.debug { message }
}

fun warn(message: String?, code: ResponseCode, stackTrace: String) {
logger.warn { printLog(message, code, stackTrace) }
fun warn(message: String?, code: ResponseCode, ex: Exception) {
logger.warn(ex) { makeMessage(message, code) }
}

fun error(message: String?) {
logger.error { message }
}

fun error(message: String?, code: ResponseCode, stackTrace: String) {
logger.error { printLog(message, code, stackTrace) }
fun error(message: String?, code: ResponseCode, ex: Exception) {
logger.error(ex) { makeMessage(message, code) }
}

private fun printLog(message: String?, code: ResponseCode, stackTrace: String): String {
return "$message - Code: ${code.code}, Message : ${code.message}, StackTrace : $stackTrace"
private fun makeMessage(message: String?, code: ResponseCode): String {
return "$message - Code: ${code.code}, Message : ${code.message}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import backend.team.ahachul_backend.common.client.RedisClient
import backend.team.ahachul_backend.common.constant.CommonConstant.Companion.HASHTAG_LOG_DATETIME_FORMATTER
import backend.team.ahachul_backend.common.constant.CommonConstant.Companion.HASHTAG_REDIS_KEY
import backend.team.ahachul_backend.common.logging.Logger
import backend.team.ahachul_backend.common.response.ResponseCode
import backend.team.ahachul_backend.common.utils.LogAnalyzeUtils
import org.quartz.JobExecutionContext
import org.springframework.scheduling.quartz.QuartzJobBean
Expand Down Expand Up @@ -70,8 +71,10 @@ class RankHashTagJob(
pointer -= 1
}
}
} catch (ex: FileNotFoundException) {
logger.error("invalid file to read : $fileUrl")
} catch (e: FileNotFoundException) {
logger.error("file not found to read : $fileUrl")
} catch (e: Exception) {
logger.error("failed to read hash tag file : $fileUrl", ResponseCode.INTERNAL_SERVER_ERROR, e)
}

return sortByTop(map)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ class UpdateLostDataJob(
}
}
} catch (e: JsonSyntaxException) {
logger.error("invalid json format : $readPath")
logger.error("invalid json format : $readPath", ResponseCode.INTERNAL_SERVER_ERROR, e)
} catch (e: IOException) {
logger.error("no data to read from file : $readPath")
logger.error("i/o exception occurred from file : $readPath", ResponseCode.INTERNAL_SERVER_ERROR, e)
} catch (e: Exception) {
logger.error("failed to read lost112 crawling file : $readPath")
logger.error("failed to read lost112 crawling file : $readPath", ResponseCode.INTERNAL_SERVER_ERROR, e)
}
}

Expand Down
3 changes: 3 additions & 0 deletions scheduler/src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spring:
profiles:
active: test

0 comments on commit 11116df

Please sign in to comment.