scala-cli icon indicating copy to clipboard operation
scala-cli copied to clipboard

Refactor loggers to enable easier exception handling

Open Gedochao opened this issue 2 years ago • 1 comments

What is the problem? Our loggers currently have comprehensive stacktrace printing and exception handling for BuildException only, which excludes non-build-related throwables. We should be able to handle those as well, to simplify error handling in the cli layer. https://github.com/VirtusLab/scala-cli/blob/518d63de7592b665c3134b5f2b0905e7a8a4abdc/modules/core/src/main/scala/scala/build/Logger.scala#L27

Additionally, our naming for different verbosity levels is slightly off. For example, it requires deeper code knowledge to know the difference between logger.log and logger.message. https://github.com/VirtusLab/scala-cli/blob/518d63de7592b665c3134b5f2b0905e7a8a4abdc/modules/core/src/main/scala/scala/build/Logger.scala#L14 logger.message should probably be named logger.warn. a more standard logging level should probably be in place. For example, we could mimic Log4j's levels, having:

  • trace
  • debug
  • info
  • warn
  • error
  • fatal
  • log

Additional context Inspired by https://github.com/VirtusLab/scala-cli/pull/1760#discussion_r1065807688

Gedochao avatar Jan 10 '23 15:01 Gedochao

Additional refactor suggestions:

  • refactor to enable using loggers in using directive declarations
  • prefix logging messages with console-colored tags appropriate to the logging level
    • so logger.warn(msg: String) would produce smth like [${Console.YELLOW}warn${Console.RESET}] $msg

Gedochao avatar May 17 '23 10:05 Gedochao