Skip to content

Commit

Permalink
Track prefixes for logging listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Dec 23, 2023
1 parent 7d3b0e0 commit c9f39e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,9 @@ class HttpLoggingInterceptorTest {
return Request.Builder().url(url)
}

internal class LogRecorder : HttpLoggingInterceptor.Logger {
internal class LogRecorder(
val prefix: Regex = Regex(""),
) : HttpLoggingInterceptor.Logger {
private val logs = mutableListOf<String>()
private var index = 0

Expand All @@ -994,7 +996,7 @@ class HttpLoggingInterceptorTest {
.overridingErrorMessage("No more messages found")
.isLessThan(logs.size)
assertThat(logs[index++])
.matches(Pattern.compile("\\[\\d+ ms] ${regex.pattern}", Pattern.DOTALL))
.matches(Pattern.compile(prefix.pattern + regex.pattern, Pattern.DOTALL))
}

fun assertNoMoreLogs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class LoggingEventListenerTest {
val clientTestRule = OkHttpClientTestRule()
private lateinit var server: MockWebServer
private val handshakeCertificates = platform.localhostHandshakeCertificates()
private val logRecorder = HttpLoggingInterceptorTest.LogRecorder()
private val logRecorder = HttpLoggingInterceptorTest.LogRecorder(
prefix = Regex("""\[\d+ ms] """)
)
private val loggingEventListenerFactory = LoggingEventListener.Factory(logRecorder)
private lateinit var client: OkHttpClient
private lateinit var url: HttpUrl
Expand Down

0 comments on commit c9f39e9

Please sign in to comment.