getkyo / kyo

Toolkit for Scala Development
https://getkyo.io
Apache License 2.0
481 stars 38 forks source link

Option to disable logging the result in KyoApp #492

Open steinybot opened 1 week ago

steinybot commented 1 week ago

It would be nice to have a bit more control over whether the result of run in a KyoApp gets logged or not.

Perhaps something simple like if it returns Unit then don't log it. Otherwise some flag that can be overriden.

I could override handle but that seems a bit heavy handed.

It is especially annoying when there is a resource release that logs when it is done such as:

  run {
    for {
      _ <- Consoles.println(s"Server is running on port $port. Press Ctrl-C to stop.")
      server <- Resources.acquireRelease(IOs(buildServer(port, services).start())) { (server: Server) =>
        for {
          _ <- Consoles.run(Consoles.print("Shutting down..."))
          _ <- IOs(server.shutdown().awaitTermination())
          _ <- Consoles.run(Consoles.println("Done."))
        } yield ()
      }
      s <- waitForInterrupt
    } yield "Goodbye!"
  }

Which will log:

Server is running on port 9001. Press Ctrl-C to stop.
Goodbye!
Shutting down...Done.

Instead of:

Server is running on port 9001. Press Ctrl-C to stop.
Shutting down...Done.
Goodbye!

Maybe I shouldn't be logging in the release but there aren't many options.