MM-43077 Allow inline JSON in config.json for advanced logging config (#23324)

* add AdvancedLoggingJSON to LogSettings and deprecate AdvancedLoggingConfig
* allow embedded JSON in config for advanced logging.
Этот коммит содержится в:
Doug Lauder
2023-05-15 10:37:48 -04:00
коммит произвёл GitHub
родитель 156d1429de
Коммит e4075dae18
11 изменённых файлов: 324 добавлений и 74 удалений

Просмотреть файл

@@ -6,6 +6,7 @@ package utils
import (
"bytes"
"encoding/json"
"strings"
"github.com/pkg/errors"
)
@@ -54,3 +55,32 @@ func NewHumanizedJSONError(err error, data []byte, offset int64) *HumanizedJSONE
Err: errors.Wrapf(err, "parsing error at line %d, character %d", line, character),
}
}
func IsEmptyJSON(j json.RawMessage) bool {
if len(j) == 0 || bytes.Equal(j, []byte("{}")) || bytes.Equal(j, []byte("\"\"")) || bytes.Equal(j, []byte("[]")) {
return true
}
return false
}
func StringPtrToJSON(ptr *string) json.RawMessage {
if ptr == nil || len(*ptr) == 0 {
return []byte("{}")
}
s := *ptr
if strings.HasPrefix(s, "{") && strings.HasSuffix(s, "}") {
return []byte(s)
}
if strings.HasPrefix(s, "[") && strings.HasSuffix(s, "]") {
return []byte(s)
}
if strings.HasPrefix(s, "\"") && strings.HasSuffix(s, "\"") {
return []byte(s)
}
// This must be a bare string which will need quotes to make a valid JSON document.
return []byte("\"" + s + "\"")
}