Commit 767cfeac authored by Ihrig, Arvid Conrad (ari)'s avatar Ihrig, Arvid Conrad (ari)
Browse files

Integrated Pipeline: EventLogger now uses Log4j2 Scala API for logging, moved...

Integrated Pipeline: EventLogger now uses Log4j2 Scala API for logging, moved log4j2 test config file to test resources
parent 83ac23ce
......@@ -35,7 +35,8 @@ val loggingLibs = {
"org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.10.0",
"org.apache.logging.log4j" % "log4j-api" % "2.10.0",
"org.apache.logging.log4j" % "log4j-core" % "2.10.0",
"org.apache.logging.log4j" % "log4j-1.2-api" % "2.10.0")
"org.apache.logging.log4j" % "log4j-1.2-api" % "2.10.0",
"org.apache.logging.log4j" % "log4j-api-scala_2.11" % "11.0")
scalalogLib +: log4j2Libs
}
val commonsLoggingBridgeLib = "org.apache.logging.log4j" % "log4j-jcl" % "2.5"
......
package eu.nomad_lab.integrated_pipeline
import com.typesafe.scalalogging.StrictLogging
import eu.nomad_lab.integrated_pipeline.messages._
import org.slf4j.{ Marker, MarkerFactory }
import org.apache.logging.log4j.scala.Logging
import org.apache.logging.log4j.{ Marker, MarkerManager }
object EventLogger {
val logMarker: Marker = MarkerFactory.getMarker("parsing-manager")
val baseMarker: Marker = MarkerManager.getMarker("ParsingManager")
val parseResultMarker: Marker = MarkerManager.getMarker("ParsingResult").setParents(baseMarker)
val parseSuccessMarker: Marker = MarkerManager.getMarker("ParsingSuccess").setParents(parseResultMarker)
val parseSkippedMarker: Marker = MarkerManager.getMarker("ParsingSkipped").setParents(parseResultMarker)
val parseFailureMarker: Marker = MarkerManager.getMarker("ParsingFailure").setParents(parseResultMarker)
}
/**
......@@ -12,29 +17,29 @@ object EventLogger {
* This trait stacks and can thus be combined with other EventListener-traits to create a custom
* event logging class with multiple features.
*/
trait EventLogger extends EventListener with StrictLogging {
import EventLogger.logMarker
trait EventLogger extends EventListener with Logging {
import EventLogger.baseMarker
override def processEvent(reporter: TreeParserId, message: TreeParserEvent): Unit = {
message match {
case x: TreeParserEventStart => logger.info(
logMarker,
baseMarker,
s"[TreeParser ${reporter.name}] start processing file tree " +
s"'${x.treeTask.treeBasePath}' (tree type ${x.treeTask.treeType})"
)
case x: TreeParserEventEnd => logger.info(
logMarker,
baseMarker,
s"[TreeParser ${reporter.name}] finished processing file tree " +
s"'${x.treeTask.treeBasePath}', found ${x.numCandidates} candidate files " +
s"(tree type ${x.treeTask.treeType})"
)
case x: TreeParserEventCandidate => logger.debug(
logMarker,
baseMarker,
s"[TreeParser ${reporter.name}] found candidate in file tree " +
s"'${x.treeTask.treeBasePath}' at '${x.relativePath}' (parser '${x.parser}')"
)
case x: TreeParserEventScanError => logger.warn(
logMarker,
baseMarker,
s"[TreeParser ${reporter.name}] scanning failure in file tree " +
s"'${x.treeTask.treeBasePath}' at '${x.relativePath}' (${x.error.toString})"
)
......@@ -45,12 +50,12 @@ trait EventLogger extends EventListener with StrictLogging {
override def processEvent(reporter: CalculationParserId, message: CalculationParserEvent): Unit = {
message match {
case x: CalculationParserEventStart => logger.info(
logMarker,
baseMarker,
s"[CalculationParser ${reporter.name}] start parsing file " +
s"'${x.relativePath}' in file tree '${x.treeTask.treeBasePath}' (parser '${x.parser}')"
)
case x: CalculationParserEventEnd => logger.info(
logMarker,
baseMarker,
s"[CalculationParser ${reporter.name}] finished parsing file '${x.relativePath}' in file " +
s"tree '${x.treeTask.treeBasePath}': ${x.result} (parser '${x.parser}')"
)
......@@ -61,17 +66,17 @@ trait EventLogger extends EventListener with StrictLogging {
override def processEvent(reporter: ResultWriterId, message: ResultWriterEvent): Unit = {
message match {
case x: ResultWriterEventStart => logger.info(
logMarker,
baseMarker,
s"[ResultWriter ${reporter.name}] started processing results for file tree " +
s"'${x.treeTask.treeBasePath}'"
)
case x: ResultWriterEventResult => logger.debug(
logMarker,
baseMarker,
s"[ResultWriter ${reporter.name}] processes parsing results for file '${x.relativePath}' " +
s"from file tree '${x.treeTask.treeBasePath}'"
)
case x: ResultWriterEventEnd => logger.info(
logMarker,
baseMarker,
s"[ResultWriter ${reporter.name}] finished writing results for file tree " +
s"'${x.treeTask.treeBasePath}', output location: '${x.outputLocation}' " +
s"(${x.numCalculations} calculations, ${x.numParsingFailures} parsing failures)"
......
......@@ -12,7 +12,7 @@
</Appenders>
<Loggers>
<Logger name="eu.nomad_lab" level="debug">
<MarkerFilter marker="parsing-manager" onMatch="NEUTRAL" onMismatch="DENY"/>
<MarkerFilter marker="ParsingManager" onMatch="NEUTRAL" onMismatch="DENY"/>
<AppenderRef ref="Console"/>
</Logger>
<Root level="info">
......
......@@ -26,7 +26,7 @@ trait LoggingTestBase {
val rawBytes = new ByteArrayOutputStream()
val context = LoggerContext.getContext(false)
val config = context.getConfiguration
val layout = PatternLayout.newBuilder().withPattern("%-5level - %msg%n").build()
val layout = PatternLayout.newBuilder().withPattern("%-5level [%marker] - %msg%n").build()
val appender = OutputStreamAppender.createAppender(layout, null, rawBytes, appenderName, false, true)
appender.start()
config.addAppender(appender)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment