Skip to content
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

Messages, logging, and exception #24

Merged
merged 4 commits into from
Oct 6, 2017
Merged

Messages, logging, and exception #24

merged 4 commits into from
Oct 6, 2017

Conversation

drewejohnson
Copy link
Collaborator

Closes #16

Added a messages module that contains functions for various status updates.
A custom Logger is created, and all updates, warnings, and debug statements pass through this object.
This is hidden with double underscores, __logger__, as to be super private.

All the updates are passed to one of four functions: messages.debug, messages.info, messages.warnings, and messages.error.
If we decide to change the underlying error reporting, by adding some file logs, or something totally crazy, as long as every other program just uses these functions, nothing should break.

Usage Examples

In the project

From the depletion reader:

def read(self):
        """Read through the depletion file and store requested data."""
        messages.info('Preparing to read {}'.format(self.filePath))
        # reading
        messages.info('Done reading depletion file')
        messages.debug('  found {} materials'.format(len(self.materials)))

Currently, the depletion reader does not play well with materials that contain underscores, because of variables like ING_TOX.
A warning is printed to inform the user of this fact:

if any(['_' in pat for pat in patterns]):
        messages.warning('Materials with underscores are not supported.')`

Any time a setting is changed, a debug statement is printed
messages.debug('Updated setting {} to {}'.format(name, value))

The error function has an additional setting: fatal.
If this value is true, a critical message is created, but also a SerpentToolsException is raised with the same message.
This may be redundant, but the exception can be caught and suppressed, while the message should still be raised.
If fatal is false, then an error message is posted.

Outward facing

To the user, the notices look as follows:


[ajohnson400@core serpent-tools]$ python
Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 12:22:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import serpentTools
INFO    : serpentTools   : Using version 1.0b0+3.gb8a02ab
>>> from serpentTools.settings import rc
>>> rc['verbosity'] = 'debug'
DEBUG   : serpentTools   : Updated setting verbosity to debug
>>> rc['depletion.processTotal'] = False
DEBUG   : serpentTools   : Updated setting depletion.processTotal to False

Exception

As mentioned above, a custom SerpentToolsException was created.
This is for any exception that is unique to this project and not covered by the base exceptions.
This can be subclassed for unique exceptions, e.g.

class ReaderSpecificException(SerpentToolsException):
    pass

Andrew Johnson added 3 commits October 5, 2017 15:39
Signed-off-by: Andrew Johnson <1drew.e.johnson@gmail.com>
Signed-off-by: Andrew Johnson <1drew.e.johnson@gmail.com>
Signed-off-by: Andrew Johnson <1drew.e.johnson@gmail.com>
@drewejohnson drewejohnson added this to the Version 1.0.0 milestone Oct 5, 2017
Signed-off-by: Andrew Johnson <1drew.e.johnson@gmail.com>
Copy link
Contributor

@DanKotlyar DanKotlyar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Drew. This is great.
But, in the future we do need to fix the '_' issue in material definition.

@DanKotlyar DanKotlyar closed this Oct 6, 2017
@drewejohnson drewejohnson reopened this Oct 6, 2017
@drewejohnson
Copy link
Collaborator Author

Reopened to squash and merge

@drewejohnson drewejohnson merged commit 7281428 into develop Oct 6, 2017
@drewejohnson drewejohnson deleted the messages branch October 15, 2017 23:55
drewejohnson added a commit that referenced this pull request Dec 13, 2017
* Updated gitignore to exclude pycharm project settings
* Skeleton files for each reader class; Basic directory setup
* Depletion reader and project settings (#1)
* Quick: DepletedMaterial returns time vector if not given as input (#2)
* Quick fix: DepletedMaterial getXY only returns time if no time is given as input
* Fixes #3; Cleaned up reader subclasses (#4)
* Fixes #3; Cleaned up reader subclasses
* Added versioneer (#18)
* Fix get xy (#21)
* Fixes #19: Material doesn't return days if given as input
* Fixed unit tests
* Versioneer (#23)
* Messages, logging, and exception (#24)
* Expand variable groups; XSReader base; Temporary settings  (#27)
* Branching testing; Temporary settings modification
* Initial documentation - sphinx (#28)
* Added variables.yaml to data_files in setup (#32)
* Added depreciation and future warning decorators; More debug statements (#34)
* Depletion reader now correctly adds data from TOT; Updated defaults (#39)
* Better support (#40)
* Added python 2.7 support (#41)
* Homogenized Universe (#35)
* Read depmtx (#44)
* Return A matrix from depmtx as csc matrix not csr (#46)
* Remove settings package; Cleaned up messages file (#47)
* Implemented a module level read function (#48)
* Examples (#49)
* depmtx reader now parses using regular expressions (#52)
* Updated documentation - developer guide, api, and examples (#59)
* Updated setup.py to begrudgingly support distutils (#61)
* Use warnings.catch_warnings to record warnings in test_settings (#55)
* Native drewtils (#62)
* Branching Reader (#65)
* Release 0.1.0
drewejohnson added a commit that referenced this pull request Dec 13, 2017
* Release 0.1.0 (#66)

* Updated gitignore to exclude pycharm project settings
* Skeleton files for each reader class; Basic directory setup
* Depletion reader and project settings (#1)
* Quick: DepletedMaterial returns time vector if not given as input (#2)
* Quick fix: DepletedMaterial getXY only returns time if no time is given as input
* Fixes #3; Cleaned up reader subclasses (#4)
* Fixes #3; Cleaned up reader subclasses
* Added versioneer (#18)
* Fix get xy (#21)
* Fixes #19: Material doesn't return days if given as input
* Fixed unit tests
* Versioneer (#23)
* Messages, logging, and exception (#24)
* Expand variable groups; XSReader base; Temporary settings  (#27)
* Branching testing; Temporary settings modification
* Initial documentation - sphinx (#28)
* Added variables.yaml to data_files in setup (#32)
* Added depreciation and future warning decorators; More debug statements (#34)
* Depletion reader now correctly adds data from TOT; Updated defaults (#39)
* Better support (#40)
* Added python 2.7 support (#41)
* Homogenized Universe (#35)
* Read depmtx (#44)
* Return A matrix from depmtx as csc matrix not csr (#46)
* Remove settings package; Cleaned up messages file (#47)
* Implemented a module level read function (#48)
* Examples (#49)
* depmtx reader now parses using regular expressions (#52)
* Updated documentation - developer guide, api, and examples (#59)
* Updated setup.py to begrudgingly support distutils (#61)
* Use warnings.catch_warnings to record warnings in test_settings (#55)
* Native drewtils (#62)
* Branching Reader (#65)
* Release 0.1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants