Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use slogging as cross-platform compatible logger #308

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ lazy val scalateUtil = scalateProject("util")
mimaSettings,
libraryDependencies ++= Seq(
junit % Test,
slogging.value,
logbackClassic % Test,
slf4jApi,
s"${scalaOrganization.value}.modules" %% "scala-parser-combinators" %
Expand Down
1 change: 1 addition & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ object Dependencies {
val jRubyComplete = "org.jruby" % "jruby-complete" % "9.2.14.0"
val junit = "junit" % "junit" % "4.13.1"
val karafShell = "org.apache.karaf.shell" % "org.apache.karaf.shell.console" % "4.3.0"
val slogging = Def.setting("biz.enef" %% "slogging-slf4j" % (if (scalaVersion.value < "2.13") "0.6.1" else "0.6.2"))
// TODO: upgrade to 1.5.x
val logbackClassic = "ch.qos.logback" % "logback-classic" % "1.2.3"
val osgiCore = "org.osgi" % "org.osgi.core" % "6.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
package org.fusesource.scalate.support

import java.io.{ File, PrintWriter, StringWriter }

import org.fusesource.scalate._
import org.fusesource.scalate.util.{ ClassPathBuilder, Log }
import org.fusesource.scalate.util.ClassPathBuilder
import slogging.StrictLogging

import scala.reflect.internal.util.{ FakePos, NoPosition, Position }
import scala.runtime.ByteRef
import scala.tools.nsc.{ Global, Settings }
import scala.tools.nsc.reporters.{ ConsoleReporter, Reporter }
import scala.util.parsing.input.OffsetPosition

object ScalaCompiler extends Log {
object ScalaCompiler {

def create(engine: TemplateEngine): ScalaCompiler = {
Thread.currentThread.getContextClassLoader match {
Expand All @@ -40,12 +40,10 @@ object ScalaCompiler extends Log {

}

import org.fusesource.scalate.support.ScalaCompiler._

class ScalaCompiler(
bytecodeDirectory: File,
classpath: String,
combineClasspath: Boolean = false) extends Compiler {
combineClasspath: Boolean = false) extends Compiler with StrictLogging {

val settings = generateSettings(bytecodeDirectory, classpath, combineClasspath)

Expand Down Expand Up @@ -134,10 +132,10 @@ class ScalaCompiler(
classPathFromClassLoader
}

debug("using classpath: " + useCP)
debug("system class loader: " + ClassLoader.getSystemClassLoader)
debug("context class loader: " + Thread.currentThread.getContextClassLoader)
debug("scalate class loader: " + getClass.getClassLoader)
logger.debug("using classpath: " + useCP)
logger.debug("system class loader: " + ClassLoader.getSystemClassLoader)
logger.debug("context class loader: " + Thread.currentThread.getContextClassLoader)
logger.debug("scalate class loader: " + getClass.getClassLoader)

val settings = new Settings(errorHandler)
settings.classpath.value = useCP
Expand All @@ -154,7 +152,7 @@ class ScalaCompiler(
}

protected def createCompiler(settings: Settings, reporter: Reporter): Global = {
debug("creating non-OSGi compiler")
logger.debug("creating non-OSGi compiler")
new Global(settings, reporter)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
*/
package org.fusesource.scalate.support

import java.io.{ File, PrintWriter, StringWriter }

import java.io.{File, PrintWriter, StringWriter}
import org.fusesource.scalate._
import org.fusesource.scalate.util.{ ClassPathBuilder, Log }
import org.fusesource.scalate.util.ClassPathBuilder
import slogging.StrictLogging

import scala.reflect.internal.util.{ FakePos, NoPosition, Position }
import scala.reflect.internal.util.{FakePos, NoPosition, Position}
import scala.runtime.ByteRef
import scala.tools.nsc.{ Global, Settings }
import scala.tools.nsc.reporters.{ ConsoleReporter, Reporter }
import scala.tools.nsc.{Global, Settings}
import scala.tools.nsc.reporters.{ConsoleReporter, Reporter}
import scala.util.parsing.input.OffsetPosition

object ScalaCompiler extends Log {
object ScalaCompiler {

def create(engine: TemplateEngine): ScalaCompiler = {
Thread.currentThread.getContextClassLoader match {
Expand All @@ -45,7 +45,7 @@ import org.fusesource.scalate.support.ScalaCompiler._
class ScalaCompiler(
bytecodeDirectory: File,
classpath: String,
combineClasspath: Boolean = false) extends Compiler {
combineClasspath: Boolean = false) extends Compiler with StrictLogging {

val settings = generateSettings(bytecodeDirectory, classpath, combineClasspath)

Expand Down Expand Up @@ -122,10 +122,10 @@ class ScalaCompiler(
classPathFromClassLoader
}

debug("using classpath: " + useCP)
debug("system class loader: " + ClassLoader.getSystemClassLoader)
debug("context class loader: " + Thread.currentThread.getContextClassLoader)
debug("scalate class loader: " + getClass.getClassLoader)
logger.debug("using classpath: " + useCP)
logger.debug("system class loader: " + ClassLoader.getSystemClassLoader)
logger.debug("context class loader: " + Thread.currentThread.getContextClassLoader)
logger.debug("scalate class loader: " + getClass.getClassLoader)

val settings = new Settings(errorHandler)
settings.classpath.value = useCP
Expand All @@ -142,7 +142,7 @@ class ScalaCompiler(
}

protected def createCompiler(settings: Settings, reporter: Reporter): Global = {
debug("creating non-OSGi compiler")
logger.debug("creating non-OSGi compiler")
new Global(settings, reporter)
}
}
Expand Down Expand Up @@ -211,4 +211,4 @@ class ScalaCompiler(
// combineClasspath
// )
// }
//}
//}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@
package org.fusesource.scalate

import java.io._

import org.fusesource.scalate.support.AttributesHashMap
import org.fusesource.scalate.util.{ Log, Resource }
import org.fusesource.scalate.util.Resource
import slogging.StrictLogging

import scala.collection.mutable.Stack

object DefaultRenderContext extends Log
/**
* Default implementation of [[org.fusesource.scalate.RenderContext]]
*/
class DefaultRenderContext(
private[this] val _requestUri: String,
val engine: TemplateEngine,
var out: PrintWriter = new PrintWriter(new StringWriter())) extends RenderContext {

import DefaultRenderContext._
var out: PrintWriter = new PrintWriter(new StringWriter())) extends RenderContext with StrictLogging {

val attributes: AttributeMap = new AttributesHashMap() {
update("context", DefaultRenderContext.this)
Expand Down Expand Up @@ -89,7 +86,7 @@ class DefaultRenderContext(
outStack.push(out)
out = new PrintWriter(buffer)
try {
debug("rendering template %s", template)
logger.debug("rendering template %s", template)
template.render(this)
out.close()
buffer.toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import java.io.{ File, PrintWriter, StringWriter }
import java.net.URLClassLoader
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicBoolean

import org.fusesource.scalate.filter._
import org.fusesource.scalate.jade.JadeCodeGenerator
import org.fusesource.scalate.layout.{ LayoutStrategy, NullLayoutStrategy }
Expand All @@ -30,6 +29,7 @@ import org.fusesource.scalate.scaml.ScamlCodeGenerator
import org.fusesource.scalate.ssp.SspCodeGenerator
import org.fusesource.scalate.support._
import org.fusesource.scalate.util._
import slogging.{ Logger, LoggerFactory, StrictLogging }

import scala.collection.immutable.TreeMap
import scala.collection.mutable.HashMap
Expand All @@ -40,8 +40,6 @@ import scala.xml.NodeSeq

object TemplateEngine {

val log = Log(getClass)

def apply(sourceDirectories: Iterable[File], mode: String): TemplateEngine = {
new TemplateEngine(sourceDirectories, mode)
}
Expand All @@ -66,8 +64,7 @@ object TemplateEngine {
*/
class TemplateEngine(
var sourceDirectories: Iterable[File] = None,
var mode: String = System.getProperty("scalate.mode", "production")) {
import TemplateEngine.log._
var mode: String = System.getProperty("scalate.mode", "production")) extends StrictLogging {

private case class CacheEntry(
template: Template,
Expand Down Expand Up @@ -142,7 +139,7 @@ class TemplateEngine(
} catch {
case e: Throwable =>
// if it's not, then disable class reloading..
debug("Scala compiler not found on the class path. Template reloading disabled.")
logger.debug("Scala compiler not found on the class path. Template reloading disabled.")
allowReload = false
compilerInstalled = false
}
Expand All @@ -153,7 +150,7 @@ class TemplateEngine(
Boots.invokeBoot(clazz, bootInjections)

case _ =>
info("No bootstrap class " + bootClassName + " found on classloader: " + classLoader)
logger.info("No bootstrap class " + bootClassName + " found on classloader: " + classLoader)
}
}
}
Expand Down Expand Up @@ -257,7 +254,7 @@ class TemplateEngine(

// Discover bits that can enhance the default template engine configuration. (like filters)
ClassFinder.discoverCommands[TemplateEngineAddOn]("META-INF/services/org.fusesource.scalate/addon.index").foreach { addOn =>
debug("Installing Scalate add on " + addOn.getClass)
logger.debug("Installing Scalate add on " + addOn.getClass)
addOn(this)
}

Expand Down Expand Up @@ -286,7 +283,7 @@ class TemplateEngine(
_workingDirectory = f
f.deleteOnExit
} else {
warn("Could not delete file %s so we could create a temp directory", f)
logger.warn("Could not delete file %s so we could create a temp directory", f)
_workingDirectory = new File(new File(System.getProperty("java.io.tmpdir")), "_scalate")
}
}
Expand Down Expand Up @@ -731,7 +728,7 @@ class TemplateEngine(
templateCache += (source.uri -> ce)
}
val answer = ce.template
debug("Loaded uri: " + source.uri + " template: " + answer)
logger.debug("Loaded uri: " + source.uri + " template: " + answer)
answer
}

Expand All @@ -750,7 +747,7 @@ class TemplateEngine(
new File(sourceDirectory, uri.replace(':', '_') + ".scala")
}

protected val sourceMapLog = Log(getClass, "SourceMap")
protected val sourceMapLog = LoggerFactory.getLogger(s"$loggerName.SourceMap")

private def compileAndLoad(
source: TemplateSource,
Expand Down Expand Up @@ -850,7 +847,7 @@ class TemplateEngine(
CompilerError(uri, olderror.message, pos, olderror)
}
}
error(e)
logger.error("Caught exception", e)
if (e.errors.isEmpty) {
throw e
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ package org.fusesource.scalate
import java.io.File
import java.net.{ URI, URL }
import java.util.regex.Pattern

import org.fusesource.scalate.support._
import org.fusesource.scalate.util.Strings.isEmpty
import org.fusesource.scalate.util._
import slogging.StrictLogging

import scala.io.Source

Expand All @@ -32,8 +32,7 @@ import scala.io.Source
*
* @version $Revision : 1.1 $
*/
trait TemplateSource extends Resource {
import TemplateSource.log._
trait TemplateSource extends Resource with StrictLogging {

var engine: TemplateEngine = _
private[this] var _packageName: String = ""
Expand Down Expand Up @@ -125,7 +124,7 @@ trait TemplateSource extends Resource {
if (sep != "/") {
// on windows lets replace the \ in a directory name with /
val newName = name.replace('\\', '/')
debug("converted windows path into: " + newName)
logger.debug("converted windows path into: " + newName)
newName
} else {
name
Expand Down Expand Up @@ -165,7 +164,6 @@ trait TemplateSource extends Resource {
* Helper methods to create a [[org.fusesource.scalate.TemplateSource]] from various sources
*/
object TemplateSource {
val log = Log(getClass)

/**
* Creates a [[org.fusesource.scalate.TemplateSource]] from the actual String contents using the given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.io.File
import _root_.javax.servlet.ServletContext
import _root_.org.fusesource.scalate.RenderContext
import _root_.org.fusesource.scalate.servlet.ServletRenderContext
import org.fusesource.scalate.util.{ Log, SourceMap, SourceMapInstaller }
import org.fusesource.scalate.util.{ SourceMap, SourceMapInstaller }

import scala.collection.JavaConverters._
import scala.collection.immutable.SortedMap
Expand Down Expand Up @@ -58,8 +58,6 @@ case class SourceLine(
}
}

object ConsoleHelper extends Log

/**
* Helper snippets for creating the console
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ package org.fusesource.scalate
package filter

import java.util.concurrent.atomic.AtomicBoolean

import javax.script.ScriptException
import org.fusesource.scalate.support.RenderHelper
import org.fusesource.scalate.util.Log
import slogging.StrictLogging
import tv.cntt.rhinocoffeescript.Compiler

/**
Expand All @@ -32,7 +31,7 @@ import tv.cntt.rhinocoffeescript.Compiler
*
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
*/
object CoffeeScriptFilter extends Filter with Log {
object CoffeeScriptFilter extends Filter with StrictLogging {

/**
* Server side compilation of coffeescript is enabled by default. Disable this flag
Expand All @@ -56,7 +55,7 @@ object CoffeeScriptFilter extends Filter with Log {
// we don't have rhino on the classpath
// so lets do client side compilation
if (warnedMissingRhino.compareAndSet(false, true)) {
warn("No Rhino on the classpath: " + e + ". Using client side CoffeeScript compile", e)
logger.warn("No Rhino on the classpath: " + e + ". Using client side CoffeeScript compile", e)
}
clientSideCompile
}
Expand All @@ -65,7 +64,7 @@ object CoffeeScriptFilter extends Filter with Log {
try {
CoffeeScriptCompiler.compile(content, Some(context.currentTemplate)).fold({
error =>
warn("Could not compile coffeescript: " + error, error)
logger.warn("Could not compile coffeescript: " + error, error)
throw new CompilerException(error.message, Nil)
}, {
coffee =>
Expand All @@ -88,7 +87,7 @@ object CoffeeScriptFilter extends Filter with Log {
/**
* Compiles a .coffee file into JS on the server side
*/
object CoffeeScriptPipeline extends Filter with Log {
object CoffeeScriptPipeline extends Filter with StrictLogging {

/**
* Installs the coffeescript pipeline
Expand All @@ -101,7 +100,7 @@ object CoffeeScriptPipeline extends Filter with Log {
def filter(context: RenderContext, content: String) = {
CoffeeScriptCompiler.compile(content, Some(context.currentTemplate)).fold({
error =>
warn("Could not compile coffeescript: " + error, error)
logger.warn("Could not compile coffeescript: " + error, error)
throw new CompilerException(error.message, Nil)
}, {
coffee => coffee
Expand Down
Loading