diff --git a/docs/source/cases_specification.rst b/docs/source/cases_specification.rst index b0c2f14..ea5d9f5 100644 --- a/docs/source/cases_specification.rst +++ b/docs/source/cases_specification.rst @@ -54,6 +54,9 @@ The following header section elements (denoted as `header-lines` above) are defi * If no `CosimExecution` object is provided, but a `OspSystemStructure.xml` file is found in the same folder as the `.cases` file, this file is assumed as the system definition file and a `CosimExecution` object is instantiated internally. * A system structure file can be explicitly specified and will be used to generate a `CosimExecution` object. +*logLevel* (optional) + Log level of the simulator. Per default the level is set to FATAL, + but it can be set to TRACE, DEBUG, INFO, WARNING, ERROR or FATAL (e.g. for debugging purposes) *timeUnit* (optional) The unit of time the independent variable relates to, e.g. "second" *variables* (mandatory) diff --git a/sim_explorer/case.py b/sim_explorer/case.py index e3b8d4a..f3ec7b1 100644 --- a/sim_explorer/case.py +++ b/sim_explorer/case.py @@ -8,6 +8,7 @@ from pathlib import Path from typing import Any, Callable +from libcosimpy.CosimLogging import log_output_level, CosimLogLevel import matplotlib.pyplot as plt import numpy as np @@ -530,7 +531,7 @@ def __init__(self, spec: str | Path, simulator: SimulatorInterface | None = None self.file = Path(spec) # everything relative to the folder of this file! assert self.file.exists(), f"Cases spec file {spec} not found" self.js = Json5(spec) - # self.spec = self.js.js_py + log_level = CosimLogLevel[self.js.jspath("$.header.logLevel") or "FATAL"] if simulator is None: modelfile = self.js.jspath("$.header.modelFile", str) or "OspSystemStructure.xml" path = self.file.parent / modelfile @@ -540,11 +541,13 @@ def __init__(self, spec: str | Path, simulator: SimulatorInterface | None = None system=path, name=self.js.jspath("$.header.name", str) or "", description=self.js.jspath("$.header.description", str) or "", + log_level = log_level, ) except Exception as err: raise AssertionError(f"'modelFile' needed from spec: {err}") from err else: self.simulator = simulator # SimulatorInterface( simulator = simulator) + log_output_level( log_level) self.timefac = self._get_time_unit() * 1e9 # internally OSP uses pico-seconds as integer! # read the 'variables' section and generate dict { alias : { (instances), (variables)}}: diff --git a/sim_explorer/simulator_interface.py b/sim_explorer/simulator_interface.py index f3cc0e8..f789ffc 100644 --- a/sim_explorer/simulator_interface.py +++ b/sim_explorer/simulator_interface.py @@ -7,6 +7,7 @@ from zipfile import BadZipFile, ZipFile, is_zipfile from libcosimpy.CosimEnums import CosimVariableCausality, CosimVariableType, CosimVariableVariability # type: ignore +from libcosimpy.CosimLogging import log_output_level, CosimLogLevel from libcosimpy.CosimExecution import CosimExecution # type: ignore from libcosimpy.CosimManipulator import CosimManipulator # type: ignore from libcosimpy.CosimObserver import CosimObserver # type: ignore @@ -65,6 +66,8 @@ class SimulatorInterface: description (str)="": Optional possibility to provide a system description simulator (CosimExecution)=None: Optional possibility to insert an existing simulator object. Otherwise this is generated through CosimExecution.from_osp_config_file(). + log_level (CosimLogLevel): Per default the level is set to FATAL, + but it can be set to TRACE, DEBUG, INFO, WARNING, ERROR or FATAL (e.g. for debugging purposes) """ simulator: CosimExecution @@ -75,6 +78,7 @@ def __init__( name: str | None = None, description: str = "", simulator: CosimExecution | None = None, + log_level: CosimLogLevel = CosimLogLevel.FATAL, ): self.name = name # overwrite if the system includes that self.description = description # overwrite if the system includes that @@ -87,6 +91,7 @@ def __init__( self.simulator = self._simulator_from_config(self.sysconfig) else: self.simulator = simulator + log_output_level( log_level) self.components = self.get_components() # dict of {component name : modelId} # Instantiate a suitable manipulator for changing variables. self.manipulator = CosimManipulator.create_override()