Skip to content
Merged
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 publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@ 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.
*
* 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)
Expand All @@ -34,4 +33,4 @@ trait LoggerInit {

@transient
protected lazy val logger: Logger = LoggerFactory.getLogger(getClass.getName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package com.workday.warp.logger

import com.workday.warp.config.WarpPropertyManager
import org.slf4j.{Logger, LoggerFactory}

/**
* Trait that initializes the logger configuration for Warp.
* It sets up the logger context and initializes properties for use in logger configuration.
*
* 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