Repository: amir20/dozzle (language: go)

Issue:
Malformed output when log contains an equals sign
**Describe the bug**
Whenever a container's console output contains `a = b`, Dozzle seems to misinterpret the line as a series of variables and ends up malforming the entire line.

**To Reproduce**

1. Run some variation of the following code, in any container. This example is in Python but the language doesn't matter. The only important part is the second print statement.
```py
import time

print("hello world")
print("Failed to run somecommand with somevariable = 1")

while True:
    time.sleep(1)
```

2. Open the Dozzle logs for the container
3. Observe that the output looks like the screenshot below

**Expected behavior**
I expected the message to be printed as-is: `Failed to run somecommand with somevariable = 1`

**Screenshots**

![image](https://github.com/amir20/dozzle/assets/12799103/51c326de-b575-4bd6-9bd5-ffd17a7eade5)

**Desktop (please complete the following information):**

- OS: Windows 10
- Docker version: 25.0.3
- Browser & version: Chrome 122.0.6261.129
- Version: v6.3.1



Discussion / hints:
Hmm that does seem like a tricky bug.  Dozzle supports https://grafana.com/docs/loki/latest/send-data/promtail/stages/logfmt/ but the parser seems pretty relaxed. 

I am not sure how to fix it. 
Looks like I do `strings.Contains(message, "=")`. Maybe I should change it to some regex without spaces around `=`. 
Would it be reasonable to check if the message matches regex something like `^[^ ]+=[^ ].*`? This would expect the message to start with a key that contains no spaces (which I think is a reasonable restriction), which I would imagine is a typical use case for key-value logs. That way it would match:

```
time=2012-11-01T22:08:41+00:00
```

But none of these:

```
This is a log message: "key=value"
Testing a variable = 2
```
Thanks for the quick reply! If you can't find a good way to improve the regex, another option could be adding a new environment variable that disables all parsing and prints all messages as-is. Just tossing out an idea. 🙂
> adding a new environment variable that disables all parsing and prints all messages as-is. Just tossing out an idea

Not worth it. Makes testing and configuration harder. 

Let me play around with regex. 

Fix patch:
diff --git a/internal/docker/event_generator.go b/internal/docker/event_generator.go
index c555e42bed86..aeb870086cc3 100644
--- a/internal/docker/event_generator.go
+++ b/internal/docker/event_generator.go
@@ -156,7 +156,8 @@ func readEvent(reader *bufio.Reader, tty bool) (string, StdType, error) {
 	}
 }
 
-var validLogFmtKey = regexp.MustCompile(`^[a-zA-Z0-9_]+$`)
+var validLogFmtMessage = regexp.MustCompile(`([a-zA-Z0-9_.-]+)=(?:(?:"(.*)")|(?:(?:([^\s]+)[\s])))`)
+var validLogFmtKey = regexp.MustCompile(`^[a-zA-Z0-9_.-]+$`)
 
 func createEvent(message string, streamType StdType) *LogEvent {
 	h := fnv.New32a()
@@ -180,7 +181,7 @@ func createEvent(message string, streamType StdType) *LogEvent {
 				} else {
 					logEvent.Message = data
 				}
-			} else if strings.Contains(message, "=") {
+			} else if validLogFmtMessage.MatchString(message) {
 				buffer := bufPool.Get().(*bytes.Buffer)
 				buffer.Reset()
 				defer bufPool.Put(buffer)


Test patch: