Skip to content

Commit

Permalink
Added log map for demoting certain log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
j-hall-mwam committed Dec 5, 2023
1 parent 67cc3f8 commit 7d25b0e
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,46 @@

package com.mwam.kafkakewl.utils.logging

import zio.*
import zio.logging.LogFormat.{quoted, space, *}
import zio.{Config, Runtime, ZLayer}
import zio.logging.slf4j.bridge.Slf4jBridge
import zio.logging.{ConsoleLoggerConfig, FileLoggerConfig, LogFilter, LogFormat}
import zio.logging.{ConsoleLoggerConfig, FileLoggerConfig, LogColor, LogFilter, LogFormat, LoggerNameExtractor}

import java.nio.file.Paths

object Logging {

private def format = LogFormat.default
private def levelMapper: LogFormat =
LogFormat.make { (builder, trace, _, logLevel, message, _, fibreRefs, _, annotations) =>
{
val loggerName = LoggerNameExtractor.loggerNameAnnotationOrTrace(trace, fibreRefs, annotations).getOrElse("zio-logger")

val newLogLevel = (logLevel, loggerName) match {
case (LogLevel.Warning, "org.apache.kafka.clients.consumer.internals.ConsumerCoordinator")
if message().contains("Offset commit failed on partition") =>
LogLevel.Info
case (LogLevel.Warning, "org.apache.kafka.clients.admin.AdminClientConfig" | "org.apache.kafka.clients.consumer.ConsumerConfig")
if message().contains("supplied but isn't a known config.") =>
LogLevel.Info
case (LogLevel.Warning, "org.apache.kafka.common.security.kerberos.KerberosLogin")
if message().contains("TGT renewal thread has been interrupted and will exit") =>
LogLevel.Info
case (LogLevel.Error, "org.apache.curator.ConnectionState") if message().contains("Authentication failed") =>
LogLevel.Warning
case _ => logLevel
}

builder.appendText(newLogLevel.label)

}
}

private def format = label("timestamp", timestamp.fixed(32)).color(LogColor.BLUE) |-|
label("level", levelMapper).highlight |-|
label("thread", fiberId).color(LogColor.WHITE) |-|
label("message", quoted(line)).highlight +
(space + label("cause", cause).highlight).filter(LogFilter.causeNonEmpty) |-| allAnnotations

private def filter =
LogFilter.acceptAll
Expand Down

0 comments on commit 7d25b0e

Please sign in to comment.