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

Expunge all unsafe logging [resolve conflicts] #7122

Merged
merged 11 commits into from
Jun 2, 2023

Conversation

iRevive
Copy link
Contributor

@iRevive iRevive commented May 23, 2023

The follow-up to #6645 (comment).

@armanbilge I hope I didn't break anything 😬

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Thank you so much for fixing this up! Seems fine to me.

Commenting on my own changes ... unfortunately this was a bit messy, but I think it's better to rip-off this bandaid. Future merges from 0.23 are going to be Fun:tm: for anything this touched.

I'll leave this open for the rest of the week to give a chance for other http4s maintainers to weigh in.

httpVersion = firstResp.httpVersion,
headers = firstResp.headers.redactSensitive(redactWhen),
).withEntity(JsonErrorHandlerResponse[G](req, mf))
}
case t =>
serviceErrorLogger
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, 'serviceErrorLogger' is defined as a def. Should we define it as a val right above the Kleisli?

): Kleisli[F, Request[G], Response[G]] = {
  val serviceErrorLogger = LoggerFactory[F].getLoggerFromName(...)
  Kleisli { req =>
  ...
  }
}

Copy link
Member

Choose a reason for hiding this comment

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

I don't see why not.

Copy link
Member

Choose a reason for hiding this comment

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

Oh good point. We can probably do the same with messageFailureLogger?

Btw is there a meaningful difference between the effectful and non-effectful APIs for obtaining a logger?
/~https://github.com/typelevel/log4cats/blob/36bfbb6bd8d89e5f81575f85c78b0f8616de5c0b/core/shared/src/main/scala/org/typelevel/log4cats/LoggerFactoryGen.scala#L21-L26

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

.fold(
_ => {
Message.logger
.warn(s"Attempt to provide a negative content length of $l")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are not logging a warning anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we log it?

Copy link
Member

Choose a reason for hiding this comment

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

I removed this in #6645 (comment) because it makes the ergonomics really bad. I don't know how useful it is.

service: Kleisli[F, Request[G], Response[G]],
redactWhen: CIString => Boolean = Headers.SensitiveHeaders.contains,
): Kleisli[F, Request[G], Response[G]] =
Kleisli { req =>
import cats.syntax.applicative._
import cats.syntax.applicativeError._
implicit def entEnc[M[_]]: EntityEncoder.Pure[JsonErrorHandlerResponse[M]] =
Copy link
Contributor Author

@iRevive iRevive May 23, 2023

Choose a reason for hiding this comment

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

Not related to the PR, but it caught my eye.
The entEnc is always used with G type parameter. Technically, we can preallocate it too:

implicit val entityEncoder: EntityEncider.Pure[JsonErrorHandlerResponse[F]] = 
  JsonErrorHandlerResponse.entEnc[M](redactWhen)

On the other hand, since it's defined as def, no error = no allocation. The same is true for loggers.

@@ -228,6 +229,7 @@ import org.http4s.circe._
import org.http4s.dsl.io._
import org.http4s.ember.server._
import org.http4s.implicits._
import org.typelevel.log4cats.slf4j._
Copy link
Contributor

Choose a reason for hiding this comment

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

importing these will cause warnings, we should use Slf4jFactory.create[IO] in app boot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I bumped logs4cats to 2.6.0 and replaced org.typelevel.log4cats.slf4j._ with Slf4jFactory.create.

@iRevive iRevive requested review from rossabaker and hamnis May 25, 2023 13:40
@armanbilge
Copy link
Member

Ok, let's rip off this bandaid. Thank you so much for getting this cleaned up, and sorry to anyone caught in the crossfire.

@armanbilge armanbilge merged commit ccaafe9 into http4s:main Jun 2, 2023
@iRevive iRevive deleted the topic/remove-log4s branch June 21, 2023 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants