Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@danicheg
Copy link
Member

@danicheg danicheg commented May 9, 2025

Today, I was investigating the classic thing when updating dependencies in a service that hasn’t been touched in years, and I was a bit amazed when I found this debug log (kinda cool that it got printed on that running environment though):

service raised an error: class java.lang.NoSuchMethodError

... with no additional info, like stack traces or anything meaningful else.

So, I propose to log errors by default for cases fibers exit with an error in ResponseLogger.

@mergify mergify bot added series/0.23 PRs targeting 0.23.x module:server labels May 9, 2025
object ResponseLogger {
private[this] val logger = Platform.loggerFactory.getLogger
private[this] val errorLogger =
Platform.loggerFactory.getLoggerFromName("org.http4s.server.service-errors")
Copy link
Member Author

Choose a reason for hiding this comment

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

FWIW, we're already instantiating the logger with that name in org.http4s.server, so it should be cached already.

)(implicit G: MonadCancelThrow[G], F: Async[F]): Kleisli[G, A, Response[F]] = {
val fallback: String => F[Unit] = s => logger.info(s).to[F]
val log = logAction.fold(fallback)(identity)
val errLog: (String, Throwable) => F[Unit] = (msg, th) => errorLogger.error(th)(msg).to[F]
Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps a better approach would be to add errLogAction alongside logAction, allowing users to decide how to log that case. But unfortunately, that would require duplicating a bunch of constructors to preserve binary compatibility, which I’m confident would hurt ergonomics for very little gain. Maybe I’ll revisit this in 1.0, but definitely not in 0.23.

@rossabaker rossabaker merged commit 4876202 into http4s:series/0.23 Sep 22, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:server series/0.23 PRs targeting 0.23.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants