feat: enable filtering console output by severity level
This commit is contained in:
@ -3,6 +3,7 @@ package console_exporter
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
|
||||
"git.ma-al.com/maal-libraries/observer/pkg/attr"
|
||||
@ -22,7 +23,8 @@ type TraceFormatter interface {
|
||||
// Most of options are passed to the formatter.
|
||||
type ProcessorOptions struct {
|
||||
// Try to parse filters from an environment variable with a name provided by this field.
|
||||
// Result will only by applied to unset options. NOT IMPLEMENTED!
|
||||
// Result will only by applied to unset options. Currently it will only attempt to parse
|
||||
// severity level from the variable and use that as a filter.
|
||||
FilterFromEnvVar *string
|
||||
// Filter the output based on the [level.SeverityLevel].
|
||||
FilterOnLevel level.SeverityLevel
|
||||
@ -79,9 +81,16 @@ func NewProcessor(opts ProcessorOptions) trace.SpanProcessor {
|
||||
fmt := NewPrettyMultilineFormatter()
|
||||
formatter = fmt
|
||||
}
|
||||
if opts.FilterFromEnvVar != nil {
|
||||
envFilter := os.Getenv(*opts.FilterFromEnvVar)
|
||||
parsedLvl := level.FromString(envFilter)
|
||||
if parsedLvl != level.SeverityLevel(0) {
|
||||
lvl = parsedLvl
|
||||
}
|
||||
}
|
||||
if opts.FilterOnLevel != level.SeverityLevel(0) {
|
||||
lvl = opts.FilterOnLevel
|
||||
} else {
|
||||
} else if lvl == level.SeverityLevel(0) {
|
||||
lvl = level.TRACE + 1
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user