diff --git a/publish.sh b/publish.sh index f2eddf22..7a63cff8 100755 --- a/publish.sh +++ b/publish.sh @@ -67,6 +67,7 @@ if [[ $RELEASE_TYPE = 'final' || $RELEASE_TYPE = 'candidate' ]] then if git remote show origin | grep "Fetch URL: git@github.com:Workday/warp-core.git"; then echo "we are on main fork, proceeding with $RELEASE_TYPE release" + ./gradlew -q clean -PallScalaVersions # create our repo tag # TODO despite being in `runOnceTasks`, it appears `candidate` is run multiple times with -PallScalaVersions, incorrectly creating multiple tags echo "creating repo tag for $RELEASE_TYPE release" diff --git a/warp-core/src/main/scala/com/workday/warp/config/WarpPropertyManager.scala b/warp-core/src/main/scala/com/workday/warp/config/WarpPropertyManager.scala index 5d9bf3e1..f914ec9f 100644 --- a/warp-core/src/main/scala/com/workday/warp/config/WarpPropertyManager.scala +++ b/warp-core/src/main/scala/com/workday/warp/config/WarpPropertyManager.scala @@ -7,6 +7,7 @@ import com.workday.warp.logger.{LoggerInit, WarpLogUtils} import org.apache.commons.configuration2.PropertiesConfiguration import org.apache.commons.configuration2.builder.fluent.Configurations import org.apache.commons.configuration2.ex.ConfigurationException +import org.slf4j.{Logger, LoggerFactory} import scala.collection.JavaConverters._ import scala.collection.mutable @@ -22,7 +23,12 @@ import scala.util.{Failure, Success, Try} * Created by tomas.mccandless on 10/21/15. * Based on a class created by michael.ottati on 3/29/13 */ -object WarpPropertyManager extends LoggerInit { +object WarpPropertyManager { + + LoggerInit.init() + + @transient + protected lazy val logger: Logger = LoggerFactory.getLogger(getClass.getName) /** * Properties containing this prefix will be passed through as system properties with this diff --git a/warp-core/src/main/scala/com/workday/warp/logger/LoggerInit.scala b/warp-core/src/main/scala/com/workday/warp/logger/LoggerInit.scala index 603db2d4..be67cf6c 100644 --- a/warp-core/src/main/scala/com/workday/warp/logger/LoggerInit.scala +++ b/warp-core/src/main/scala/com/workday/warp/logger/LoggerInit.scala @@ -10,11 +10,12 @@ import scala.util.{Failure, Try} * This trait is intended to quiesce debug entries from transitive dependencies that occur in the early stages of initialization * before we have had a chance to configure the logger properly. */ -trait LoggerInit { +object LoggerInit { - // early configuration of this log level to - // Prevent spurious log entries from commons-beanutils library, which is a transitive dependency. - getLoggerContext.foreach(_.getLogger("org.apache.commons.beanutils.converters").setLevel(Level.INFO)) + /** Early logger configuration to prevent spurious log entries. */ + def init(): Unit = { + LoggerInit.getLoggerContext.foreach(_.getLogger("org.apache.commons.beanutils.converters").setLevel(Level.INFO)) + } /** * Retrieve the LoggerContext as a Try from the ILoggerFactory. @@ -22,10 +23,8 @@ trait LoggerInit { * Because we want to programmatically configure the logger, we need some methods only available via logback rather * than slf4j. This necessitates a cast, however if slf4j is bound at runtime to some concrete implementation other * than logback (e.g., slf4j-simple), this fails. Configuration will fallback to the default for that implementation. - * - * @return Try[LoggerContext] */ - def getLoggerContext: Try[LoggerContext] = { + lazy val getLoggerContext: Try[LoggerContext] = { Try(LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext]).recoverWith { case e => logger.warn("Could not cast to logback LoggerContext at runtime, logger will run with default configuration") Failure(e) @@ -34,4 +33,4 @@ trait LoggerInit { @transient protected lazy val logger: Logger = LoggerFactory.getLogger(getClass.getName) -} +} \ No newline at end of file diff --git a/warp-core/src/main/scala/com/workday/warp/logger/WarpLogUtils.scala b/warp-core/src/main/scala/com/workday/warp/logger/WarpLogUtils.scala index ddbb33fb..88dcdf03 100644 --- a/warp-core/src/main/scala/com/workday/warp/logger/WarpLogUtils.scala +++ b/warp-core/src/main/scala/com/workday/warp/logger/WarpLogUtils.scala @@ -36,7 +36,7 @@ object WarpLogUtils extends WarpLogging { CustomLoggerLevels("com.workday.warp", this.parseLevel(WARP_CONSOLE_LOG_LEVEL.value, WARP_CONSOLE_LOG_LEVEL.defaultValue)) ) - getLoggerContext.foreach { context => + LoggerInit.getLoggerContext.foreach { context => val logEncoder: PatternLayoutEncoder = new PatternLayoutEncoder logEncoder.setContext(context) logEncoder.setPattern(LOG_FORMAT) @@ -86,7 +86,7 @@ object WarpLogUtils extends WarpLogging { * @param writerConfig - configuration properties for each new fileWriter */ def addFileWriter(writerConfig: WriterConfig): Unit = { - getLoggerContext.map { context => + LoggerInit.getLoggerContext.map { context => // Create a logEncoder for the logFileAppender val logEncoder2: PatternLayoutEncoder = new PatternLayoutEncoder logEncoder2.setContext(context) diff --git a/warp-core/src/main/scala/com/workday/warp/logger/WarpLogging.scala b/warp-core/src/main/scala/com/workday/warp/logger/WarpLogging.scala index a98ab097..4f221429 100644 --- a/warp-core/src/main/scala/com/workday/warp/logger/WarpLogging.scala +++ b/warp-core/src/main/scala/com/workday/warp/logger/WarpLogging.scala @@ -1,6 +1,7 @@ package com.workday.warp.logger import com.workday.warp.config.WarpPropertyManager +import org.slf4j.{Logger, LoggerFactory} /** * Trait that initializes the logger configuration for Warp. @@ -8,10 +9,15 @@ import com.workday.warp.config.WarpPropertyManager * * This trait is intended to be mixed into classes that require logging capabilities. */ -trait WarpLogging extends LoggerInit { +trait WarpLogging { + + LoggerInit.init() // Initializes properties for use in logger configuration WarpPropertyManager.version + + @transient + protected lazy val logger: Logger = LoggerFactory.getLogger(getClass.getName) } class WarpLoggingWrapper extends WarpLogging \ No newline at end of file