otel4s icon indicating copy to clipboard operation
otel4s copied to clipboard

Use logger instead of Console[F].println

Open rochala opened this issue 2 months ago • 1 comments

Right now messages are printed to stdout e.g https://github.com/typelevel/otel4s/blob/b380dd09138dd9557c45e5386b35eae9598e30b2/sdk/logs/src/main/scala/org/typelevel/otel4s/sdk/logs/SdkLogs.scala#L238-L242

Is there any chance we could use a logger so we can filter those into another appender via logback or provide --quiet option ? I'm happy to implement the change if there is an agreement to do this.

I'm creating a language server and it communicates over stdout, so each stdout print breaks the pipe making it impossible to use.

rochala avatar Oct 04 '25 09:10 rochala

Thanks for the report. It would be problematic to add SLF4J (or Logback) dependency to the core or sdk modules.

However, Console usage has bothered me for a while. It might make sense to have our own very primitive org.typelevel.otel4s.sdk.InternalLogger type. So users can plug in any logging backend they want to log internal information properly. The default implementation can still use Console under the hood.

Ultimately, log4cats might work as a logging interface. But there could be issues with cyclic dependencies in the future.


In your particular case, you can use a noop console:

implicit val console: Console[F] = new Console[F] {
  def readLineWithCharset(charset: Charset): F[String] =
    Sync[F].delay(sys.error("not implemented"))
  def print[A](a: A)(implicit S: Show[A]): F[Unit] = Sync[F].unit
  def println[A](a: A)(implicit S: Show[A]): F[Unit] = Sync[F].unit
  def error[A](a: A)(implicit S: Show[A]): F[Unit] = Sync[F].unit
  def errorln[A](a: A)(implicit S: Show[A]): F[Unit] = Sync[F].unit
}

OpenTelemetrySdk.autoConfigured[IO](...).use { otel4s => ... }

iRevive avatar Oct 04 '25 10:10 iRevive

The new 0.15.0 release will include a console replacement.

iRevive avatar Nov 09 '25 08:11 iRevive