cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

Add thread name to IO.debug

Open asarkar opened this issue 5 months ago • 0 comments
trafficstars

It'd be very useful to have the thread name in the IO.debug extension method, which is implemented as follows in v3.7-4972921. Something like IO.println(s"[${Thread.currentThread().getName}] ${prefix}: Succeeded: ${S.show(a)}").

 def debug[B >: A](prefix: String = "DEBUG")(
      implicit S: Show[B] = Show.fromToString[B]): IO[A] =
    guaranteeCase {
      case Outcome.Succeeded(ioa) =>
        ioa.flatMap(a => IO.println(s"${prefix}: Succeeded: ${S.show(a)}"))

      case Outcome.Errored(ex) =>
        IO.println(s"${prefix}: Errored: ${ex}")

      case Outcome.Canceled() =>
        IO.println(s"${prefix}: Canceled")
    }

asarkar avatar May 22 '25 10:05 asarkar