Skip to content

Commit

Permalink
Add logLevelFilter parameter
Browse files Browse the repository at this point in the history
Signed-off-by: lisrte <[email protected]>
  • Loading branch information
Lisrte committed May 27, 2024
1 parent 81b84f6 commit 209c335
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class DynaWaltzParameters extends AbstractExtension<DynamicSimulationPara
public static final boolean DEFAULT_USE_MODEL_SIMPLIFIERS = false;
public static final double DEFAULT_PRECISION = 1e-6;
public static final ExportMode DEFAULT_TIMELINE_EXPORT_MODE = ExportMode.TXT;
public static final LogLevel DEFAULT_LOG_LEVEL_FILTER = LogLevel.INFO;

/**
* Information about the solver to use in the simulation
Expand Down Expand Up @@ -72,6 +73,13 @@ public String getFileExtension() {
}
}

public enum LogLevel {
DEBUG,
INFO,
WARN,
ERROR
}

private Map<String, ParametersSet> modelsParameters = new LinkedHashMap<>();
private ParametersSet networkParameters;
private ParametersSet solverParameters;
Expand All @@ -82,6 +90,7 @@ public String getFileExtension() {
private DumpFileParameters dumpFileParameters = DumpFileParameters.DEFAULT_DUMP_FILE_PARAMETERS;
private double precision = DEFAULT_PRECISION;
private ExportMode timelineExportMode = DEFAULT_TIMELINE_EXPORT_MODE;
private LogLevel logLevelFilter = DEFAULT_LOG_LEVEL_FILTER;

/**
* Loads parameters from the default platform configuration.
Expand Down Expand Up @@ -122,6 +131,7 @@ public static DynaWaltzParameters load(PlatformConfig platformConfig, FileSystem
c.getOptionalBooleanProperty("useModelSimplifiers").ifPresent(parameters::setUseModelSimplifiers);
c.getOptionalDoubleProperty("precision").ifPresent(parameters::setPrecision);
c.getOptionalEnumProperty("timeline.exportMode", ExportMode.class).ifPresent(parameters::setTimelineExportMode);
c.getOptionalEnumProperty("log.levelFilter", LogLevel.class).ifPresent(parameters::setLogLevelFilter);
});
return parameters;
}
Expand Down Expand Up @@ -244,4 +254,13 @@ public DynaWaltzParameters setTimelineExportMode(ExportMode timelineExportMode)
this.timelineExportMode = timelineExportMode;
return this;
}

public LogLevel getLogLevelFilter() {
return logLevelFilter;
}

public DynaWaltzParameters setLogLevelFilter(LogLevel logLevelFilter) {
this.logLevelFilter = logLevelFilter;
return this;
}
}
11 changes: 6 additions & 5 deletions dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private static void writeSimulation(XMLStreamWriter writer, DynaWaltzContext con
}

private static void writeOutput(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException {
DynaWaltzParameters parameters = context.getDynaWaltzParameters();
writer.writeStartElement(DYN_URI, "outputs");
writer.writeAttribute("directory", "outputs");

Expand All @@ -98,8 +99,8 @@ private static void writeOutput(XMLStreamWriter writer, DynaWaltzContext context
writer.writeAttribute("exportMode", context.getDynaWaltzParameters().getTimelineExportMode().name());

writer.writeEmptyElement(DYN_URI, "finalState");
writer.writeAttribute("exportIIDMFile", Boolean.toString(context.getDynaWaltzParameters().isWriteFinalState()));
writer.writeAttribute("exportDumpFile", Boolean.toString(context.getDynaWaltzParameters().getDumpFileParameters().exportDumpFile()));
writer.writeAttribute("exportIIDMFile", Boolean.toString(parameters.isWriteFinalState()));
writer.writeAttribute("exportDumpFile", Boolean.toString(parameters.getDumpFileParameters().exportDumpFile()));

if (context.withCurves()) {
writer.writeEmptyElement(DYN_URI, "curves");
Expand All @@ -108,16 +109,16 @@ private static void writeOutput(XMLStreamWriter writer, DynaWaltzContext context
}

writer.writeStartElement(DYN_URI, "logs");
writeAppender(writer);
writeAppender(writer, parameters);
writer.writeEndElement();

writer.writeEndElement();
}

private static void writeAppender(XMLStreamWriter writer) throws XMLStreamException {
private static void writeAppender(XMLStreamWriter writer, DynaWaltzParameters parameters) throws XMLStreamException {
writer.writeEmptyElement(DYN_URI, "appender");
writer.writeAttribute("tag", "");
writer.writeAttribute("file", "dynawaltz.log");
writer.writeAttribute("lvlFilter", "DEBUG");
writer.writeAttribute("lvlFilter", parameters.getLogLevelFilter().toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.powsybl.commons.test.AbstractSerDeTest;
import com.powsybl.dynamicsimulation.DynamicSimulationParameters;
import com.powsybl.dynamicsimulation.json.JsonDynamicSimulationParameters;
import com.powsybl.dynawaltz.DynaWaltzParameters.ExportMode;
import com.powsybl.dynawaltz.DynaWaltzParameters.SolverType;
import com.powsybl.dynawaltz.parameters.Parameter;
import com.powsybl.dynawaltz.parameters.ParameterType;
Expand Down Expand Up @@ -61,7 +60,8 @@ void checkParameters() throws IOException {
boolean useModelSimplifiers = true;
double precision = 1e-8;
ExportMode timelinExportMode = ExportMode.XML;
initPlatformConfig(networkParametersId, solverType, solverParametersId, mergeLoads, useModelSimplifiers, precision, timelinExportMode);
DynaWaltzParameters.LogLevel logLevel = DynaWaltzParameters.LogLevel.WARN;
initPlatformConfig(networkParametersId, solverType, solverParametersId, mergeLoads, useModelSimplifiers, precision, timelinExportMode, logLevel);

DynaWaltzParameters parameters = DynaWaltzParameters.load(platformConfig, fileSystem);

Expand Down Expand Up @@ -94,6 +94,7 @@ void checkParameters() throws IOException {
assertEquals(useModelSimplifiers, parameters.isUseModelSimplifiers());
assertEquals(precision, parameters.getPrecision());
assertEquals(timelinExportMode, parameters.getTimelineExportMode());
assertEquals(logLevel, parameters.getLogLevelFilter());
}

@Test
Expand All @@ -116,7 +117,7 @@ void roundTripParametersSerializing() throws IOException {
SolverType solverType = SolverType.IDA;
String solverParametersId = "solverParametersId";
boolean mergeLoads = false;
initPlatformConfig(networkParametersId, solverType, solverParametersId, mergeLoads, false, 1e-7, ExportMode.TXT);
initPlatformConfig(networkParametersId, solverType, solverParametersId, mergeLoads, false, 1e-7, ExportMode.TXT, DynaWaltzParameters.LogLevel.INFO);

DynamicSimulationParameters dynamicSimulationParameters = new DynamicSimulationParameters()
.setStartTime(0)
Expand All @@ -127,7 +128,7 @@ void roundTripParametersSerializing() throws IOException {
JsonDynamicSimulationParameters::read, "/DynaWaltzParameters.json");
}

private void initPlatformConfig(String networkParametersId, SolverType solverType, String solverParametersId, boolean mergeLoads, boolean useModelSimplifiers, double precision, ExportMode timelineExportMode) throws IOException {
private void initPlatformConfig(String networkParametersId, SolverType solverType, String solverParametersId, boolean mergeLoads, boolean useModelSimplifiers, double precision, ExportMode timelineExportMode, DynaWaltzParameters.LogLevel logLevel) throws IOException {
String parametersFile = USER_HOME + "parametersFile";
String networkParametersFile = USER_HOME + "networkParametersFile";
String solverParametersFile = USER_HOME + "solverParametersFile";
Expand All @@ -143,6 +144,7 @@ private void initPlatformConfig(String networkParametersId, SolverType solverTyp
moduleConfig.setStringProperty("useModelSimplifiers", String.valueOf(useModelSimplifiers));
moduleConfig.setStringProperty("precision", Double.toString(precision));
moduleConfig.setStringProperty("timeline.exportMode", String.valueOf(timelineExportMode));
moduleConfig.setStringProperty("log.levelFilter", logLevel.toString());

Files.createDirectories(fileSystem.getPath(USER_HOME));
copyFile("/parametersSet/models.par", parametersFile);
Expand Down
1 change: 1 addition & 0 deletions dynawaltz/src/test/resources/DynaWaltzParameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
},
"precision" : 1.0E-7,
"timelineExportMode" : "TXT",
"logLevelFilter" : "INFO",
"modelsParameters" : [ {
"id" : "test",
"parameters" : {
Expand Down
2 changes: 1 addition & 1 deletion dynawaltz/src/test/resources/jobs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<dyn:finalState exportIIDMFile="true" exportDumpFile="false"/>
<dyn:curves inputFile="powsybl_dynawaltz.crv" exportMode="CSV"/>
<dyn:logs>
<dyn:appender tag="" file="dynawaltz.log" lvlFilter="DEBUG"/>
<dyn:appender tag="" file="dynawaltz.log" lvlFilter="INFO"/>
</dyn:logs>
</dyn:outputs>
</dyn:job>
Expand Down
2 changes: 1 addition & 1 deletion dynawaltz/src/test/resources/jobsWithDump.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dyn:finalState exportIIDMFile="true" exportDumpFile="true"/>
<dyn:curves inputFile="powsybl_dynawaltz.crv" exportMode="CSV"/>
<dyn:logs>
<dyn:appender tag="" file="dynawaltz.log" lvlFilter="DEBUG"/>
<dyn:appender tag="" file="dynawaltz.log" lvlFilter="INFO"/>
</dyn:logs>
</dyn:outputs>
</dyn:job>
Expand Down

0 comments on commit 209c335

Please sign in to comment.