Pass around non-static logger instances and programmatic access to messages in-memory

This commit is contained in:
Thomas Krijnen
2026-06-10 18:30:54 +02:00
parent a751fb956d
commit a7738eeb64
132 changed files with 1029 additions and 884 deletions
@@ -95,6 +95,7 @@ from .entity_instance import entity_instance, register_schema_attributes
from .file import file, rocksdb_lazy_instance
from .file import file as _file
from .sql import sqlite, sqlite_entity
from .ifcopenshell_wrapper import get_log, logger
# explicitly specify available imported symbols
# (it's a requirement for a typed library)
@@ -389,4 +390,3 @@ def convert_path_to_rocksdb(ifcspf_path: Union[Path, str], rocksdb_path: Union[P
version_core = ifcopenshell_wrapper.version()
__version__ = version = "0.0.0"
get_log = ifcopenshell_wrapper.get_log
@@ -461,6 +461,7 @@ def create_shape(
inst: entity_instance,
repr: Optional[entity_instance] = None,
geometry_library: GEOMETRY_LIBRARY = "opencascade",
logger: Optional[ifcopenshell.logger] = None,
) -> Union[ShapeType, ShapeElementType, ifcopenshell_wrapper.Transformation, utils.shape_tuple, TopoDS.TopoDS_Shape]:
"""
Returns a geometric interpretation of the IFC entity instance
@@ -507,7 +508,7 @@ def create_shape(
return wrap_shape_creation(
settings,
ifcopenshell_wrapper.create_shape(
settings, inst.wrapped_data, repr.wrapped_data if repr is not None else None, geometry_library
settings, inst.wrapped_data, repr.wrapped_data if repr is not None else None, geometry_library, *(filter(None, (logger,)))
),
)
@@ -2,7 +2,7 @@ ISO-10303-21;
HEADER;
FILE_DESCRIPTION(('ViewDefinition [CoordinationView]','RevitIdentifiers [ContentGUID: a0df3484-2dab-42c5-b806-8c10d313bee0, VersionGUID: 658c1394-f3a4-43d1-9b3c-eee44a0cd67a, NumberOfSaves: 2]','CoordinateReference [CoordinateBase: Shared Coordinates]'),'2;1');
FILE_NAME('Column_4x3.ifc','2025-03-12T13:53:30+00:00',(''),(''),'ODA SDAI 24.12','Autodesk Revit 25.4.0.32 (ENG) - IFC 25.4.0.32','');
FILE_SCHEMA(('IFC4X3_ADD2'));
FILE_SCHEMA(('IFC2X3'));
ENDSEC;
DATA;
#1=IFCORGANIZATION($,'Autodesk Revit 2025 (ENG)',$,$,$);
@@ -216,6 +216,26 @@ def test_iterator():
assert iterator.initialize()
def test_logging():
logger = ifcopenshell.logger()
logger.OutputFormat(logger.FMT_INMEMORY)
settings = ifcopenshell.geom.settings()
f = ifcopenshell.open(fn)
col = f.by_type("IfcColumn")[0]
_ = ifcopenshell.geom.create_shape(settings, col, logger=logger)
num_log_items = len(list(logger))
col.Representation.Representations[0].Items[0].MappingSource.MappedRepresentation.Items[0].Depth *= -1.0
with pytest.raises(RuntimeError):
_ = ifcopenshell.geom.create_shape(settings, col, logger=logger)
new_items = list(logger)[num_log_items:]
assert ("GEO089", "Non-positive extrusion height encountered for:") in [
(msg.code, msg.message) for msg in new_items
]
if __name__ == "__main__":
import pytest