generated from pricelees/issue-pr-template
feat: 배포 환경에서의 Slow Query 로깅을 위한 설정 추가
This commit is contained in:
parent
0c83798b3f
commit
d96c890dc0
@ -0,0 +1,29 @@
|
|||||||
|
package roomescape.common.log
|
||||||
|
|
||||||
|
import net.ttddyy.dsproxy.ExecutionInfo
|
||||||
|
import net.ttddyy.dsproxy.QueryInfo
|
||||||
|
import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel
|
||||||
|
import net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener
|
||||||
|
|
||||||
|
class MDCAwareSlowQueryListenerWithoutParams(
|
||||||
|
private val thresholdMs: Long
|
||||||
|
) : SLF4JQueryLoggingListener() {
|
||||||
|
|
||||||
|
init {
|
||||||
|
this.logLevel = SLF4JLogLevel.WARN
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun afterQuery(
|
||||||
|
execInfo: ExecutionInfo,
|
||||||
|
queryInfoList: List<QueryInfo>
|
||||||
|
) {
|
||||||
|
if (execInfo.elapsedTime >= thresholdMs) {
|
||||||
|
super.afterQuery(execInfo, queryInfoList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun writeLog(message: String) {
|
||||||
|
val modified = message.replace(Regex("""(,?\s*)Params:\[.*?]"""), "")
|
||||||
|
super.writeLog(modified)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
package roomescape.common.log
|
||||||
|
|
||||||
|
import com.zaxxer.hikari.HikariDataSource
|
||||||
|
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||||
|
import org.springframework.boot.jdbc.DataSourceBuilder
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.context.annotation.Primary
|
||||||
|
import org.springframework.context.annotation.Profile
|
||||||
|
import javax.sql.DataSource
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Profile("deploy")
|
||||||
|
@EnableConfigurationProperties(SlowQueryProperties::class)
|
||||||
|
class ProxyDataSourceConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
fun dataSource(
|
||||||
|
@Qualifier("actualDataSource") actualDataSource: DataSource,
|
||||||
|
properties: SlowQueryProperties
|
||||||
|
): DataSource = ProxyDataSourceBuilder.create(actualDataSource)
|
||||||
|
.name(properties.loggerName)
|
||||||
|
.listener(
|
||||||
|
MDCAwareSlowQueryListenerWithoutParams(
|
||||||
|
properties.thresholdMs
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.buildProxy()
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConfigurationProperties(prefix = "spring.datasource.hikari")
|
||||||
|
fun actualDataSource(): DataSource = DataSourceBuilder.create()
|
||||||
|
.type(HikariDataSource::class.java)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Profile("deploy")
|
||||||
|
@ConfigurationProperties(prefix = "slow-query")
|
||||||
|
data class SlowQueryProperties(
|
||||||
|
val loggerName: String,
|
||||||
|
val thresholdMs: Long,
|
||||||
|
)
|
||||||
@ -36,7 +36,7 @@ class RoomescapeLogMaskingConverter : MessageConverter() {
|
|||||||
|
|
||||||
private fun maskedPlainMessage(message: String): String {
|
private fun maskedPlainMessage(message: String): String {
|
||||||
val keys: String = SENSITIVE_KEYS.joinToString("|")
|
val keys: String = SENSITIVE_KEYS.joinToString("|")
|
||||||
val regex = Regex("(?i)($keys)(\\s*=\\s*)([^,\\s]+)")
|
val regex = Regex("(?i)($keys)(\\s*=\\s*)([^(,|\"|?)\\s]+)")
|
||||||
|
|
||||||
return regex.replace(message) { matchResult ->
|
return regex.replace(message) { matchResult ->
|
||||||
val key = matchResult.groupValues[1]
|
val key = matchResult.groupValues[1]
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
spring:
|
spring:
|
||||||
jpa:
|
jpa:
|
||||||
show-sql: false
|
|
||||||
properties:
|
properties:
|
||||||
hibernate:
|
hibernate:
|
||||||
format_sql: true
|
format_sql: true
|
||||||
@ -35,7 +34,7 @@ jdbc:
|
|||||||
query:
|
query:
|
||||||
enable-logging: true
|
enable-logging: true
|
||||||
log-level: DEBUG
|
log-level: DEBUG
|
||||||
logger-name: query-logger
|
logger-name: all-query-logger
|
||||||
multiline: true
|
multiline: true
|
||||||
includes: connection,query,keys,fetch
|
includes: connection,query,keys,fetch
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
<appender-ref ref="CONSOLE"/>
|
<appender-ref ref="CONSOLE"/>
|
||||||
</logger>
|
</logger>
|
||||||
|
|
||||||
<logger name="query-logger" level="debug" additivity="false">
|
<logger name="all-query-logger" level="debug" additivity="false">
|
||||||
<appender-ref ref="CONSOLE"/>
|
<appender-ref ref="CONSOLE"/>
|
||||||
</logger>
|
</logger>
|
||||||
</included>
|
</included>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user