Permalink
Browse files

Improved logging infrastructure and plugged Log4J in the scala-ide.sd…

…t.core

project.

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.  The  goal 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 open the Eclipse
Preferences, then Scala > Logging, and there is a link to open the
*scala-ide.log* file in the editor (though, mind that it is not automatically
refreshed while it's open).

From the same preference's page, you can also control the amount of produced
log, i.e., you can set the log level that better suits you (the default level
is WARNING).  If needed, you can also enable a console appender to print all
produced log items in the console (this is quite handy when doing development
on the Scala IDE sources).

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.

Finally, I removed the "plugininfo" option, which it was used to enable debug
information in the ScalaIndexBuilder. As a matter of fact, the amount of logged
information can now be easily controlled through Log Levels.

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?!).

Fixes #1000880.
  • Loading branch information...
1 parent f266bcc commit 0ff7e44b12c9193c1cb12e7e609da71608fc4336 Mirco Dotta committed Feb 3, 2012
Showing with 698 additions and 190 deletions.
  1. +3 −3 org.scala-ide.sdt.core.tests/src/scala/tools/eclipse/pc/PresentationCompilerTest.scala
  2. +1 −0 org.scala-ide.sdt.core/.classpath
  3. +2 −1 org.scala-ide.sdt.core/META-INF/MANIFEST.MF
  4. +9 −0 org.scala-ide.sdt.core/plugin.xml
  5. +38 −0 org.scala-ide.sdt.core/pom.xml
  6. +1 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaBuilder.scala
  7. +1 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaHyperlinkDetector.scala
  8. +4 −3 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaPlugin.scala
  9. +5 −4 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaPresentationCompiler.scala
  10. +7 −7 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaProject.scala
  11. +1 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaSourceIndexer.scala
  12. +1 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaToggleBreakpointAdapter.scala
  13. +2 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/BuildReporter.scala
  14. +2 −2 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/refined/EclipseRefinedBuildManager.scala
  15. +2 −2 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/AnalysisCompile.scala
  16. +3 −3 ...ala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/EclipseSbtBuildManager.scala
  17. +1 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/SbtConf.scala
  18. +1 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/completion/ScalaCompletions.scala
  19. +5 −6 org.scala-ide.sdt.core/src/scala/tools/eclipse/diagnostic/DiagnosticDialog.scala
  20. +4 −3 org.scala-ide.sdt.core/src/scala/tools/eclipse/diagnostic/ReportBugDialog.scala
  21. +1 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/diagnostic/StartupDiagnostics.scala
  22. +3 −3 org.scala-ide.sdt.core/src/scala/tools/eclipse/formatter/FormatterPreferencePage.scala
  23. +2 −2 org.scala-ide.sdt.core/src/scala/tools/eclipse/interpreter/InterpreterTabGroup.scala
  24. +1 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaClassFileProvider.scala
  25. +2 −2 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaCompilationUnit.scala
  26. +9 −24 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaIndexBuilder.scala
  27. +1 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaJavaMapper.scala
  28. +2 −2 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaOverrideIndicatorBuilder.scala
  29. +1 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaSelectionEngine.scala
  30. +1 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/jcompiler/ScalaMethodVerifierProvider.scala
  31. +34 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/EclipseLogListener.scala
  32. +63 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/EclipseLogger.scala
  33. +17 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/HasLogger.scala
  34. +6 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/Level.scala
  35. +56 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/LogManager.scala
  36. +19 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/Logger.scala
  37. +95 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/PluginLogConfigurator.scala
  38. +60 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/log4j/Log4JAdapter.scala
  39. +36 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/log4j/Log4JConfig.scala
  40. +78 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/log4j/Log4JFacade.scala
  41. +7 −0 ...scala-ide.sdt.core/src/scala/tools/eclipse/logging/ui/properties/LoggingPreferenceConstants.scala
  42. +52 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/ui/properties/LoggingPreferencePage.scala
  43. +2 −2 org.scala-ide.sdt.core/src/scala/tools/eclipse/properties/CompilerSettings.scala
  44. +0 −4 org.scala-ide.sdt.core/src/scala/tools/eclipse/properties/IDESettings.scala
  45. +0 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/properties/ScalaCompilerPreferenceInitializer.scala
  46. +3 −6 org.scala-ide.sdt.core/src/scala/tools/eclipse/properties/ScalaPreferences.scala
  47. +3 −3 org.scala-ide.sdt.core/src/scala/tools/eclipse/quickfix/ImportCompletionProposal.scala
  48. +1 −1 ...de.sdt.core/src/scala/tools/eclipse/reconciliation/ReconciliationParticipantsExtensionPoint.scala
  49. +3 −3 ...la-ide.sdt.core/src/scala/tools/eclipse/semantic/highlighting/SemanticHighlightingPresenter.scala
  50. +40 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/ui/OpenExternalFile.scala
  51. +0 −65 org.scala-ide.sdt.core/src/scala/tools/eclipse/util/DefaultLogger.scala
  52. +0 −12 org.scala-ide.sdt.core/src/scala/tools/eclipse/util/HasLogger.scala
  53. +0 −9 org.scala-ide.sdt.core/src/scala/tools/eclipse/util/Logger.scala
  54. +4 −2 org.scala-ide.sdt.core/src/scala/tools/eclipse/util/Utils.scala
  55. +2 −2 org.scala-ide.sdt.core/src/scala/tools/eclipse/wizards/AbstractNewElementWizardPage.scala
  56. +1 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/wizards/NewApplicationWizard.scala
