-
Notifications
You must be signed in to change notification settings - Fork 81
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
A simple logger tree-based filtering #204
Conversation
Very useful when using the SLF4j bridge (#202) |
def filterByTree[A](root: LogFilterNode): (LogContext, => A) => Boolean = | ||
(ctx, _) => { | ||
val loggerName = ctx.get(LogAnnotation.Name).flatMap(_.split('.')) | ||
val logLevel = findMostSpecificLogLevel(loggerName, root) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you check what will be performance impact of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet, I can add some benchmarks to have an understanding. And then it could be probably improved with a cache or something.
} | ||
|
||
private def buildLogFilterTree(rootLevel: LogLevel, mappings: Seq[(String, LogLevel)]): LogFilterNode = { | ||
def add(tree: LogFilterNode, names: List[String], level: LogLevel): LogFilterNode = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably should use Chunk
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but note that the LogAnnotation.Name
has a type of List[String]
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I forgot about. we should probably change that in the future
I created some benchmarks and also wrote a simple
For me this looks like the tree-based filter is comparable to a hand-written one (for a few nodes in the tree, which is the normal use case to my experience - thinking of the number of differently configured loggers in a typical log4j config for example). |
import scala.annotation.tailrec | ||
|
||
object LogFiltering { | ||
case class LogFilterNode(logLevel: LogLevel, children: Map[String, LogFilterNode]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
@jdegoes I believe this is ready to merge |
Introduces a simple hierarchic name-based filtering method that is similar to other logging systems. The filter is defined by a list of names tied to minimum log levels.