Logger MDC filtering

My goal is to associate key-value pairs with my log messages so that I can better filter for associated messages. For example, I’d like to associate Line=Line1 for any log messages related to Line1. These messages might come from a multitude of loggers with a variety of message contents.

My plan was to do this using MDC:

def getLogger(loggerName, context=None):
        """Return a logger with optional MDC

        loggerName (String): the name of the logger to be built
        context ({String: String}): key-value pairs for MDC
        """
	loggerBuilder = LoggerEx.newBuilder()
	if context:
		contextualizeLoggerBuilder(loggerBuilder, context)
	logger = loggerBuilder.build(loggerName)
	return logger

def contextualizeLoggerBuilder(loggerBuilder, context):
        """Add key-value context pairs to a LoggerBuilder object.
        
        loggerBuilder (LoggerEx.LoggerBuilder): the LoggerBuilder object to contextualize
        context ({String: String}): key-value pairs for MDC
        """
	keyValueList = [a for tup in context.items() for a in tup]  # expand tuple list into plain list
	loggerBuilder.mdcContext(keyValueList)

Here are my applied filters in the log. I’ve applied two filters: Line=Line4 and MachineArea=Depal. I would expect that only entries meeting both criteria are shown.

Unfortunately, this is my output. It looks like an entry that meets either criteria is included:

Is this is expected behavior? Is there a fundamental problem with how I’m going about this?

That’s nice but what’s the question?

Hit post on accident and needed to edit, lol

I think that’s just the way the webpage works, yeah. You can always export the logs and do your own manipulation; it’s just a SQLite file. See Kindling if you want inspiration :slight_smile:

Any chance this webpage behavior would get changed such that all key-values need to be satisfied? It would make MDC filters much more useful, IMHO

I think we’re planning to revamp the web interface in the next major version, we might change the way these filters work then.

1 Like