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

Feat: Move logging to ZIO's official logging library #47

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added log map for demoting certain log messages
Signed-off-by: Jordan Hall <j.hall@mwam.com>
j-hall-mwam committed Dec 5, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit c130da7158005dccaae50c41aae380ad78abad64
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment on PR about exactly what functionality we are losing when going from old logger to new one?

Logging can no longer be Filtered the same way as before. ZIO does not seem to expose a way of modifying a log's level once it has been created.

Seems like you are changing log level in code?


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