# Logger MDC filtering

**URL:** <https://forum.inductiveautomation.com/t/logger-mdc-filtering/61173>\
**Category:** Ignition\
**Tags:** ignition80, scripting\
**Created:** [June 24, 2022, 4:16pm UTC](https://forum.inductiveautomation.com/t/logger-mdc-filtering/61173 "2022-06-24T16:16:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![srunde](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@srunde](https://forum.inductiveautomation.com/u/srunde)\
**Post date:** [June 24, 2022, 4:16pm UTC](https://forum.inductiveautomation.com/t/logger-mdc-filtering/61173/1 "2022-06-24T16:16:44Z")

</div>

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:

```auto
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.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/e/3e0816511d967df5bc46d7abf0d4580babf78192.png)

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/a/4ad702557dc6b3195267425b331c46619f8aad2f.png)

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

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 24, 2022, 4:18pm UTC](https://forum.inductiveautomation.com/t/logger-mdc-filtering/61173/2 "2022-06-24T16:18:39Z")

</div>

That’s nice but what’s the question?

---

<div class="post-metadata">

**Author:** ![srunde](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@srunde](https://forum.inductiveautomation.com/u/srunde)\
**Post date:** [June 24, 2022, 4:21pm UTC](https://forum.inductiveautomation.com/t/logger-mdc-filtering/61173/3 "2022-06-24T16:21:55Z")

</div>

Hit post on accident and needed to edit, lol

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 24, 2022, 4:33pm UTC](https://forum.inductiveautomation.com/t/logger-mdc-filtering/61173/4 "2022-06-24T16:33:11Z")

</div>

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](https://github.com/paul-griffith/kindling) if you want inspiration 🙂

---

<div class="post-metadata">

**Author:** ![srunde](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@srunde](https://forum.inductiveautomation.com/u/srunde)\
**Post date:** [June 24, 2022, 4:48pm UTC](https://forum.inductiveautomation.com/t/logger-mdc-filtering/61173/5 "2022-06-24T16:48:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 24, 2022, 5:01pm UTC](https://forum.inductiveautomation.com/t/logger-mdc-filtering/61173/6 "2022-06-24T17:01:44Z")

</div>

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