-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: Add a logger for all the vtk filter of geos-processing and all the plugin of geos-pv #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f4f9bc6
d0b2bfb
e5823f3
be96ffd
cbba20b
313469d
97010df
5bdc8e0
479813a
e8159d3
ebe20dd
33e8249
94537cb
533fce1
1e935ed
cf9a437
fe04cb2
380a693
934f734
5b7a2af
e14a065
1966e36
6ac33ec
c62097c
d7f69d8
c6c1c9d
64c5c21
4eaef30
af6e564
fa79fd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,7 @@ def __init__( | |
| else: | ||
| self.logger = logging.getLogger( loggerTitle ) | ||
| self.logger.setLevel( logging.INFO ) | ||
| self.logger.propagate = False | ||
|
|
||
| def setLoggerHandler( self: Self, handler: logging.Handler ) -> None: | ||
| """Set a specific handler for the filter logger. | ||
|
|
@@ -113,7 +114,7 @@ def setLoggerHandler( self: Self, handler: logging.Handler ) -> None: | |
| Args: | ||
| handler (logging.Handler): The handler to add. | ||
| """ | ||
| if not self.logger.hasHandlers(): | ||
| if len( self.logger.handlers ) == 0: | ||
| self.logger.addHandler( handler ) | ||
| else: | ||
| self.logger.warning( "The logger already has an handler, to use yours set the argument 'speHandler'" | ||
|
|
@@ -139,58 +140,58 @@ def applyFilter( self: Self ) -> bool: | |
| """ | ||
| self.logger.info( f"Apply filter { self.logger.name }." ) | ||
|
|
||
| if len( self.attributeNames ) == 0: | ||
| self.logger.warning( f"Please enter at least one { self.piece } attribute to transfer." ) | ||
| self.logger.warning( f"The filter { self.logger.name } has not been used." ) | ||
| return False | ||
|
|
||
| attributesInMeshFrom: set[ str ] = getAttributeSet( self.meshFrom, self.onPoints ) | ||
| wrongAttributeNames: set[ str ] = self.attributeNames.difference( attributesInMeshFrom ) | ||
| if len( wrongAttributeNames ) > 0: | ||
| self.logger.error( | ||
| f"The { self.piece } attributes { wrongAttributeNames } are not present in the source mesh." ) | ||
| self.logger.error( f"The filter { self.logger.name } failed." ) | ||
| return False | ||
|
|
||
| attributesInMeshTo: set[ str ] = getAttributeSet( self.meshTo, self.onPoints ) | ||
| attributesAlreadyInMeshTo: set[ str ] = self.attributeNames.intersection( attributesInMeshTo ) | ||
| if len( attributesAlreadyInMeshTo ) > 0: | ||
| self.logger.error( | ||
| f"The { self.piece } attributes { attributesAlreadyInMeshTo } are already present in the final mesh." ) | ||
| self.logger.error( f"The filter { self.logger.name } failed." ) | ||
| return False | ||
| try: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure of try except and raise in the try.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this pr I wanted to add or update the logger. To do that I used the same scheme try/except in all the plugins and filters. But your are right, the filtre may not use try/except. To keep "small" and "unitary" pr, I think it can be done in another pr (see pr #185 ) |
||
| if len( self.attributeNames ) == 0: | ||
| raise ValueError( f"Please enter at least one { self.piece } attribute to transfer." ) | ||
|
|
||
| attributesInMeshFrom: set[ str ] = getAttributeSet( self.meshFrom, self.onPoints ) | ||
| wrongAttributeNames: set[ str ] = self.attributeNames.difference( attributesInMeshFrom ) | ||
| if len( wrongAttributeNames ) > 0: | ||
| raise AttributeError( | ||
| f"The { self.piece } attributes { wrongAttributeNames } are not present in the source mesh." ) | ||
|
|
||
| attributesInMeshTo: set[ str ] = getAttributeSet( self.meshTo, self.onPoints ) | ||
| attributesAlreadyInMeshTo: set[ str ] = self.attributeNames.intersection( attributesInMeshTo ) | ||
| if len( attributesAlreadyInMeshTo ) > 0: | ||
| raise AttributeError( | ||
| f"The { self.piece } attributes { attributesAlreadyInMeshTo } are already present in the final mesh." | ||
| ) | ||
|
|
||
| if isinstance( self.meshFrom, vtkMultiBlockDataSet ): | ||
| partialAttributes: list[ str ] = [] | ||
| for attributeName in self.attributeNames: | ||
| if not isAttributeGlobal( self.meshFrom, attributeName, self.onPoints ): | ||
| partialAttributes.append( attributeName ) | ||
|
|
||
| if len( partialAttributes ) > 0: | ||
| raise AttributeError( | ||
| f"All { self.piece } attributes to transfer must be global, { partialAttributes } are partials." | ||
| ) | ||
|
|
||
| self.ElementMap = computeElementMapping( self.meshFrom, self.meshTo, self.onPoints ) | ||
| sharedElement: bool = False | ||
| for key in self.ElementMap: | ||
| if np.any( self.ElementMap[ key ] > -1 ): | ||
| sharedElement = True | ||
|
|
||
| if not sharedElement: | ||
| raise ValueError( f"The two meshes do not have any shared { self.piece }." ) | ||
|
|
||
| if isinstance( self.meshFrom, vtkMultiBlockDataSet ): | ||
| partialAttributes: list[ str ] = [] | ||
| for attributeName in self.attributeNames: | ||
| if not isAttributeGlobal( self.meshFrom, attributeName, self.onPoints ): | ||
| partialAttributes.append( attributeName ) | ||
|
|
||
| if len( partialAttributes ) > 0: | ||
| self.logger.error( | ||
| f"All { self.piece } attributes to transfer must be global, { partialAttributes } are partials." ) | ||
| self.logger.error( f"The filter { self.logger.name } failed." ) | ||
|
|
||
| self.ElementMap = computeElementMapping( self.meshFrom, self.meshTo, self.onPoints ) | ||
| sharedElement: bool = False | ||
| for key in self.ElementMap: | ||
| if np.any( self.ElementMap[ key ] > -1 ): | ||
| sharedElement = True | ||
|
|
||
| if not sharedElement: | ||
| self.logger.warning( f"The two meshes do not have any shared { self.piece }." ) | ||
| self.logger.warning( f"The filter { self.logger.name } has not been used." ) | ||
| # TODO:: Modify arrayModifiers function to raise error. | ||
| if not transferAttributeWithElementMap( self.meshFrom, self.meshTo, self.ElementMap, attributeName, | ||
| self.onPoints, self.logger ): | ||
| raise | ||
|
|
||
| # Log the output message. | ||
| self._logOutputMessage() | ||
| except ( TypeError, ValueError, AttributeError ) as e: | ||
| self.logger.error( f"The filter { self.logger.name } failed.\n{ e }" ) | ||
| return False | ||
| except Exception as e: | ||
| mess: str = f"The filter { self.logger.name } failed.\n{ e }" | ||
| self.logger.critical( mess, exc_info=True ) | ||
| return False | ||
|
|
||
| for attributeName in self.attributeNames: | ||
| if not transferAttributeWithElementMap( self.meshFrom, self.meshTo, self.ElementMap, attributeName, | ||
| self.onPoints, self.logger ): | ||
| self.logger.error( f"The attribute { attributeName } has not been mapped." ) | ||
| self.logger.error( f"The filter { self.logger.name } failed." ) | ||
| return False | ||
|
|
||
| # Log the output message. | ||
| self._logOutputMessage() | ||
|
|
||
| return True | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why in this PR ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I changed the filter MergeBlockEnhanced, its test needed to be change to, this test was usless with the new implementation of the filter so I move it to the test of the function mergeBlock