Skip to content

Commit 73b213d

Browse files
fix: Fix VTKHandler managment in geos-pv (#234)
1 parent b46488b commit 73b213d

17 files changed

Lines changed: 72 additions & 51 deletions

geos-processing/src/geos/processing/generic_processing_tools/SplitMesh.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ def __init__( self, inputMesh: vtkUnstructuredGrid, speHandler: bool = False ) -
8383
self.logger = logging.getLogger( loggerTitle )
8484
self.logger.setLevel( logging.INFO )
8585
self.logger.propagate = False
86+
handlers: list[ logging.Handler ] = self.logger.handlers
87+
# Get the handler to specify if the logger already exist and has it
88+
for handler in handlers:
89+
# The CountWarningHandler can't be the handler to specify
90+
if type( handler ) is not type( CountWarningHandler() ):
91+
self.handler = handler
92+
break
8693

8794
counter: CountWarningHandler = CountWarningHandler()
8895
self.counter: CountWarningHandler

geos-processing/src/geos/processing/pre_processing/MeshQualityEnhanced.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def __init__(
132132
self._allCellTypesExtended: tuple[ int, ...] = getAllCellTypesExtended()
133133
self._allCellTypes: tuple[ int, ...] = getAllCellTypes()
134134
self.speHandler: bool = speHandler
135+
self.handler: logging.Handler
135136

136137
# Logger
137138
self.logger: Logger
@@ -141,6 +142,13 @@ def __init__(
141142
self.logger = logging.getLogger( loggerTitle )
142143
self.logger.setLevel( logging.INFO )
143144
self.logger.propagate = False
145+
handlers: list[ logging.Handler ] = self.logger.handlers
146+
# Get the handler to specify if the logger already exist and has it
147+
for handler in handlers:
148+
# The CountWarningHandler can't be the handler to specify
149+
if type( handler ) is not type( CountWarningHandler() ):
150+
self.handler = handler
151+
break
144152

145153
counter: CountWarningHandler = CountWarningHandler()
146154
self.counter: CountWarningHandler

geos-pv/src/geos/pv/plugins/generic_processing/PVAttributeMapping.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
5555
"""
5656

57+
HANDLER: logging.Handler = VTKHandler()
58+
5759

5860
@smproxy.filter( name="PVAttributeMapping", label="Attribute Mapping" )
5961
@smhint.xml( f'<ShowInMenu category="{ FilterCategory.GENERIC_PROCESSING.value }"/>' )
@@ -76,7 +78,6 @@ def __init__( self: Self ) -> None:
7678
self.piece: Piece = Piece.CELLS
7779
self.clearAttributeNames = True
7880
self.attributeNames: list[ str ] = []
79-
self.handler: logging.Handler = VTKHandler()
8081

8182
@smproperty.intvector(
8283
name="AttributePiece",
@@ -190,8 +191,8 @@ def RequestData(
190191
attributeMappingFilter: AttributeMapping = AttributeMapping( meshFrom, outData, set( self.attributeNames ),
191192
self.piece, True )
192193

193-
if not isHandlerInLogger( self.handler, attributeMappingFilter.logger ):
194-
attributeMappingFilter.setLoggerHandler( self.handler )
194+
if not isHandlerInLogger( HANDLER, attributeMappingFilter.logger ):
195+
attributeMappingFilter.setLoggerHandler( HANDLER )
195196

196197
try:
197198
attributeMappingFilter.applyFilter()

geos-pv/src/geos/pv/plugins/generic_processing/PVClipToMainFrame.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
3737
"""
3838

39+
HANDLER: logging.Handler = VTKHandler()
40+
3941

4042
@SISOFilter( category=FilterCategory.GENERIC_PROCESSING,
4143
decoratedLabel="Clip to the main frame",
@@ -45,10 +47,9 @@ class PVClipToMainFrame( VTKPythonAlgorithmBase ):
4547
def __init__( self ) -> None:
4648
"""Init motherclass, filter and logger."""
4749
self._realFilter = ClipToMainFrame( speHandler=True )
48-
self.handler: logging.Handler = VTKHandler()
4950

50-
if not isHandlerInLogger( self.handler, self._realFilter.logger ):
51-
self._realFilter.SetLoggerHandler( self.handler )
51+
if not isHandlerInLogger( HANDLER, self._realFilter.logger ):
52+
self._realFilter.SetLoggerHandler( HANDLER )
5253

5354
def ApplyFilter( self, inputMesh: vtkMultiBlockDataSet, outputMesh: vtkMultiBlockDataSet ) -> None:
5455
"""Is applying clipToMainFrame filter.

geos-pv/src/geos/pv/plugins/generic_processing/PVCreateConstantAttributePerRegion.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
5151
"""
5252

53+
HANDLER: logging.Handler = VTKHandler()
54+
5355

5456
@SISOFilter( category=FilterCategory.GENERIC_PROCESSING,
5557
decoratedLabel="Create Constant Attribute Per Region",
@@ -72,7 +74,6 @@ def __init__( self: Self ) -> None:
7274

7375
# Use the handler of paraview for the log.
7476
self.speHandler: bool = True
75-
self.handler: logging.Handler = VTKHandler()
7677

7778
# Settings of the attribute with the region indexes:
7879
@smproperty.stringvector(
@@ -292,8 +293,8 @@ def ApplyFilter( self, inputMesh: vtkDataSet, outputMesh: vtkDataSet ) -> None:
292293
self.speHandler,
293294
)
294295

295-
if not isHandlerInLogger( self.handler, createConstantAttributePerRegionFilter.logger ):
296-
createConstantAttributePerRegionFilter.setLoggerHandler( self.handler )
296+
if not isHandlerInLogger( HANDLER, createConstantAttributePerRegionFilter.logger ):
297+
createConstantAttributePerRegionFilter.setLoggerHandler( HANDLER )
297298

298299
try:
299300
createConstantAttributePerRegionFilter.applyFilter()

geos-pv/src/geos/pv/plugins/generic_processing/PVFillPartialArrays.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
4242
"""
4343

44+
HANDLER: logging.Handler = VTKHandler()
45+
4446

4547
@SISOFilter( category=FilterCategory.GENERIC_PROCESSING,
4648
decoratedLabel="Fill Partial Arrays",
@@ -51,7 +53,6 @@ def __init__( self: Self, ) -> None:
5153
"""Fill a partial attribute with constant value per component."""
5254
self.clearDictAttributesValues: bool = True
5355
self.dictAttributesValues: dict[ str, Union[ list[ Any ], None ] ] = {}
54-
self.handler: logging.Handler = VTKHandler()
5556

5657
@smproperty.xml( """
5758
<StringVectorProperty
@@ -108,8 +109,8 @@ def ApplyFilter( self, inputMesh: vtkMultiBlockDataSet, outputMesh: vtkMultiBloc
108109
speHandler=True,
109110
)
110111

111-
if not isHandlerInLogger( self.handler, fillPartialArraysFilter.logger ):
112-
fillPartialArraysFilter.setLoggerHandler( self.handler )
112+
if not isHandlerInLogger( HANDLER, fillPartialArraysFilter.logger ):
113+
fillPartialArraysFilter.setLoggerHandler( HANDLER )
113114

114115
try:
115116
fillPartialArraysFilter.applyFilter()

geos-pv/src/geos/pv/plugins/generic_processing/PVMergeBlocksEnhanced.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
- nan for float data.
5454
"""
5555

56+
HANDLER: logging.Handler = VTKHandler()
57+
5658

5759
@smproxy.filter( name="PVMergeBlocksEnhanced", label="Merge Blocks Keeping Partial Attributes" )
5860
@smhint.xml( f'<ShowInMenu category="{ FilterCategory.GENERIC_PROCESSING.value }"/>' )
@@ -68,7 +70,6 @@ def __init__( self: Self ) -> None:
6870
inputType="vtkMultiBlockDataSet",
6971
outputType="vtkUnstructuredGrid",
7072
)
71-
self.handler: logging.Handler = VTKHandler()
7273

7374
def RequestDataObject(
7475
self: Self,
@@ -118,8 +119,8 @@ def RequestData(
118119

119120
mergeBlockEnhancedFilter: MergeBlockEnhanced = MergeBlockEnhanced( inputMesh, True )
120121

121-
if not isHandlerInLogger( self.handler, mergeBlockEnhancedFilter.logger ):
122-
mergeBlockEnhancedFilter.setLoggerHandler( self.handler )
122+
if not isHandlerInLogger( HANDLER, mergeBlockEnhancedFilter.logger ):
123+
mergeBlockEnhancedFilter.setLoggerHandler( HANDLER )
123124

124125
try:
125126
mergeBlockEnhancedFilter.applyFilter()

geos-pv/src/geos/pv/plugins/generic_processing/PVSplitMesh.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@
3939
4040
"""
4141

42+
HANDLER: logging.Handler = VTKHandler()
43+
4244

4345
@SISOFilter( category=FilterCategory.GENERIC_PROCESSING, decoratedLabel="Split Mesh", decoratedType="vtkPointSet" )
4446
class PVSplitMesh( VTKPythonAlgorithmBase ):
4547

4648
def __init__( self: Self ) -> None:
4749
"""Split mesh cells."""
48-
self.handler: logging.Handler = VTKHandler()
4950

5051
def ApplyFilter( self: Self, inputMesh: vtkPointSet, outputMesh: vtkPointSet ) -> None:
5152
"""Apply vtk filter.
@@ -55,8 +56,8 @@ def ApplyFilter( self: Self, inputMesh: vtkPointSet, outputMesh: vtkPointSet ) -
5556
outputMesh: Output mesh.
5657
"""
5758
splitMeshFilter: SplitMesh = SplitMesh( inputMesh, True )
58-
if not isHandlerInLogger( self.handler, splitMeshFilter.logger ):
59-
splitMeshFilter.setLoggerHandler( self.handler )
59+
if not isHandlerInLogger( HANDLER, splitMeshFilter.logger ):
60+
splitMeshFilter.setLoggerHandler( HANDLER )
6061

6162
try:
6263
splitMeshFilter.applyFilter()

geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
7474
"""
7575

76+
HANDLER: logging.Handler = VTKHandler()
77+
7678
loggerTitle: str = "Geomechanics Calculator"
7779

7880

@@ -93,10 +95,9 @@ def __init__( self: Self ) -> None:
9395
self.rockCohesion: float = DEFAULT_ROCK_COHESION
9496
self.frictionAngle: float = DEFAULT_FRICTION_ANGLE_DEG
9597

96-
self.handler: logging.Handler = VTKHandler()
9798
self.logger = logging.getLogger( loggerTitle )
9899
self.logger.setLevel( logging.INFO )
99-
self.logger.addHandler( self.handler )
100+
self.logger.addHandler( HANDLER )
100101
self.logger.propagate = False
101102

102103
counter: CountWarningHandler = CountWarningHandler()
@@ -265,8 +266,8 @@ def ApplyFilter(
265266
speHandler=True,
266267
)
267268

268-
if not isHandlerInLogger( self.handler, geomechanicsCalculatorFilter.logger ):
269-
geomechanicsCalculatorFilter.setLoggerHandler( self.handler )
269+
if not isHandlerInLogger( HANDLER, geomechanicsCalculatorFilter.logger ):
270+
geomechanicsCalculatorFilter.setLoggerHandler( HANDLER )
270271

271272
geomechanicsCalculatorFilter.physicalConstants.grainBulkModulus = self.grainBulkModulus
272273
geomechanicsCalculatorFilter.physicalConstants.specificDensity = self.specificDensity
@@ -303,8 +304,8 @@ def ApplyFilter(
303304
True,
304305
)
305306

306-
if not isHandlerInLogger( self.handler, geomechanicsCalculatorFilter.logger ):
307-
geomechanicsCalculatorFilter.setLoggerHandler( self.handler )
307+
if not isHandlerInLogger( HANDLER, geomechanicsCalculatorFilter.logger ):
308+
geomechanicsCalculatorFilter.setLoggerHandler( HANDLER )
308309

309310
geomechanicsCalculatorFilter.physicalConstants.grainBulkModulus = self.grainBulkModulus
310311
geomechanicsCalculatorFilter.physicalConstants.specificDensity = self.specificDensity

geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
8686
"""
8787

88+
HANDLER: logging.Handler = VTKHandler()
8889
loggerTitle: str = "GEOS Geomechanics Workflow"
8990

9091

@@ -139,10 +140,9 @@ def __init__( self: Self ) -> None:
139140
self.rockCohesion: float = DEFAULT_ROCK_COHESION
140141
self.frictionAngle: float = DEFAULT_FRICTION_ANGLE_DEG
141142

142-
self.handler: logging.Handler = VTKHandler()
143143
self.logger = logging.getLogger( loggerTitle )
144144
self.logger.setLevel( logging.INFO )
145-
self.logger.addHandler( self.handler )
145+
self.logger.addHandler( HANDLER )
146146
self.logger.propagate = False
147147

148148
counter: CountWarningHandler = CountWarningHandler()

0 commit comments

Comments
 (0)