View
6 org.scala-ide.sdt.core.tests/src/scala/tools/eclipse/pc/PresentationCompilerTest.scala
@@ -4,7 +4,7 @@ package pc
import scala.tools.eclipse.javaelements.ScalaCompilationUnit
import scala.tools.eclipse.javaelements.ScalaSourceFile
import scala.tools.eclipse.testsetup.SDTTestUtils
-import scala.tools.eclipse.util.Logger
+import scala.tools.eclipse.logging.Logger
import scala.tools.nsc.interactive.InteractiveReporter
import org.eclipse.jdt.core.ICompilationUnit
import org.junit.Assert._
@@ -31,7 +31,7 @@ class PresentationCompilerTest {
compiler.withStructure(sourceFile, keepLoaded = true) { tree =>
compiler.askOption { () =>
val overrideIndicatorBuilder = new compiler.OverrideIndicatorBuilderTraverser(unit, new java.util.HashMap) {
- override val logger = mockLogger
+ override val eclipseLog = mockLogger
}
// if the unit is not kept loaded (i.e., `keepLoaded = false`), then a message
// "Error creating override indicators" is reported. That is why this test checks
@@ -43,7 +43,7 @@ class PresentationCompilerTest {
}()
// verify
- verify(mockLogger, times(0)).error(any(), any())
+ verify(mockLogger, times(0)).error(any())
}
@Test
View
1 org.scala-ide.sdt.core/.classpath
@@ -8,5 +8,6 @@
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/miglayout-3.7.4.jar"/>
+ <classpathentry kind="lib" path="lib/log4j-1.2.16.jar" sourcepath="lib/log4j-1.2.16-sources.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
View
3 org.scala-ide.sdt.core/META-INF/MANIFEST.MF
@@ -90,5 +90,6 @@ Export-Package:
scala.tools.eclipse.wizards
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ClassPath: .,
- lib/miglayout-3.7.4.jar
+ lib/miglayout-3.7.4.jar,
+ lib/log4j-1.2.16.jar
View
9 org.scala-ide.sdt.core/plugin.xml
@@ -88,6 +88,12 @@
class="scala.tools.eclipse.properties.ImplicitsPreferencePage"
id="org.scala-ide.sdt.core.properties.Implicits"
name="Implicits">
+ </page>
+ <page
+ category="org.scala-ide.sdt.core.preferences"
+ class="scala.tools.eclipse.logging.ui.properties.LoggingPreferencePage"
+ id="org.scala-ide.sdt.core.properties.Logging"
+ name="Logging">
</page>
</extension>
@@ -745,6 +751,9 @@
<initializer
class="scala.tools.eclipse.properties.ImplicitsPagePreferenceInitializer">
</initializer>
+ <initializer
+ class="scala.tools.eclipse.logging.ui.properties.LoggingPreferencePageInitializer">
+ </initializer>
</extension>
<extension point="org.eclipse.core.expressions.propertyTesters">
View
38 org.scala-ide.sdt.core/pom.xml
@@ -13,6 +13,7 @@
<properties>
<miglayout.version>3.7.4</miglayout.version>
+ <log4j.version>1.2.16</log4j.version>
</properties>
<dependencies>
@@ -23,6 +24,30 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>${log4j.version}</version>
+ <scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jmx</groupId>
+ <artifactId>jmxri</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
<build>
@@ -97,6 +122,19 @@
<configuration>
<artifactItems>
<artifactItem>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>${log4j.version}</version>
+ <outputDirectory>${basedir}/lib</outputDirectory>
+ </artifactItem>
+ <artifactItem>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>${log4j.version}</version>
+ <outputDirectory>${basedir}/lib</outputDirectory>
+ <classifier>sources</classifier>
+ </artifactItem>
+ <artifactItem>
<groupId>com.miglayout</groupId>
<artifactId>miglayout</artifactId>
<version>${miglayout.version}</version>
View
2 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaBuilder.scala
@@ -13,7 +13,7 @@ import org.eclipse.jdt.internal.core.JavaModelManager
import org.eclipse.jdt.internal.core.builder.{ JavaBuilder, State }
import scala.tools.eclipse.javaelements.JDTUtils
import scala.tools.eclipse.util.{ FileUtils, ReflectionUtils }
-import util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
import scala.tools.nsc.interactive.RefinedBuildManager
class ScalaBuilder extends IncrementalProjectBuilder with HasLogger {
View
2 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaHyperlinkDetector.scala
@@ -13,7 +13,7 @@ import org.eclipse.jdt.internal.ui.javaeditor.{ EditorUtility, JavaElementHyperl
import org.eclipse.jdt.ui.actions.OpenAction
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor
import javaelements.{ ScalaCompilationUnit, ScalaSelectionEngine, ScalaSelectionRequestor }
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
class ScalaHyperlinkDetector extends AbstractHyperlinkDetector with HasLogger {
def detectHyperlinks(viewer: ITextViewer, region: IRegion, canShowMultipleHyperlinks: Boolean): Array[IHyperlink] = {
View
7 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaPlugin.scala
@@ -28,12 +28,13 @@ import scala.tools.eclipse.util.OSGiUtils.pathInBundle
import scala.tools.eclipse.templates.ScalaTemplateManager
import org.eclipse.jdt.ui.PreferenceConstants
import org.eclipse.core.resources.IResourceDelta
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
import org.osgi.framework.Bundle
import scala.tools.eclipse.util.Utils
import org.eclipse.jdt.core.ICompilationUnit
import scala.tools.nsc.io.AbstractFile
import scala.tools.eclipse.util.EclipseResource
+import scala.tools.eclipse.logging.PluginLogConfigurator
object ScalaPlugin {
var plugin: ScalaPlugin = _
@@ -46,7 +47,7 @@ object ScalaPlugin {
def getShell: Shell = getWorkbenchWindow map (_.getShell) orNull
}
-class ScalaPlugin extends AbstractUIPlugin with IResourceChangeListener with IElementChangedListener with IPartListener with HasLogger {
+class ScalaPlugin extends AbstractUIPlugin with PluginLogConfigurator with IResourceChangeListener with IElementChangedListener with IPartListener with HasLogger {
ScalaPlugin.plugin = this
final val HEADLESS_TEST = "sdtcore.headless"
@@ -135,7 +136,7 @@ class ScalaPlugin extends AbstractUIPlugin with IResourceChangeListener with IEl
val bundles = Option(Platform.getBundles(ScalaPlugin.plugin.libraryPluginId, null)).getOrElse(Array[Bundle]())
logger.debug("[scalaLibBundle] Found %d bundles: %s".format(bundles.size, bundles.toList.mkString(", ")))
bundles.find(b => b.getVersion().getMajor() == scalaCompilerBundleVersion.getMajor() && b.getVersion().getMinor() == scalaCompilerBundleVersion.getMinor()).getOrElse {
- logger.error("Could not find a match for %s in %s. Using default.".format(scalaCompilerBundleVersion, bundles.toList.mkString(", ")), null)
+ eclipseLog.error("Could not find a match for %s in %s. Using default.".format(scalaCompilerBundleVersion, bundles.toList.mkString(", ")), null)
Platform.getBundle(ScalaPlugin.plugin.libraryPluginId)
}
}
View
9 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaPresentationCompiler.scala
@@ -18,7 +18,8 @@ import scala.tools.nsc.util.{ BatchSourceFile, Position, SourceFile }
import scala.tools.eclipse.javaelements.{
ScalaCompilationUnit, ScalaIndexBuilder, ScalaJavaMapper, ScalaMatchLocator, ScalaStructureBuilder,
ScalaOverrideIndicatorBuilder }
-import scala.tools.eclipse.util.{ Cached, EclipseFile, EclipseResource, HasLogger }
+import scala.tools.eclipse.util.{ Cached, EclipseFile, EclipseResource }
+import scala.tools.eclipse.logging.HasLogger
import scala.tools.nsc.util.FailedInterrupt
import scala.tools.nsc.symtab.Flags
import scala.tools.eclipse.completion.CompletionProposal
@@ -137,11 +138,11 @@ class ScalaPresentationCompiler(project : ScalaProject, settings : Settings)
None
case e =>
- logger.error("Error during askOption", e)
+ eclipseLog.error("Error during askOption", e)
None
}
case e =>
- logger.error("Error during askOption", e)
+ eclipseLog.error("Error during askOption", e)
None
}
@@ -197,7 +198,7 @@ class ScalaPresentationCompiler(project : ScalaProject, settings : Settings)
}
override def logError(msg : String, t : Throwable) =
- logger.error(msg, t)
+ eclipseLog.error(msg, t)
def destroy() {
logger.info("shutting down presentation compiler on project: " + project)
View
14 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaProject.scala
@@ -24,7 +24,7 @@ import scala.tools.eclipse.properties.IDESettings
import util.SWTUtils.asyncExec
import EclipseUtils.workspaceRunnableIn
import scala.tools.eclipse.properties.CompilerSettings
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
import scala.collection.mutable.ListBuffer
import scala.actors.Actor
import org.eclipse.jdt.core.IJarEntryResource
@@ -75,14 +75,14 @@ class ScalaProject private (val underlying: IProject) extends HasLogger {
} catch {
case ex @ MissingRequirementError(required) =>
failedCompilerInitialization("could not find a required class: " + required)
- logger.error(ex)
+ eclipseLog.error(ex)
None
case ex =>
logger.info("Throwable when intializing presentation compiler!!! " + ex.getMessage)
ex.printStackTrace()
if (underlying.isOpen)
failedCompilerInitialization("error initializing Scala compiler")
- logger.error(ex)
+ eclipseLog.error(ex)
None
}
}
@@ -227,7 +227,7 @@ class ScalaProject private (val underlying: IProject) extends HasLogger {
}
case _ =>
- logger.warning("Classpath computation encountered unknown entry: " + cpe)
+ logger.warn("Classpath computation encountered unknown entry: " + cpe)
}
}
computeClasspath(javaProject, false)
@@ -361,7 +361,7 @@ class ScalaProject private (val underlying: IProject) extends HasLogger {
try {
cntnr.delete(true, monitor) // try again
} catch {
- case t => logger.error(t)
+ case t => eclipseLog.error(t)
}
}
} else
@@ -370,7 +370,7 @@ class ScalaProject private (val underlying: IProject) extends HasLogger {
try {
file.delete(true, monitor)
} catch {
- case t => logger.error(t)
+ case t => eclipseLog.error(t)
}
case _ =>
}
@@ -565,7 +565,7 @@ class ScalaProject private (val underlying: IProject) extends HasLogger {
setting.tryToSetFromPropertyValue(value)
}
} catch {
- case t: Throwable => logger.error("Unable to set setting '" + setting.name + "' to '" + value0 + "'", t)
+ case t: Throwable => eclipseLog.error("Unable to set setting '" + setting.name + "' to '" + value0 + "'", t)
}
}
View
2 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaSourceIndexer.scala
@@ -11,7 +11,7 @@ import org.eclipse.jdt.core.search.SearchDocument
import org.eclipse.jdt.internal.core.search.indexing.AbstractIndexer
import scala.tools.eclipse.javaelements.ScalaSourceFile
import scala.tools.eclipse.contribution.weaving.jdt.indexerprovider.IIndexerFactory
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
class ScalaSourceIndexerFactory extends IIndexerFactory {
override def createIndexer(document : SearchDocument) = new ScalaSourceIndexer(document);
View
2 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaToggleBreakpointAdapter.scala
@@ -20,7 +20,7 @@ import org.eclipse.ui.IWorkbenchPart
import scala.tools.eclipse.util.ReflectionUtils
import scala.tools.eclipse.javaelements.ScalaClassElement
import scala.tools.eclipse.javaelements.ScalaSourceTypeElement
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
class ScalaToggleBreakpointAdapter extends ToggleBreakpointAdapter with HasLogger { self =>
import ScalaToggleBreakpointAdapterUtils._
View
3 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/BuildReporter.scala
@@ -5,7 +5,8 @@ import scala.tools.eclipse.{EclipseBuildManager, TaskScanner, ScalaProject}
import scala.tools.nsc.Settings
import scala.tools.nsc.reporters.Reporter
import scala.tools.nsc.util.{ Position, NoPosition }
-import scala.tools.eclipse.util.{ EclipseResource, FileUtils, HasLogger }
+import scala.tools.eclipse.util.{ EclipseResource, FileUtils}
+import scala.tools.eclipse.logging.HasLogger
import scala.collection.mutable.ListBuffer
View
4 ...de.sdt.core/src/scala/tools/eclipse/buildmanager/refined/EclipseRefinedBuildManager.scala
@@ -11,7 +11,7 @@ import scala.tools.nsc.io.AbstractFile
import scala.tools.nsc.reporters.Reporter
import scala.tools.eclipse.util.{ EclipseResource, FileUtils }
import org.eclipse.core.runtime.{ SubMonitor, IPath, Path }
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
class EclipseRefinedBuildManager(project: ScalaProject, settings0: Settings)
extends RefinedBuildManager(settings0) with EclipseBuildManager with HasLogger {
@@ -82,7 +82,7 @@ class EclipseRefinedBuildManager(project: ScalaProject, settings0: Settings)
case e =>
hasErrors = true
project.buildError(IMarker.SEVERITY_ERROR, "Error in Scala compiler: " + e.getMessage, null)
- logger.error("Error in Scala compiler", e)
+ eclipseLog.error("Error in Scala compiler", e)
}
if (!hasErrors)
pendingSources.clear
View
4 ...la-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/AnalysisCompile.scala
@@ -22,7 +22,7 @@ import scala.tools.eclipse.util.EclipseResource
import java.io.File
import org.eclipse.jdt.launching.JavaRuntime
import org.eclipse.jdt.core.{ JavaCore, IJavaProject }
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
import scala.tools.eclipse.contribution.weaving.jdt.jcompiler.BuildManagerStore
class AnalysisCompile (conf: BasicConfiguration, bm: EclipseSbtBuildManager, contr: Controller) extends HasLogger {
@@ -195,7 +195,7 @@ class AnalysisCompile (conf: BasicConfiguration, bm: EclipseSbtBuildManager, con
null
case ex =>
- logger.error("Crash in the build compiler.", ex)
+ eclipseLog.error("Crash in the build compiler.", ex)
reporter.log(SbtConverter.convertToSbt(NoPosition), "The SBT builder crashed while compiling your project. This is a bug in the Scala compiler or SBT. Check the Erorr Log for details. The error message is: " + ex.getMessage(), xsbti.Severity.Error)
null
View
6 ...sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/EclipseSbtBuildManager.scala
@@ -16,7 +16,7 @@ import sbt.compiler.{JavaCompiler}
import sbt.{Process, ClasspathOptions}
import scala.tools.eclipse.util.{ EclipseResource, FileUtils }
import org.eclipse.core.resources.IResource
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
// The following code is based on sbt.AggressiveCompile
// Copyright 2010 Mark Harrah
@@ -340,7 +340,7 @@ class EclipseSbtBuildManager(val project: ScalaProject, settings0: Settings)
//ScalaPlugin.plugin.sbtScalaLib.get.toFile
val e = new Exception("Cannot find Scala library on the classpath. Verify your build path!")
project.buildError(IMarker.SEVERITY_ERROR, e.getMessage(), null)
- logger.error("Error in Scala SBT builder", e)
+ eclipseLog.error("Error in Scala SBT builder", e)
return
}
//val compJar = ScalaPlugin.plugin.sbtScalaCompiler
@@ -391,7 +391,7 @@ class EclipseSbtBuildManager(val project: ScalaProject, settings0: Settings)
case e =>
hasErrors = true
project.buildError(IMarker.SEVERITY_ERROR, "Error in Scala compiler: " + e.getMessage, null)
- logger.error("Error in Scala compiler", e)
+ eclipseLog.error("Error in Scala compiler", e)
}
if (!hasErrors)
pendingSources.clear
View
2 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/SbtConf.scala
@@ -6,7 +6,7 @@ import sbt.{ ScalaInstance, Path }
import xsbt.boot.{Launcher, Repository }
import java.io.File
import org.eclipse.core.resources.ResourcesPlugin
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
object ScalaCompilerConf {
val LIBRARY_SUFFIX = "scala-library.jar"
View
2 org.scala-ide.sdt.core/src/scala/tools/eclipse/completion/ScalaCompletions.scala
@@ -6,7 +6,7 @@ import org.eclipse.jdt.core.search.{SearchEngine, IJavaSearchConstants, SearchPa
import org.eclipse.jdt.core.IJavaElement
import scala.collection.mutable
import org.eclipse.core.runtime.NullProgressMonitor
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
/** Base class for Scala completions. No UI dependency, can be safely used in a
* headless testing environment.
View
11 org.scala-ide.sdt.core/src/scala/tools/eclipse/diagnostic/DiagnosticDialog.scala
@@ -5,21 +5,20 @@ import org.eclipse.jface.window.Window
import org.eclipse.jface.dialogs.{ MessageDialog, ErrorDialog, Dialog, IDialogConstants }
import org.eclipse.jface.action.IAction
import org.eclipse.jface.preference.IPreferenceStore
-
import org.eclipse.swt.widgets.{ List => SWTList, _ }
import org.eclipse.swt.layout.{ GridLayout, GridData }
import org.eclipse.swt.SWT
import org.eclipse.swt.events.{ ModifyListener, ModifyEvent, SelectionAdapter, SelectionListener, SelectionEvent }
import org.eclipse.swt.graphics.{ Font, FontData }
-
import org.eclipse.jdt.ui.PreferenceConstants
import org.eclipse.jdt.internal.ui.preferences.PreferencesMessages
import org.eclipse.jdt.internal.corext.util.Messages
-
import org.eclipse.core.runtime.IStatus
import scala.tools.eclipse.contribution.weaving.jdt.configuration.{ WeavingStateConfigurer }
import org.eclipse.ui.PlatformUI
-import org.eclipse.ui.browser.IWorkbenchBrowserSupport
+import org.eclipse.ui.browser.IWorkbenchBrowserSupport
+import scala.tools.eclipse.logging.LogManager
+import scala.tools.eclipse.logging.HasLogger
class DiagnosticDialog(shell: Shell) extends Dialog(shell) {
@@ -226,7 +225,7 @@ class DiagnosticDialog(shell: Shell) extends Dialog(shell) {
link.addListener(SWT.Selection, DiagnosticDialog.linkListener)
}
-
+
val otherGroup = newGroup("Additional", control, new GridLayout(1, true))
val knownIssuesLink = new Link(otherGroup, SWT.NONE)
@@ -405,5 +404,5 @@ object DiagnosticDialog {
case e: Exception => e.printStackTrace
}
}
- }
+ }
}
View
7 org.scala-ide.sdt.core/src/scala/tools/eclipse/diagnostic/ReportBugDialog.scala
@@ -3,12 +3,13 @@ package scala.tools.eclipse
package diagnostic
import org.eclipse.jface.dialogs.{ Dialog, IDialogConstants }
-
import org.eclipse.swt.widgets.{ List => SWTList, _ }
import org.eclipse.swt.layout.{ GridLayout, GridData }
import org.eclipse.swt.SWT
import org.eclipse.swt.events.{ ModifyListener, ModifyEvent, SelectionAdapter, SelectionListener, SelectionEvent }
import org.eclipse.core.runtime.Platform
+import scala.tools.eclipse.logging.LogManager
+
class ReportBugDialog(shell: Shell) extends Dialog(shell) {
@@ -34,8 +35,8 @@ class ReportBugDialog(shell: Shell) extends Dialog(shell) {
val reportBugLink = new Link(control, SWT.NONE)
reportBugLink.setText("<a href=\"" + SDT_TRACKER_URL + "\">Report a bug</a> on Assembla")
- reportBugLink.addListener(SWT.Selection, DiagnosticDialog.linkListener)
-
+ reportBugLink.addListener(SWT.Selection, DiagnosticDialog.linkListener)
+
control
}
View
2 org.scala-ide.sdt.core/src/scala/tools/eclipse/diagnostic/StartupDiagnostics.scala
@@ -6,7 +6,7 @@ package diagnostic
import org.eclipse.jface.dialogs.MessageDialog
import org.eclipse.jface.dialogs.IDialogConstants
import util.SWTUtils.asyncExec
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
object StartupDiagnostics extends HasLogger {
import ScalaPlugin.plugin
View
6 org.scala-ide.sdt.core/src/scala/tools/eclipse/formatter/FormatterPreferencePage.scala
@@ -39,7 +39,7 @@ import scala.tools.eclipse.util.FileUtils._
import scala.tools.eclipse.util.SWTUtils._
import scalariform.formatter._
import scalariform.formatter.preferences._
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
class FormatterPreferencePage extends PropertyPage with IWorkbenchPreferencePage with HasLogger {
import FormatterPreferencePage._
@@ -352,7 +352,7 @@ class FormatterPreferencePage extends PropertyPage with IWorkbenchPreferencePage
PreferencesImporterExporter.savePreferences(fileName, preferences)
catch {
case e: IOException =>
- logger.error(e)
+ eclipseLog.error(e)
MessageDialog.openError(getShell, "Error writing to " + fileName, e.getMessage)
}
}
@@ -364,7 +364,7 @@ class FormatterPreferencePage extends PropertyPage with IWorkbenchPreferencePage
PreferencesImporterExporter.loadPreferences(fileName)
catch {
case e: IOException =>
- logger.error(e)
+ eclipseLog.error(e)
MessageDialog.openError(getShell, "Error opening " + fileName, e.getMessage)
return
}
View
4 org.scala-ide.sdt.core/src/scala/tools/eclipse/interpreter/InterpreterTabGroup.scala
@@ -22,7 +22,7 @@ import org.eclipse.ui.dialogs._
import org.eclipse.core.runtime._
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants
import scala.tools.eclipse.ScalaPlugin
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
/**
* This defines the configuration UI for a scala interpeter launch configuration.
@@ -164,7 +164,7 @@ class InterpreterMainTab extends JavaLaunchTab with HasLogger {
catch {
case jme : JavaModelException =>
//TODO - Log
- logger.error("Java model exception", jme);
+ eclipseLog.error("Java model exception", jme);
}
val scalaProject= getScalaProject();
if (scalaProject != null) {
View
2 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaClassFileProvider.scala
@@ -11,7 +11,7 @@ import org.eclipse.jdt.internal.core.{ ClassFile, PackageFragment }
import scala.tools.eclipse.contribution.weaving.jdt.cfprovider.IClassFileProvider
import scala.tools.eclipse.ScalaClassFileDescriber
import org.eclipse.jdt.core.IClassFile
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
class ScalaClassFileProvider extends IClassFileProvider with HasLogger {
override def create(contents : Array[Byte], parent : PackageFragment, name : String) : ClassFile =
View
4 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaCompilationUnit.scala
@@ -33,7 +33,7 @@ import org.eclipse.jdt.core.ISourceReference
import org.eclipse.jdt.core.IParent
import org.eclipse.jdt.internal.core.JavaElement
import org.eclipse.jdt.internal.core.SourceRefElement
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
import scala.tools.nsc.interactive.Response
trait ScalaCompilationUnit extends Openable with env.ICompilationUnit with ScalaElement with IScalaCompilationUnit with IBufferChangedListener with HasLogger {
@@ -116,7 +116,7 @@ trait ScalaCompilationUnit extends Openable with env.ICompilationUnit with Scala
private def handleCrash(msg: String, ex: Throwable) {
if (lastCrash != ex) {
lastCrash = ex
- logger.error(msg, ex)
+ eclipseLog.error(msg, ex)
}
}
View
33 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaIndexBuilder.scala
@@ -29,22 +29,13 @@ import scala.tools.eclipse.properties.ScalaPluginSettings
*/
trait ScalaIndexBuilder { self : ScalaPresentationCompiler =>
- object IndexBuilderTraverser {
- lazy val store = ScalaPlugin.plugin.getPreferenceStore
- lazy val infoName =
- SettingConverterUtil.convertNameToProperty(ScalaPluginSettings.YPlugininfo.name)
- @inline def isInfo = store.getBoolean(infoName)
- }
-
- import IndexBuilderTraverser.isInfo
-
class IndexBuilderTraverser(indexer : ScalaSourceIndexer) extends Traverser {
var packageName = new StringBuilder
def addPackage(p : PackageDef) = {
if (!packageName.isEmpty) packageName.append('.')
if (p.name != nme.EMPTY_PACKAGE_NAME && p.name != nme.ROOTPKG) {
- if (isInfo) logger.info("Package defn: "+p.name+" ["+this+"]")
+ logger.debug("Package defn: "+p.name+" ["+this+"]")
packageName.append(p.name)
}
}
@@ -73,24 +64,22 @@ trait ScalaIndexBuilder { self : ScalaPresentationCompiler =>
private def addAnnotations(sym: Symbol) =
for (ann <- sym.annotations) {
- if (isInfo) logger.info("added annotation %s [using symbols]".format(ann.atp))
+ logger.debug("added annotation %s [using symbols]".format(ann.atp))
indexer.addAnnotationTypeReference(ann.atp.toString.toCharArray)
}
private def addAnnotationRef(tree: Tree) {
for (t <- tree) t match {
case New(tpt) =>
- if (isInfo) logger.info("added annotation %s [using trees]".format(tpt))
+ logger.debug("added annotation %s [using trees]".format(tpt))
indexer.addAnnotationTypeReference(tpt.toString.toCharArray)
case _ => ()
}
}
def addClass(c : ClassDef) {
- if (isInfo) {
- logger.info("Class defn: "+c.name+" ["+this+"]")
- logger.info("Parents: "+c.impl.parents)
- }
+ logger.debug("Class defn: "+c.name+" ["+this+"]")
+ logger.debug("Parents: "+c.impl.parents)
indexer.addClassDeclaration(
mapModifiers(c.mods),
@@ -107,8 +96,7 @@ trait ScalaIndexBuilder { self : ScalaPresentationCompiler =>
}
def addModule(m : ModuleDef) {
- if (isInfo)
- logger.info("Module defn: "+m.name+" ["+this+"]")
+ logger.debug("Module defn: "+m.name+" ["+this+"]")
indexer.addClassDeclaration(
mapModifiers(m.mods),
@@ -134,8 +122,7 @@ trait ScalaIndexBuilder { self : ScalaPresentationCompiler =>
}
def addVal(v : ValDef) {
- if (isInfo)
- logger.info("Val defn: >"+nme.getterName(v.name)+"< ["+this+"]")
+ logger.debug("Val defn: >"+nme.getterName(v.name)+"< ["+this+"]")
indexer.addMethodDeclaration(
nme.getterName(v.name).toChars,
@@ -155,8 +142,7 @@ trait ScalaIndexBuilder { self : ScalaPresentationCompiler =>
}
def addDef(d : DefDef) {
- if (isInfo)
- logger.info("Def defn: "+d.name+" ["+this+"]")
+ logger.debug("Def defn: "+d.name+" ["+this+"]")
val name = if(nme.isConstructorName(d.name)) enclClassNames.head else d.name.toChars
val fps = for(vps <- d.vparamss; vp <- vps) yield vp
@@ -211,8 +197,7 @@ trait ScalaIndexBuilder { self : ScalaPresentationCompiler =>
case md : ModuleDef => inClass(md.name.append("$").toChars) { super.traverse(tree) }
case Apply(rt : RefTree, args) =>
- if (isInfo)
- logger.info("method reference: "+rt.name+" ["+args.length+"]")
+ logger.debug("method reference: "+rt.name+" ["+args.length+"]")
indexer.addMethodReference(rt.name.toChars, args.length)
super.traverse(tree)
View
2 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaJavaMapper.scala
@@ -10,7 +10,7 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants
import scala.tools.nsc.symtab.Flags
import scala.tools.eclipse.ScalaPresentationCompiler
import ch.epfl.lamp.fjbg.{ JObjectType, JType }
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
trait ScalaJavaMapper extends ScalaAnnotationHelper with HasLogger { self : ScalaPresentationCompiler =>
View
4 ...ala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaOverrideIndicatorBuilder.scala
@@ -14,7 +14,7 @@ import scala.tools.eclipse.contribution.weaving.jdt.IScalaOverrideIndicator
import org.eclipse.ui.texteditor.ITextEditor
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility
import scala.tools.eclipse.{ ScalaPresentationCompiler, ScalaPlugin }
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
object ScalaOverrideIndicatorBuilder {
val OVERRIDE_ANNOTATION_TYPE = "org.eclipse.jdt.ui.overrideIndicator"
@@ -76,7 +76,7 @@ trait ScalaOverrideIndicatorBuilder { self : ScalaPresentationCompiler =>
} else annotationMap.put(ScalaIndicator(scu, text, base, isOverwrite), position)
}
} catch {
- case ex => logger.error("Error creating override indicators for %s".format(scu.file.path), ex)
+ case ex => eclipseLog.error("Error creating override indicators for %s".format(scu.file.path), ex)
}
case _ =>
}
View
2 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaSelectionEngine.scala
@@ -19,7 +19,7 @@ import org.eclipse.jdt.internal.codeassist.impl.{ AssistParser, Engine }
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants
import org.eclipse.jdt.internal.compiler.env.{ICompilationUnit, AccessRestriction}
import org.eclipse.jdt.internal.core.{ JavaElement, SearchableEnvironment }
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
class ScalaSelectionEngine(nameEnvironment: SearchableEnvironment, requestor: ISelectionRequestor, settings: ju.Map[_, _]) extends Engine(settings) with ISearchRequestor with HasLogger {
View
2 org.scala-ide.sdt.core/src/scala/tools/eclipse/jcompiler/ScalaMethodVerifierProvider.scala
@@ -7,7 +7,7 @@ import org.eclipse.core.runtime.Path
import org.eclipse.core.resources.ResourcesPlugin
import scala.tools.eclipse.ScalaProject
import org.eclipse.core.resources.IProject
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
import scala.tools.eclipse.util.Utils
import org.eclipse.ui.IEditorInput
import org.eclipse.ui.IFileEditorInput
View
34 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/EclipseLogListener.scala
@@ -0,0 +1,34 @@
+package scala.tools.eclipse.logging
+
+import org.eclipse.core.runtime.ILogListener
+import org.eclipse.core.runtime.ILog
+import org.eclipse.core.runtime.IStatus
+import scala.collection.mutable.StringBuilder
+import org.eclipse.core.runtime.Status
+
+/**
+ * This class forwards to the provided {{{Logger}}} all log requests occurring in the Eclipse
+ * logging framework.
+ * The idea is to collected all produced logs in a single place. */
+class EclipseLogListener(log: ILog, logger: Logger) extends ILogListener {
+ require(log != null, "<log> is null")
+ require(logger != null, "<logger> is null")
+
+ // Attach {{{this}}} listener to the eclipse logging framework (important!)
+ log.addLogListener(this)
+
+ /** Remove {{{this}}} listener from the Eclipse logging framework. */
+ def dispose() { log.removeLogListener(this) }
+
+ override def logging(status: IStatus, plugin: String) {
+
+ lazy val message = "%s - %s - %s - %s".format(plugin, status.getPlugin, status.getCode, status.getMessage)
+
+ status.getSeverity() match {
+ case IStatus.INFO => logger.info(message, status.getException)
+ case IStatus.WARNING => logger.warn(message, status.getException)
+ case IStatus.ERROR => logger.error(message, status.getException)
+ case IStatus.CANCEL => logger.info(message, status.getException)
+ }
+ }
+}
View
63 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/EclipseLogger.scala
@@ -0,0 +1,63 @@
+package scala.tools.eclipse.logging
+
+import org.eclipse.core.runtime.Status
+import scala.tools.eclipse.ScalaPlugin
+import org.eclipse.core.runtime.{ ILog, IStatus }
+import scala.util.control.ControlThrowable
+
+private[logging] object EclipseLogger extends Logger {
+ private final val pluginLogger: ILog = ScalaPlugin.plugin.getLog
+
+ def debug(message: => Any) {
+ info(message)
+ }
+
+ def debug(message: => Any, t: Throwable) {
+ info(message, t)
+ }
+
+ def info(message: => Any) {
+ info(message, null)
+ }
+
+ def info(message: => Any, t: Throwable) {
+ log(IStatus.INFO, message, t)
+ }
+
+ def warn(message: => Any) {
+ warn(message, null)
+ }
+
+ def warn(message: => Any, t: Throwable) {
+ log(IStatus.WARNING, message, t)
+ }
+
+ def error(message: => Any) {
+ error(message, null)
+ }
+
+ def error(message: => Any, t: Throwable) {
+ log(IStatus.ERROR, message, t)
+ }
+
+ def fatal(message: => Any) {
+ error(message)
+ }
+
+ def fatal(message: => Any, t: Throwable) {
+ error(message, t)
+ }
+
+ private def log(severity: Int, message: => Any, t: Throwable = null) {
+ pluginLogger.log(createStatus(severity, message, t))
+ t match {
+ case ce: ControlThrowable =>
+ pluginLogger.log(createStatus(IStatus.ERROR, "Incorrectly logged ControlThrowable: " + ce.getClass.getSimpleName + "(" + ce.getMessage + ")", t))
+ case _ => () // do nothing
+ }
+ }
+
+ private def createStatus(severity: Int, message: Any, exception: Throwable): Status = {
+ new Status(severity, ScalaPlugin.plugin.getBundle.getSymbolicName, message.toString, exception)
+ }
+}
View
17 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/HasLogger.scala
@@ -0,0 +1,17 @@
+package scala.tools.eclipse.logging
+
+/**
+ * Classes can mix this trait for having access to both the "default" {{{logger}}}
+ * and the {{{eclipseLog}}}. The {{{eclipseLog}}} is a handle on the
+ * {{{org.eclipse.core.runtime.Plugin.getLog}} instance.
+ *
+ * Clients can inject different loggers if needed.
+ */
+trait HasLogger {
+ protected[this] lazy val logger: Logger = {
+ val clazz = this.getClass
+ LogManager.getLogger(clazz)
+ }
+
+ protected[this] def eclipseLog: Logger = EclipseLogger
+}
View
6 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/Level.scala
@@ -0,0 +1,6 @@
+package scala.tools.eclipse.logging
+
+/** Available log levels. */
+object Level extends Enumeration {
+ val DEBUG, INFO, WARN, ERROR, FATAL = Value
+}
View
56 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/LogManager.scala
@@ -0,0 +1,56 @@
+package scala.tools.eclipse.logging
+
+import scala.tools.eclipse.logging.log4j.Log4JFacade
+import scala.tools.eclipse.ScalaPlugin
+import org.eclipse.jdt.internal.ui.viewsupport.IProblemChangedListener
+import org.eclipse.jface.util.IPropertyChangeListener
+import org.eclipse.jface.util.PropertyChangeEvent
+import org.eclipse.jdt.ui.PreferenceConstants
+import scala.tools.eclipse.util.SWTUtils
+import java.io.File
+
+object LogManager extends Log4JFacade with HasLogger {
+ import ui.properties.LoggingPreferenceConstants._
+
+ private def updateLogLevel: IPropertyChangeListener = {
+ SWTUtils.fnToPropertyChangeListener { event =>
+ if (event.getProperty == LogLevel) {
+ val level = event.getNewValue.asInstanceOf[String]
+ setLogLevel(Level.withName(level))
+ }
+ }
+ }
+
+ private def updateConsoleAppenderStatus: IPropertyChangeListener = {
+ SWTUtils.fnToPropertyChangeListener { event =>
+ if (event.getProperty == IsConsoleAppenderEnabled) {
+ val enable = event.getNewValue.asInstanceOf[Boolean]
+ updateConsoleAppender(enable)
+ }
+ }
+ }
+
+ override protected def logFileName = "scala-ide.log"
+
+ override def configure(logOutputLocation: String, preferredLogLevel: Level.Value) {
+ super.configure(logOutputLocation, preferredLogLevel)
+ ScalaPlugin.plugin.getPreferenceStore.addPropertyChangeListener(updateLogLevel)
+ ScalaPlugin.plugin.getPreferenceStore.addPropertyChangeListener(updateConsoleAppenderStatus)
+ }
+
+ override protected def setLogLevel(level: Level.Value) {
+ super.setLogLevel(level)
+ logger.info("Log level is `%s`".format(level))
+ }
+
+ override def currentLogLevel: Level.Value = {
+ val levelName = ScalaPlugin.plugin.getPreferenceStore.getString(LogLevel)
+ if (levelName.isEmpty) defaultLogLevel
+ else Level.withName(levelName)
+ }
+
+ private[logging] def defaultLogLevel: Level.Value = Level.WARN
+
+ override def isConsoleAppenderEnabled: Boolean =
+ ScalaPlugin.plugin.getPreferenceStore.getBoolean(IsConsoleAppenderEnabled)
+}
View
19 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/Logger.scala
@@ -0,0 +1,19 @@
+package scala.tools.eclipse.logging
+
+/** Defines the contract for implementing a Logger.*/
+trait Logger {
+ def info(message: => Any)
+ def info(message: => Any, t: Throwable)
+
+ def debug(message: => Any)
+ def debug(message: => Any, t: Throwable)
+
+ def warn(message: => Any)
+ def warn(message: => Any, t: Throwable)
+
+ def error(message: => Any)
+ def error(message: => Any, t: Throwable)
+
+ def fatal(message: => Any)
+ def fatal(message: => Any, t: Throwable)
+}
View
95 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/PluginLogConfigurator.scala
@@ -0,0 +1,95 @@
+package scala.tools.eclipse.logging
+
+import java.net.URL
+import scala.util.control.Exception.Catch
+import org.eclipse.core.runtime.IStatus
+import org.eclipse.core.runtime.Status
+import org.eclipse.ui.plugin.AbstractUIPlugin
+import org.osgi.framework.BundleContext
+
+/**
+ * This trait can be used to configure an Eclipse plug-in to use an external logging framework (such as Log4J).
+ * When mixed-in, the following steps are executed:
+ *
+ * - Programmatically configure the external logging framework.
+ * - Install a listener to forward to the external logging framework all log Events occurring in the Eclipse Log framework.
+ * - Redirect to the external logging framework all messages sent to the Standard Output/Error.
+ */
+trait PluginLogConfigurator extends AbstractUIPlugin with HasLogger {
+
+ /** Listen to log events occurring in the Eclipse log framework and redirect them to the plug-in logger. */
+ private var eclipseLogListener: EclipseLogListener = _
+
+ /** This method is called upon plug-in activation. */
+ override def start(context: BundleContext) {
+ super.start(context)
+ configure()
+ }
+
+ /** This method is called when the plug-in is stopped */
+ override def stop(context: BundleContext) {
+ super.stop(context);
+ Option(eclipseLogListener) map (_.dispose())
+ }
+
+ /**
+ * Configure logging, redirects standard output/error in to the plug-in's logger and also forward
+ * all log event happening in the Eclipse Error Log view in to the plug-in's logger.
+ */
+ private def configure() {
+ LogManager.configure(getStateLocation.toOSString, LogManager.currentLogLevel)
+ installEclipseLogEventsListener()
+ redirectStdOutAndStdErr()
+ }
+
+ private def installEclipseLogEventsListener() {
+ assert(eclipseLogListener == null)
+ val pluginLogger = LogManager.getLogger(getBundle.getSymbolicName)
+ eclipseLogListener = new EclipseLogListener(getLog, pluginLogger)
+ }
+
+ private def redirectStdOutAndStdErr() {
+ StreamRedirect.redirectStdOutput(logger)
+ StreamRedirect.redirectStdError(logger)
+ }
+}
+
+private[logging] object StreamRedirect {
+ import java.io.{ OutputStream, PrintStream }
+
+ private var isStdOutRedirected = false
+ private var isStdErrRedirected = false
+
+ def redirectStdOutput(logger: Logger): Unit = synchronized {
+ if (!isStdOutRedirected) {
+ val outStream = redirect(msg => logger.info(msg))
+ System.setOut(outStream)
+ isStdOutRedirected = true
+ }
+ }
+
+ def redirectStdError(logger: Logger): Unit = synchronized {
+ if (!isStdErrRedirected) {
+ val errStream = redirect(msg => logger.error(msg))
+ System.setErr(errStream)
+ isStdErrRedirected = true
+ }
+ }
+
+ private def redirect(to: Any => Unit): PrintStream =
+ new PrintStream(new Redirect(to), /*autoFlush = */true)
+
+ private class Redirect(to: Any => Unit) extends OutputStream {
+ override def write(b: Int) {
+ to(String.valueOf(b.asInstanceOf[Char]))
+ }
+
+ override def write(b: Array[Byte], off: Int, len: Int) {
+ to(new String(b, off, len));
+ }
+
+ override def write(b: Array[Byte]) {
+ write(b, 0, b.size);
+ }
+ }
+}
View
60 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/log4j/Log4JAdapter.scala
@@ -0,0 +1,60 @@
+package scala.tools.eclipse.logging.log4j
+
+import scala.tools.eclipse.logging.Logger
+import org.apache.log4j.{Logger => Log4JLogger}
+
+private[log4j] object Log4JAdapter {
+ def apply(name: String): Logger = {
+ val logger = Log4JLogger.getLogger(name)
+ new Log4JAdapter(logger)
+ }
+}
+
+/** A thin wrapper around Log4J Logger. */
+private class Log4JAdapter private (logger: Log4JLogger) extends Logger {
+
+ // Mind that each method's implementation checks if the corresponding log's level
+ // is enabled to avoid the cost of constructing the {{{message}}}. And that is the
+ // reason for passing {{{message}}} by-name.
+
+
+ def info(message: => Any) {
+ if(logger.isInfoEnabled) logger.info(message)
+ }
+
+ def info(message: => Any, t: Throwable) {
+ if(logger.isInfoEnabled) logger.info(message, t)
+ }
+
+ def debug(message: => Any) {
+ if(logger.isDebugEnabled) logger.debug(message)
+ }
+
+ def debug(message: => Any, t: Throwable) {
+ if(logger.isDebugEnabled) logger.debug(message, t)
+ }
+
+ def warn(message: => Any) {
+ if(logger.isEnabledFor(org.apache.log4j.Level.WARN)) logger.warn(message)
+ }
+
+ def warn(message: => Any, t: Throwable) {
+ if(logger.isEnabledFor(org.apache.log4j.Level.WARN)) logger.warn(message, t)
+ }
+
+ def error(message: => Any) {
+ if(logger.isEnabledFor(org.apache.log4j.Level.ERROR)) logger.error(message)
+ }
+
+ def error(message: => Any, t: Throwable) {
+ if(logger.isEnabledFor(org.apache.log4j.Level.ERROR)) logger.error(message, t)
+ }
+
+ def fatal(message: => Any) {
+ if(logger.isEnabledFor(org.apache.log4j.Level.FATAL)) logger.fatal(message)
+ }
+
+ def fatal(message: => Any, t: Throwable) {
+ if(logger.isEnabledFor(org.apache.log4j.Level.FATAL)) logger.fatal(message, t)
+ }
+}
View
36 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/log4j/Log4JConfig.scala
@@ -0,0 +1,36 @@
+package scala.tools.eclipse.logging.log4j
+
+import org.apache.log4j.{ Level => Log4JLevel }
+import org.apache.log4j.RollingFileAppender
+import org.apache.log4j.PatternLayout
+import org.apache.log4j.ConsoleAppender
+import java.io.File
+
+/** This class is used to programmatically configure log4j. */
+private[log4j] class Log4JConfig(logManager: Log4JFacade) {
+
+ private lazy val layout = new PatternLayout("%d %5p [%t] - %c - %m%n")
+
+ private lazy val consoleAppender = new ConsoleAppender(layout, ConsoleAppender.SYSTEM_OUT)
+
+ def configure(logFile: File, preferredLogLevel: Log4JLevel) {
+ val appender = new RollingFileAppender(layout, logFile.getAbsolutePath, true)
+
+ val rootLogger = logManager.getRootLogger
+ rootLogger.setLevel(preferredLogLevel)
+ rootLogger.addAppender(appender)
+
+ if(logManager.isConsoleAppenderEnabled)
+ addConsoleAppender()
+ }
+
+ def addConsoleAppender() {
+ val rootLogger = logManager.getRootLogger
+ rootLogger.addAppender(consoleAppender)
+ }
+
+ def removeConsoleAppender() {
+ val rootLogger = logManager.getRootLogger
+ rootLogger.removeAppender(consoleAppender)
+ }
+}
View
78 org.scala-ide.sdt.core/src/scala/tools/eclipse/logging/log4j/Log4JFacade.scala
@@ -0,0 +1,78 @@
+package scala.tools.eclipse.logging
+package log4j
+
+import java.net.URL
+import scala.tools.eclipse.logging.Logger
+import org.apache.log4j.spi.HierarchyEventListener
+import org.apache.log4j.Appender
+import org.apache.log4j.Category
+import org.apache.log4j.FileAppender
+import org.apache.log4j.{ Level => Log4JLevel }
+import org.apache.log4j.{ Logger => Log4JLogger }
+import org.apache.log4j.LogManager
+import org.apache.log4j.PropertyConfigurator
+import scala.tools.eclipse.logging.Level
+import java.io.File
+
+/**
+ * This class offers a facade over Log4J and exposes only the Log4J's
+ * features that we currently use/need (which, in practice, are not that many).
+ */
+private[logging] abstract class Log4JFacade {
+
+ private final val config: Log4JConfig = new Log4JConfig(this)
+
+ private var _logFile: File = _
+
+ def logFile: File = synchronized { _logFile }
+
+ protected def logFileName: String
+
+ def configure(logOutputLocation: String, preferredLogLevel: Level.Value) {
+ synchronized {
+ _logFile = new File(logOutputLocation + java.io.File.separator + logFileName)
+ }
+ config.configure(_logFile, toLog4JLevel(preferredLogLevel))
+ }
+
+ private[log4j] def getRootLogger: Log4JLogger = LogManager.getRootLogger
+
+ def currentLogLevel: Level.Value
+
+ /** Programmatically change the root logger's log level. */
+ protected def setLogLevel(level: Level.Value) {
+ val log4JLevel = toLog4JLevel(level)
+ LogManager.getRootLogger.setLevel(log4JLevel)
+ }
+
+ private def toLog4JLevel(level: Level.Value): Log4JLevel = level match {
+ case Level.DEBUG => Log4JLevel.DEBUG
+ case Level.INFO => Log4JLevel.INFO
+ case Level.WARN => Log4JLevel.WARN
+ case Level.ERROR => Log4JLevel.ERROR
+ case Level.FATAL => Log4JLevel.FATAL
+ }
+
+ protected def updateConsoleAppender(enable: Boolean) {
+ if (enable) config.addConsoleAppender()
+ else config.removeConsoleAppender()
+ }
+
+ def isConsoleAppenderEnabled: Boolean
+
+ /** Factory for Log4J logger's instance.*/
+ private object Logger {
+ def apply(clazz: Class[_]): Logger = {
+ val name = if (clazz.isAnonymousClass()) clazz.getName else clazz.getSimpleName
+ this(name)
+ }
+
+ def apply(name: String): Logger = log4j.Log4JAdapter(name)
+ }
+
+ /** Get the logger instance for the passed {{{clazz}}}. */
+ def getLogger(clazz: Class[_]): Logger = Logger(clazz)
+
+ /** Get the logger instance for the passed {{{name}}}. */
+ def getLogger(name: String): Logger = Logger(name)
+}
View
7 ...e.sdt.core/src/scala/tools/eclipse/logging/ui/properties/LoggingPreferenceConstants.scala
@@ -0,0 +1,7 @@
+package scala.tools.eclipse.logging.ui.properties
+
+private[logging] object LoggingPreferenceConstants {
+ private final val Prefix = "scala.tools.eclipse.logging.ui.properties."
+ final val LogLevel = Prefix + "LogLevel"
+ final val IsConsoleAppenderEnabled = Prefix + "ConsoleAppenderEnabled"
+}
View
52 ...la-ide.sdt.core/src/scala/tools/eclipse/logging/ui/properties/LoggingPreferencePage.scala
@@ -0,0 +1,52 @@
+package scala.tools.eclipse.logging.ui.properties
+
+import scala.tools.eclipse.logging.Level
+import scala.tools.eclipse.logging.LogManager
+import scala.tools.eclipse.ui.OpenExternalFile
+import scala.tools.eclipse.ScalaPlugin
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer
+import org.eclipse.jface.preference.BooleanFieldEditor
+import org.eclipse.jface.preference.ComboFieldEditor
+import org.eclipse.jface.preference.FieldEditorPreferencePage
+import org.eclipse.swt.widgets.Composite
+import org.eclipse.swt.widgets.Control
+import org.eclipse.swt.widgets.Link
+import org.eclipse.swt.SWT
+import org.eclipse.ui.IWorkbench
+import org.eclipse.ui.IWorkbenchPreferencePage
+
+class LoggingPreferencePage extends FieldEditorPreferencePage with IWorkbenchPreferencePage {
+
+ setPreferenceStore(ScalaPlugin.plugin.getPreferenceStore)
+
+ setDescription("General settings for managing logging information in the plugin.")
+
+ override def createFieldEditors() {
+ val sortedLevels = Level.values.toArray.sortBy(_.id)
+ val namesAndValues = sortedLevels.map(v => Array(v.toString, v.toString))
+
+ addField(new ComboFieldEditor(LoggingPreferenceConstants.LogLevel, "Log Level", namesAndValues, getFieldEditorParent))
+ addField(new BooleanFieldEditor(LoggingPreferenceConstants.IsConsoleAppenderEnabled, "Output log in terminal", getFieldEditorParent))
+ }
+
+ override def createContents(parent: Composite): Control = {
+ val control = super.createContents(parent)
+
+ val link = new Link(parent, SWT.NONE)
+ link.setText("Click <a>here</a> to open the log file")
+ link.addListener(SWT.Selection, OpenExternalFile(LogManager.logFile))
+
+ control
+ }
+
+ def init(workbench: IWorkbench) {}
+}
+
+class LoggingPreferencePageInitializer extends AbstractPreferenceInitializer {
+ override def initializeDefaultPreferences() {
+ val store = ScalaPlugin.plugin.getPreferenceStore
+ store.setDefault(LoggingPreferenceConstants.LogLevel, LogManager.defaultLogLevel.toString)
+ store.setDefault(LoggingPreferenceConstants.IsConsoleAppenderEnabled, false)
+ }
+}
View
4 org.scala-ide.sdt.core/src/scala/tools/eclipse/properties/CompilerSettings.scala
@@ -25,7 +25,7 @@ import org.eclipse.swt.events.VerifyEvent
import scala.tools.nsc.CompilerCommand
import org.eclipse.jface.fieldassist._
import org.eclipse.jface.bindings.keys.KeyStroke
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
trait ScalaPluginPreferencePage extends HasLogger {
self: PreferencePage with EclipseSettings =>
@@ -227,7 +227,7 @@ class CompilerSettings extends PropertyPage with IWorkbenchPreferencePage with E
buildIfNecessary()
true
} catch {
- case ex => logger.error(ex); false
+ case ex => eclipseLog.error(ex); false
}
//Make sure apply button isn't available until it should be
View
4 org.scala-ide.sdt.core/src/scala/tools/eclipse/properties/IDESettings.scala
@@ -32,15 +32,11 @@ object IDESettings {
List(YpresentationDebug, YpresentationVerbose, YpresentationLog, YpresentationReplay, YpresentationDelay)))
}
- def pluginSettings: List[Box] =
- List(Box("Scala Plugin Debugging", List(YPlugininfo)))
-
def buildManagerSettings: List[Box] =
List(Box("Build manager", List(buildManager, compileOrder)))
}
object ScalaPluginSettings extends Settings {
- val YPlugininfo = BooleanSetting("-plugininfo", "Enable logging of the Scala Plugin info")
val buildManager = ChoiceSetting("-buildmanager", "which", "Build manager to use", List("refined", "sbt"), "sbt")
val compileOrder = ChoiceSetting("-compileorder", "which", "Compilation order",
List("Mixed", "JavaThenScala", "ScalaThenJava"), "Mixed")
View
1 ...-ide.sdt.core/src/scala/tools/eclipse/properties/ScalaCompilerPreferenceInitializer.scala
@@ -37,7 +37,6 @@ class ScalaCompilerPreferenceInitializer extends AbstractPreferenceInitializer {
}
IDESettings.shownSettings(new Settings).foreach {_.userSettings.foreach (defaultPreference)}
- IDESettings.pluginSettings.foreach {_.userSettings.foreach (defaultPreference)}
IDESettings.buildManagerSettings.foreach {_.userSettings.foreach(defaultPreference)}
}
}
View
9 org.scala-ide.sdt.core/src/scala/tools/eclipse/properties/ScalaPreferences.scala
@@ -17,7 +17,7 @@ import org.eclipse.core.resources.IProject
import scala.tools.eclipse.ScalaPlugin
import scala.tools.nsc.Settings
import scala.tools.eclipse.{SettingConverterUtil }
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
class ScalaPreferences extends PropertyPage with IWorkbenchPreferencePage with EclipseSettings
with ScalaPluginPreferencePage with HasLogger {
@@ -31,8 +31,7 @@ class ScalaPreferences extends PropertyPage with IWorkbenchPreferencePage with E
/** Returns the id of what preference page we use */
import EclipseSetting.toEclipseBox
- lazy val scalaBoxes = IDESettings.pluginSettings
- lazy val eclipseBoxes = scalaBoxes.map { s => toEclipseBox(s, getPreferenceStore) }
+ override val eclipseBoxes: List[EclipseSetting.EclipseBox] = Nil
def createContents(parent : Composite) : Control = {
val composite = {
@@ -66,7 +65,7 @@ class ScalaPreferences extends PropertyPage with IWorkbenchPreferencePage with E
save()
true
} catch {
- case ex => logger.error(ex); false
+ case ex => eclipseLog.error(ex); false
}
def updateApply = updateApplyButton
@@ -83,8 +82,6 @@ class ScalaPreferences extends PropertyPage with IWorkbenchPreferencePage with E
}
def save(): Unit = {
- save(scalaBoxes, getPreferenceStore)
-
//Don't let user click "apply" again until a change
updateApplyButton
}
View
6 org.scala-ide.sdt.core/src/scala/tools/eclipse/quickfix/ImportCompletionProposal.scala
@@ -8,7 +8,7 @@ import org.eclipse.jface.text.{TextUtilities, IDocument}
import org.eclipse.swt.graphics.{Point, Image}
import scala.tools.eclipse.refactoring.EditorHelpers
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
import scala.tools.refactoring.implementations.AddImportStatement
case class ImportCompletionProposal(val importName: String) extends IJavaCompletionProposal with HasLogger {
@@ -29,7 +29,7 @@ case class ImportCompletionProposal(val importName: String) extends IJavaComplet
applyByASTTransformation(document)
} catch {
case t => {
- logger.error("failed to update import by AST transformation, fallback to text implementation", t)
+ eclipseLog.error("failed to update import by AST transformation, fallback to text implementation", t)
applyByTextTransformation(document)
}
}
@@ -50,7 +50,7 @@ case class ImportCompletionProposal(val importName: String) extends IJavaComplet
compiler.askLoadedTyped(sourceFile, r)
(r.get match {
case Right(error) =>
- logger.error(error)
+ eclipseLog.error(error)
None
case _ =>
compiler.askOption {() =>
View
2 ...ore/src/scala/tools/eclipse/reconciliation/ReconciliationParticipantsExtensionPoint.scala
@@ -8,7 +8,7 @@ import org.eclipse.core.runtime.CoreException
import org.eclipse.core.runtime.{Platform, IProgressMonitor}
import org.eclipse.jdt.core.WorkingCopyOwner
import scala.tools.eclipse.javaelements.ScalaCompilationUnit
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
import scala.tools.eclipse.util.Utils
/**
View
6 ...dt.core/src/scala/tools/eclipse/semantic/highlighting/SemanticHighlightingPresenter.scala
@@ -21,7 +21,7 @@ import scala.collection.mutable.SynchronizedMap
import scala.collection.mutable.HashMap
import scala.tools.eclipse.javaelements.ScalaCompilationUnit
import scala.tools.eclipse.properties.ImplicitsPreferencePage.{P_ITALIC, P_BOLD, P_ACTIVE}
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
import scala.tools.eclipse.{ScalaSourceFileEditor, ScalaPresentationCompiler}
import scala.tools.nsc.util.SourceFile
@@ -211,9 +211,9 @@ class SemanticHighlightingPresenter(editor: FileEditorInput, sourceViewer: ISour
case Some(Left(_)) =>
annotationsToAdd = findAllImplicitConversions(compiler, sourceFile)
case Some(Right(exc)) =>
- logger.error(exc)
+ eclipseLog.error(exc)
case None =>
- logger.warning("Timeout while waiting for `askLoadedTyped` during implicit highlighting.")
+ logger.warn("Timeout while waiting for `askLoadedTyped` during implicit highlighting.")
}
}
View
40 org.scala-ide.sdt.core/src/scala/tools/eclipse/ui/OpenExternalFile.scala
@@ -0,0 +1,40 @@
+package scala.tools.eclipse.ui
+
+import org.eclipse.core.filesystem.EFS
+import org.eclipse.core.runtime.Path
+import org.eclipse.ui.PartInitException
+import org.eclipse.ui.ide.IDE
+import java.io.File
+import org.eclipse.swt.widgets.Listener
+import scala.tools.eclipse.logging.HasLogger
+import org.eclipse.swt.widgets.Event
+import org.eclipse.ui.PlatformUI
+
+/** This class can be used to open an editor on a file outside the workspace. */
+private class OpenExternalFile private (file: File) extends Listener with HasLogger {
+ require(file != null, "file should not be null.")
+ require(file.exists, "file %s does not exist.".format(file.getAbsolutePath))
+
+ import scala.util.control.Exception.catching
+
+ def handleEvent(e: Event): Unit = {
+ val parentLocation = file.getParent
+ var fileStore = EFS.getLocalFileSystem().getStore(new Path(parentLocation));
+
+ val fileName = file.getName
+ fileStore = fileStore.getChild(fileName)
+ if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
+ val wb = PlatformUI.getWorkbench
+ val win = wb.getActiveWorkbenchWindow
+ val page = win.getActivePage
+
+ catching(classOf[PartInitException]) {
+ IDE.openEditorOnFileStore(page, fileStore)
+ }
+ }
+ }
+}
+
+object OpenExternalFile {
+ def apply(file: File): Listener = new OpenExternalFile(file)
+}
View
65 org.scala-ide.sdt.core/src/scala/tools/eclipse/util/DefaultLogger.scala
@@ -1,65 +0,0 @@
-package scala.tools.eclipse.util
-
-import scala.tools.eclipse.ScalaPlugin
-import org.eclipse.core.runtime.Status
-import org.eclipse.core.runtime.IStatus
-import scala.util.control.ControlThrowable
-
-private[util] object DefaultLogger {
- def apply(clazz: Class[_]): Logger = {
- val name = if(clazz.isAnonymousClass()) clazz.getName else clazz.getSimpleName
- new DefaultLogger(name)
- }
-}
-
-/**
- * The `DefaultLogger` is a minimal implementation of a logger.
- * On the one hand, calling {{{info}}} or {{{debug}}} will output
- * in the standard out the passed message.
- * On the other hand, calling {{{warning}}} or {{{error}}} will push the
- * passed message in the Eclipse Error View component.
- *
- * By making this implementation package private we avoid that it leaks out
- * (only the Logger's interface is public), so please do not change this.
- *
- * [In the future the default logger should become somewhat more robust and
- * easy to configure, using Log4J or similar seem a good solution.
- */
-private class DefaultLogger(name: String) extends Logger {
- private object Category extends Enumeration {
- val INFO, DEBUG, ERROR = Value
- }
-
- import Category._
-
- override def info(message: String) = log(message, INFO)
- override def debug(message: String) = log(message, DEBUG)
-
- private def log(message: String, cat: Value = INFO) = {
- val printer = if (cat eq ERROR) System.err else System.out
-
- printer.format("[%s] %s%n", name, message)
- }
-
- import ScalaPlugin.plugin
-
- override def warning(msg: String): Unit = ScalaPlugin.plugin.getLog.log(new Status(IStatus.WARNING, plugin.pluginId, msg))
-
- override def error(t: Throwable): Unit = error(t.getClass + ":" + t.getMessage, t)
-
- override def error(msg: String, t: Throwable): Unit = {
- val t1 = if (t != null) t else { val ex = new Exception; ex.fillInStackTrace; ex }
- val status1 = new Status(IStatus.ERROR, ScalaPlugin.plugin.pluginId, IStatus.ERROR, msg, t1)
- plugin.getLog.log(status1)
-
- val status = t match {
- case ce: ControlThrowable =>
- val t2 = { val ex = new Exception; ex.fillInStackTrace; ex }
- val status2 = new Status(
- IStatus.ERROR, plugin.pluginId, IStatus.ERROR,
- "Incorrectly logged ControlThrowable: " + ce.getClass.getSimpleName + "(" + ce.getMessage + ")", t2)
- plugin.getLog.log(status2)
- case _ =>
- }
- }
-}
View
12 org.scala-ide.sdt.core/src/scala/tools/eclipse/util/HasLogger.scala
@@ -1,12 +0,0 @@
-package scala.tools.eclipse.util
-
-/**
- * Classes can mix this trait for having access to the `logger`.
- * Clients are allowed to inject a different logger.
- */
-trait HasLogger {
- protected[this] val logger: Logger = {
- val clazz = this.getClass
- DefaultLogger(clazz)
- }
-}
View
9 org.scala-ide.sdt.core/src/scala/tools/eclipse/util/Logger.scala
@@ -1,9 +0,0 @@
-package scala.tools.eclipse.util
-
-trait Logger {
- def info(message: String)
- def debug(message: String)
- def warning(message: String)
- def error(t: Throwable)
- def error(message: String, t: Throwable)
-}
View
6 org.scala-ide.sdt.core/src/scala/tools/eclipse/util/Utils.scala
@@ -1,5 +1,7 @@
package scala.tools.eclipse.util
+import scala.tools.eclipse.logging.HasLogger
+
object Utils extends HasLogger {
/** Return the time in ms required to evaluate `f()`. */
@@ -22,8 +24,8 @@ object Utils extends HasLogger {
catch {
case t =>
msgIfError match {
- case Some(errMsg) => logger.error(errMsg, t)
- case None => logger.error(t)
+ case Some(errMsg) => eclipseLog.error(errMsg, t)
+ case None => eclipseLog.error(t)
}
None
}
View
4 org.scala-ide.sdt.core/src/scala/tools/eclipse/wizards/AbstractNewElementWizardPage.scala
@@ -51,7 +51,7 @@ import collection.Seq
import collection.mutable.Buffer
import scala.tools.eclipse.ScalaPlugin._
import scala.tools.eclipse.formatter.ScalaFormatterCleanUpProvider
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
abstract class AbstractNewElementWizardPage extends NewTypeWizardPage(1, "") with HasLogger {
@@ -375,7 +375,7 @@ abstract class AbstractNewElementWizardPage extends NewTypeWizardPage(1, "") wit
cu.commitWorkingCopy(true, new SubProgressMonitor(monitor, 1))
parentCU.discardWorkingCopy
} catch {
- case ex: JavaModelException => logger.error(ex)
+ case ex: JavaModelException => eclipseLog.error(ex)
} finally {
monitor done
}
View
2 org.scala-ide.sdt.core/src/scala/tools/eclipse/wizards/NewApplicationWizard.scala
@@ -8,7 +8,7 @@ import scala.tools.nsc.util.Chars._
import scala.tools.eclipse.formatter.FormatterPreferences
import scala.tools.eclipse.util.EclipseUtils._
import scala.tools.eclipse.util.Utils._
-import scala.tools.eclipse.util.HasLogger
+import scala.tools.eclipse.logging.HasLogger
import scala.tools.eclipse.ScalaPlugin
import scalariform.formatter.ScalaFormatter

0 comments on commit 0ff7e44

Please sign in to comment.