scala-ide/scala-ide — pull request #64 by dotta (2012-01-27 09:47:36+00:00)
Title: Improved logging infrastructure and plugged Log4J in the scala-ide.sdt.core project

(I know, long message, but please read it :))

We used to have too many alternatives to create log items (Eclipse Log
framework, our ad-hoc naive internal Logger and println statements originating
from scalac). In short, we did not have an ideal logging infrastructure.

Now, I plugged Log4J as the backend logger (I'll refer to it as the "default
logger" in the rest of this commit message), which replaces our naive ad-hoc
Logger. Further, all log events occurring in the Eclipse Log Framework are now
*forwarded* to the default logger. Also, the Standard Output and Standard Error
are *redirected* to the default logger. Naturally, the idea is to have a
single place to consult the log, and that is now the *scala-ide.log* file that
is produced by the default logger, located in

${workspace}/.metadata/.plugin/org.scala-ide.sdt.core/

It's easy to consult the log from within Eclipse, just click on the menu bar
Scala > Report a Bug, and the opened popup has a link that should open the
*scala-ide.log* file in the editor (though, mind that it is not automatically
refreshed while it's open).

You can also control the amount of produced log, i.e., you can set the log
level to accomodate your preferences (the default level is WARNING). To change
it, click on the menu bar Scala > Run Setup Diagnostic and you should see a
"Logging" box. There, you can change the log level and you can also enable a
console appender to print all produced log items in the console.

To get a handle on the loggers you simply need to mix-in the HasLogger trait,
which contains a reference to both the default logger and the Eclipse Log. You
may wonder why we have two loggers. The reason is simple, if you want to
communicate a message to the user, you should use the Eclipse Log. This becayse
messages sent to the Eclipse Log are shown in the Eclipse Log View (remember
that all messages sent to the Eclipse Log are also forwarded to the default
logger, so you don't need to log the same message twice). In all other cases,
you should use th default logger.

One element I'm not happy with is that I plugged Log4J within the
scala-ide.sdt.core project and not as an external plug-in. I've tried to do so
but failed due to my lack of understanding of OSGi. This is something that I
believe we should do at some point (maybe someone can help with this?!).

Finally, as part of this commit I also deleted the lib/miglayout.jar binary and
updated the scala-ide.sdt.core POM to copy both the log4j and miglayout
dependencies in the lib/ folder. This has a consequence in our project's setup
(yes, I'll update the doc), which is: you need to compile the project from the
command line *before* starting to work on the Scala IDE sources in Eclipse.
That because the dependencies to log4j and miglayout are copied in the lib
folder when maven runs the build of the org.scala-ide.psdt.core project.

I also noticed there is some duplication in the POMs and I think we should
refactor them a bit, but that should definitely be done in a separate commit
;).

Fixes #1000880.