Skip to content

Commit

Permalink
Add public API to get reporter from Logger
Browse files Browse the repository at this point in the history
Contrary to the previous API, now it's possible to get a reporter out of
a dumb `xsbti.Logger` that any user of the API can easily extend. This
new method covers almost all the needs that third-party developers need
to get Zinc working.
  • Loading branch information
jvican committed Jun 22, 2017
1 parent 9b174e2 commit 60820b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ public static Reporter getReporter(PrintWriter writer, ReporterConfig config) {
public static Reporter getReporter(PrintStream stream, ReporterConfig config) {
return ReporterManager.getReporter(stream, config);
}

public static Reporter getReporter(xsbti.Logger logger, ReporterConfig config) {
return ReporterManager.getReporter(logger, config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,23 @@ object ReporterManager {
def getDefaultReporterConfig: ReporterConfig =
new ReporterConfig(DefaultName, 100, UseColor, Array(), Array(), Level.INFO, NoPositionMapper)

// WARNING: Never expose this method in the public API, `ManagedLogger` is internal
def getReporter(logger: ManagedLogger, config: ReporterConfig): Reporter = {
def getReporter(logger: xsbti.Logger, config: ReporterConfig): Reporter = {
val maxErrors = config.maximumErrors()
val posMapper = config.positionMapper().toScala
if (config.fileFilters().isEmpty && config.msgFilters.isEmpty)
new ManagedLoggedReporter(maxErrors, logger, posMapper)
else {
if (config.fileFilters().isEmpty && config.msgFilters.isEmpty) {
logger match {
case managed: ManagedLogger => new ManagedLoggedReporter(maxErrors, managed, posMapper)
case _ => new LoggedReporter(maxErrors, logger, posMapper)
}
} else {
implicit def scalaPatterns(patterns: Array[java.util.regex.Pattern]): Array[Regex] =
patterns.map(_.pattern().r)
val (fileRegexes, msgRegexes) = (config.fileFilters, config.msgFilters)
new ManagedFilteredReporter(fileRegexes, msgRegexes, maxErrors, logger, posMapper)
logger match {
case managed: ManagedLogger =>
new ManagedFilteredReporter(fileRegexes, msgRegexes, maxErrors, managed, posMapper)
case _ => new FilteredReporter(fileRegexes, msgRegexes, maxErrors, logger, posMapper)
}
}
}

Expand Down

0 comments on commit 60820b1

Please sign in to comment.