# Extracting and Setting LogLevel based off a Single Character

**URL:** <https://community.dynatrace.com/t/extracting-and-setting-loglevel-based-off-a-single-character/46952>\
**Category:** Dynatrace Tips\
**Tags:** log-processing, tips-and-tricks, dpl, logs\
**Created:** [August 1, 2024, 2:30pm UTC](https://community.dynatrace.com/t/extracting-and-setting-loglevel-based-off-a-single-character/46952 "2024-08-01T14:30:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsnurka](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/bsnurka/32/26730_2.png) [@bsnurka](https://community.dynatrace.com/u/bsnurka)\
**Post date:** [August 1, 2024, 2:30pm UTC](https://community.dynatrace.com/t/extracting-and-setting-loglevel-based-off-a-single-character/46952/1 "2024-08-01T14:30:12Z")

</div>

**Use Case:** Customer has an application log which contains a single character, “E” for example, which denotes what the LogLevel for said Log entry is.

```markup
[2024-05-21T12:06:40.084-0400] 012345 id= com.github.example E HOST: An unexpected error occured whilst opening the log. Log example Log example Log example Log example Log example Log example Log example

```

Dynatrace will not automatically extract the single character and set the LogLevel as it is in a non-standard format, but we can perform this work using a Log Processing Rule -&nbsp;[Log processing — Dynatrace Docs](https://docs.dynatrace.com/docs/shortlink/lma-log-processing)

**Log Processor Setup:** &nbsp;Open up the Dynatrace Tenant \> Settings \> Log Monitoring \> Log Processing.

Click Add rule - Give the rule a friendly but descriptive name.

In the Matcher field, enter the DQL filters which will focus the log processing rule down to the specific application we are focused on. For example:

```markup
matchesValue(k8s.namespace.name, "App-namespace") AND matchesValue(k8s.deployment.name, "MyApplication")

```

For the processor definition, enter the following:

```markup
USING(INOUT loglevel, IN content)
|PARSE(content,"LD SPACE LD SPACE LD BLANK LD BLANK ['A-Z']{1}:logstatus SPACE")
| FIELDS_ADD(loglevel:
  IF(logstatus == "W", "WARN",
    IF(logstatus == "E", "ERROR", 
      IF(logstatus == "I", "INFO", 
        IF(logstatus == "C", "CRITICAL",
          IF(logstatus == "D", "DEBUG",
            IF(logstatus == "S", "SEVERE", 
              IF(logstatus == "T", "TRACE", 
                IF(logstatus == "N", "NOTICE",
                  IF(logstatus == "A", "ALERT",
                    IF(logstatus == "F", "FATAL",
                      "NONE"
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  )
)

```

This Log Processing Rule will extract the single character, “E” in the above example, and save that to a logstatus field. Then based off the logstatus field, we update the loglevel to the corresponding value.

Before transformation vs After Transformation

 ![bsnurka_0-1722522958844.png](https://global.discourse-cdn.com/dynatrace/original/3X/c/a/caf48a73f216a18a2669328277790a8cf1b62b20.png)

Save the Rule and Turn it on to start updating the loglevel for any newly ingested logs matching the defined matcher!
