Skip to content
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

Add filter for log levels #2432

Open
Corbie-42 opened this issue Oct 20, 2023 · 10 comments
Open

Add filter for log levels #2432

Corbie-42 opened this issue Oct 20, 2023 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@Corbie-42
Copy link

The log level detection is already working fine. Now it would be great, if we could filter the output by log level. Every level should be filterable individually.

@Corbie-42 Corbie-42 added the enhancement New feature or request label Oct 20, 2023
@amir20
Copy link
Owner

amir20 commented Oct 20, 2023

Yea, that's a good idea. But there is an issue why I didn't implement this. Right now, I guess the level.

func guessLogLevel(logEvent *LogEvent) string {
switch value := logEvent.Message.(type) {
case string:
levels := []string{"error", "warn", "warning", "info", "debug", "trace", "fatal"}
stripped := ANSI_COLOR_REGEX.ReplaceAllString(value, "") // remove ansi color codes
for _, level := range levels {
if match, _ := regexp.MatchString("(?i)^"+level+"[^a-z]", stripped); match {
return level
}
if strings.Contains(value, "["+strings.ToUpper(level)+"]") {
return level
}
if strings.Contains(value, " "+strings.ToUpper(level)+" ") {
return level
}
}
if matches := KEY_VALUE_REGEX.FindStringSubmatch(value); matches != nil {
return matches[1]
}

I use a combination of regex and filters to check for level. It could totally be wrong. I haven't implemented this because I don't think I am always right. So what should happen to the filtering when it can't find the level?

Example would be say there are 4 lines, WARN, WARN, INFO, NO_LEVEL. If I filter by WARN, should it not show NO_LEVEL too?

@EDIflyer
Copy link
Contributor

Perhaps rather than treating as levels (as proper logging would, where you'd see that level and anything higher but nothing lower) you could instead treat them more like custom filters in Excel where the user could pick any combination of them that they want by ticking/unticking them? Hope that makes some sense!

@Corbie-42
Copy link
Author

Maybe you can treat NO_LEVEL just like the level detected above. This often happens, if a log entry consists of multiple lines, like a stack trace.

You could also make it a option to treat such entries differently and show/hide them on demand.

@EDIflyer that's what I meant 😊

@amir20
Copy link
Owner

amir20 commented Oct 23, 2023

I think it would be weird if someone is filtering by INFO and then WARN doesn't show up. What do other tools do? Does anybody have examples?

@Corbie-42
Copy link
Author

You can have a look at the Chrome developer console. There the log levels can be selected individually.

@EDIflyer
Copy link
Contributor

Ah yes, good idea of an example!
image

@amir20
Copy link
Owner

amir20 commented Oct 27, 2023

This is the javascript console right? I think with JS, you can only have console.log, console.error and console.warnings so that makes sense.

But perhaps this is good enough and one option could be undefined levels.

I'll keep thinking about this. Gotta finish the mult-user authentication first. :)

@EDIflyer
Copy link
Contributor

Yep just the standard console in Chrome - It covers non JS things too (CSS, etc.) that might be why it has those other levels...
image

@Corbie-42
Copy link
Author

Corbie-42 commented Oct 29, 2023

There is also console.debug in JavaScript, that's what they mean by "verbose" . In some languages "verbose" is the same as "trace", which are both one level below "debug" in that case. So there is no common usage.
There are also higher levels like "fatal" in some languages.

@madrussa
Copy link

Most log tooling I've used will track what log levels it has detected and allow you to select from those that it has seen. The UI shows a toggle list of levels its seen so that the user is able to select those they deem important. You can then select a series of levels or a single level if you know what you're filtering for.

I don't feel as though Dozzle should decided what level is more important than another... considering that some systems use "critical", "emergency" or "serious" as log levels; but who knows what order they should appear! And then you can have a single container running multiple applications, each with their own log levels, this becomes even more confusing.

So getting back to KISS methodology, detect any level, allow user to choose those they want.

In my opinion the only aspect of log levels that Dozzle may be opinionated about is ordering and colouring that appear in the list it has detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants