Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KTOR-7806 Add logging with standard Okhttp-like format #4592

Merged
merged 6 commits into from
Jan 15, 2025

Conversation

Stexxe
Copy link
Contributor

@Stexxe Stexxe commented Jan 10, 2025

@Stexxe Stexxe requested review from e5l and osipxd January 10, 2025 09:33
@Stexxe Stexxe requested a review from osipxd January 10, 2025 13:09
is OutgoingContent.ContentWrapper -> calcRequestBodySize(content.delegate(), content.headers)
is OutgoingContent.NoContent -> 0
is OutgoingContent.ProtocolUpgrade -> 0
else -> error("Unable to calculate the size for type ${content::class.simpleName}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you tell me if the exception is supposed to be handled or printed?

I would return null and handle this case explicitly

Copy link
Contributor Author

@Stexxe Stexxe Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more like a guard. If the exception is thrown, then it's a bug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the test to make sure the exception is not lost

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said before, the exception will be raised only if there is a bug in the code (like an assert). I don't understand what I should test.

@@ -239,6 +613,34 @@ public val Logging: ClientPlugin<LoggingConfig> = createClientPlugin("Logging",
ResponseObserver.install(ResponseObserver.prepare { onResponse(observer) }, client)
}

private fun Url.pathQuery(): String {
return buildString {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider adding:

  • a non-empty browser test with window.location
  • test with default request plugin and relative path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test with default request plugin and relative path

Wouldn't I test the DefaultRequest plugin then? If not, can you explain the subject under test?

Copy link
Contributor Author

@Stexxe Stexxe Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a non-empty browser test with window.location

Can you explain in more detail how the test should look like?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set window.location.href = "https://ktor.io"

So this call will give you a different result:

private fun locationOrigin(): String = js(

Copy link
Contributor Author

@Stexxe Stexxe Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set window.location.href = "https://ktor.io"

So this call will give you a different result:

private fun locationOrigin(): String = js(

This method is used only within the URLBuilder.Companion.origin property, which I don't use at all.

@Stexxe Stexxe force-pushed the stexxe/logging-format-like-okhttp branch from 7e617f8 to 06034f5 Compare January 13, 2025 10:41
@Stexxe Stexxe requested a review from e5l January 13, 2025 10:43
is OutgoingContent.ContentWrapper -> calcRequestBodySize(content.delegate(), content.headers)
is OutgoingContent.NoContent -> 0
is OutgoingContent.ProtocolUpgrade -> 0
else -> error("Unable to calculate the size for type ${content::class.simpleName}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the test to make sure the exception is not lost

@Stexxe Stexxe force-pushed the stexxe/logging-format-like-okhttp branch from 06034f5 to bd1cd22 Compare January 14, 2025 13:21
@Stexxe Stexxe requested a review from e5l January 14, 2025 13:26
@Stexxe Stexxe requested a review from osipxd January 14, 2025 14:58
Copy link
Member

@e5l e5l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -165,6 +514,23 @@ public val Logging: ClientPlugin<LoggingConfig> = createClientPlugin("Logging",
return@on
}

if (okHttpFormat) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice to have extensions for okHttp format grouped in a separate file

@Stexxe Stexxe force-pushed the stexxe/logging-format-like-okhttp branch from 4ac86cf to c1e0689 Compare January 15, 2025 09:12
@Stexxe Stexxe merged commit c61cbe3 into main Jan 15, 2025
15 of 16 checks passed
@Stexxe Stexxe deleted the stexxe/logging-format-like-okhttp branch January 15, 2025 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants