translate from user-friendly syntax
@@ -21,7 +21,9 @@ import com.yahoo.vespa.model.admin.monitoring.builder.xml.MetricsBuilder;
import org.w3c.dom.Element;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
/**
@@ -110,11 +112,40 @@ public abstract class DomAdminBuilderBase extends VespaDomBuilder.DomConfigProdu
}
}
+ private static Map<String, String> defaultLogLevels() {
+ var m = new HashMap<String,String>();
+ m.put("all", "off");
+ m.put("error", "on");
+ m.put("warning", "on");
+ m.put("info", "on");
+ m.put("config", "on");
+ m.put("event", "on");
+ m.put("debug", "off");
+ m.put("spam", "off");
+ return m;
+ }
+
private void addLoggingSpec(ModelElement loggingSpec, Admin admin) {
+ var currentLevels = defaultLogLevels();
if (loggingSpec == null) return;
String componentSpec = loggingSpec.requiredStringAttribute("name");
- String levelsModSpec = loggingSpec.requiredStringAttribute("levels");
- admin.addLogctlCommand(componentSpec, levelsModSpec);
+ String levels = loggingSpec.requiredStringAttribute("levels");
+ var levelsModSpec = new StringBuilder();
+ levelsModSpec.append("all=off");
+ for (String s : levels.split("[ ,]")) {
+ if (s.isEmpty()) continue;
+ String offOn = "on";
+ if (s.startsWith("-")) {
+ offOn = "off";
+ s = s.substring(1);
+ }
+ if (currentLevels.containsKey(s)) {
+ levelsModSpec.append(",").append(s).append("=").append(offOn);
+ } else {
+ throw new IllegalArgumentException("invalid level '" + s + "' in logging levels: " + levels);
+ }
+ }
+ admin.addLogctlCommand(componentSpec, levelsModSpec.toString());
}
void addLoggingSpecs(ModelElement loggingElement, Admin admin) {
