diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParameters.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParameters.java index f5b6f02c4..a8705da2c 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParameters.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParameters.java @@ -81,12 +81,15 @@ public enum LogLevel { } public enum SpecificLog { + NETWORK("network"), MODELER("modeler"), PARAMETERS("param"), VARIABLES("variables"), EQUATIONS("equations"); + private static final String DEFAULT_FILE_EXTENSION = ExportMode.TXT.getFileExtension(); + private final String fileName; SpecificLog(String fileName) { @@ -94,7 +97,7 @@ public enum SpecificLog { } public String getFileName() { - return fileName; + return fileName + DEFAULT_FILE_EXTENSION; } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java index 69720ad2e..a20972ed2 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java @@ -194,7 +194,7 @@ public DynamicSimulationResult after(Path workingDir, ExecutionReport report) th DynaWaltzParameters parameters = context.getDynaWaltzParameters(); DumpFileParameters dumpFileParameters = parameters.getDumpFileParameters(); - setDynawoLog(outputsFolder); + setDynawoLog(outputsFolder, parameters.getSpecificLogs()); // Error file Path errorFile = workingDir.resolve(ERROR_FILENAME); if (Files.exists(errorFile)) { @@ -224,11 +224,21 @@ public DynamicSimulationResult after(Path workingDir, ExecutionReport report) th return new DynamicSimulationResultImpl(status, statusText, curves, timeline); } - private void setDynawoLog(Path outputsFolder) { - Path logFile = outputsFolder.resolve(LOGS_FOLDER).resolve(LOGS_FILENAME); - if (Files.exists(logFile)) { - ReportNode logReportNode = CommonReports.createDynawoLogReportNode(reportNode); - new CsvLogParser().parse(logFile).forEach(e -> CommonReports.reportLogEntry(logReportNode, e)); + private void setDynawoLog(Path outputsFolder, Set specificLogs) throws IOException { + Path logFolder = outputsFolder.resolve(LOGS_FOLDER); + if (Files.exists(logFolder)) { + Path logFile = logFolder.resolve(LOGS_FILENAME); + if (Files.exists(logFile)) { + ReportNode logReportNode = CommonReports.createDynawoLogReportNode(reportNode); + new CsvLogParser().parse(logFile).forEach(e -> CommonReports.reportLogEntry(logReportNode, e)); + } + for (DynaWaltzParameters.SpecificLog specificLog : specificLogs) { + Path specificLogFile = logFolder.resolve(specificLog.getFileName()); + if (Files.exists(specificLogFile)) { + ReportNode logReport = DynawaltzReports.createDynawoSpecificLogReportNode(reportNode, specificLog); + DynawaltzReports.reportSpecificLogEntry(logReport, Files.readString(specificLogFile)); + } + } } else { LOGGER.warn("Dynawo logs file not found"); } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawaltzReports.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawaltzReports.java index f2e65a340..8abd02178 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawaltzReports.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynawaltzReports.java @@ -9,6 +9,7 @@ import com.powsybl.commons.report.ReportNode; import com.powsybl.commons.report.TypedValue; +import org.apache.commons.lang3.StringUtils; /** * @author Laurent Issertial {@literal } @@ -72,4 +73,19 @@ public static void reportEmptyListAutomaton(ReportNode reportNode, String automa .withSeverity(TypedValue.WARN_SEVERITY) .add(); } + + public static ReportNode createDynawoSpecificLogReportNode(ReportNode reportNode, DynaWaltzParameters.SpecificLog logType) { + String logTypeName = StringUtils.capitalize(logType.toString().toLowerCase()); + return reportNode.newReportNode() + .withMessageTemplate("dynawo" + logTypeName + "Log", logTypeName + " log") + .add(); + + } + + public static void reportSpecificLogEntry(ReportNode reportNode, String logEntry) { + reportNode.newReportNode() + .withMessageTemplate("dynawoSpecificLogEntry", "${message}") + .withUntypedValue("message", logEntry) + .add(); + } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java index 717ee0403..e45c3e2e9 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java @@ -128,7 +128,7 @@ private static void writeAppender(XMLStreamWriter writer, DynaWaltzParameters pa private static void writeSpecificAppender(XMLStreamWriter writer, DynaWaltzParameters.SpecificLog log) throws XMLStreamException { writer.writeEmptyElement(DYN_URI, "appender"); writer.writeAttribute("tag", log.toString()); - writer.writeAttribute("file", log.getFileName() + ".log"); + writer.writeAttribute("file", log.getFileName()); writer.writeAttribute("lvlFilter", DynaWaltzParameters.LogLevel.DEBUG.toString()); } } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java index 61070f28b..df03b710f 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java @@ -153,7 +153,6 @@ private void initPlatformConfig(String networkParametersId, SolverType solverTyp moduleConfig.setStringProperty("log.levelFilter", logLevel.toString()); moduleConfig.setStringListProperty("log.specificLogs", specificLogs.stream().map(SpecificLog::toString).toList()); - Files.createDirectories(fileSystem.getPath(USER_HOME)); copyFile("/parametersSet/models.par", parametersFile); copyFile("/parametersSet/network.par", networkParametersFile);