generated from pricelees/issue-pr-template
[#28] 쿠버네티스 환경 배포 #29
@ -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 {
|
||||
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 ->
|
||||
val key = matchResult.groupValues[1]
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
spring:
|
||||
jpa:
|
||||
show-sql: false
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
@ -35,7 +34,7 @@ jdbc:
|
||||
query:
|
||||
enable-logging: true
|
||||
log-level: DEBUG
|
||||
logger-name: query-logger
|
||||
logger-name: all-query-logger
|
||||
multiline: true
|
||||
includes: connection,query,keys,fetch
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
<logger name="query-logger" level="debug" additivity="false">
|
||||
<logger name="all-query-logger" level="debug" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
</included>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user