Validate log level values

This commit is contained in:
Tim Liou 2024-01-18 21:40:23 +08:00
parent a5d15c10e8
commit 61826cf21a

View File

@ -32,6 +32,30 @@ def is_json(log_json):
return True
def validate_log_level(config, logs):
root = ET.fromstring(config)
key = root.findtext(".//names/level") or "level"
valid_level_values = {
"Fatal",
"Critical",
"Error",
"Warning",
"Notice",
"Information",
"Debug",
"Trace",
"Test",
}
length = min(10, len(logs))
for i in range(0, length):
json_log = json.loads(logs[i])
if json_log[key] not in valid_level_values:
return False
return True
def validate_log_config_relation(config, logs, config_type):
root = ET.fromstring(config)
keys_in_config = set()
@ -80,7 +104,7 @@ def valiade_everything(config, node, config_type):
logs = node.grep_in_log("").split("\n")
return validate_logs(logs) and validate_log_config_relation(
config, logs, config_type
)
) and validate_log_level(config, logs)
def test_structured_logging_json_format(start_cluster):