Martee
Martee

Reputation: 77

Simple logging scala

I implemented a simple

trait Logging {
   ...
   object log {
      def info(msg: String)
      ...
   }

   //saves stuff 
   def logOut(path) = {}

setting up a full log4j takes a ton of time with all the properties file required

Logging seems to be working fine except for the fact that I need to make a logOut at the end of my main() to print or save those logs somewhere, which is inconvenient and ugly

So the questions are :

  1. Is there a way to force Logging to do something at the end of the program?
  2. Is there another good way to approach the problem?

Upvotes: 0

Views: 78

Answers (1)

Alex
Alex

Reputation: 7926

You can add Shutdown hook at the end of your program. But keep in mind that it will only be executed in case of graceful shutdown. Killing the process will not invoke this hook.

sys.addShutdownHook { println("Bye-bye") }

Upvotes: 2

Related Questions