pynrc.logging_utils.setup_logging

pynrc.logging_utils.setup_logging(level='INFO', filename=None, verbose=True)[source]

Setup Logging

Allows selection of logging detail and output locations (screen and/or file). Shamelessly stolen from WebbPSF utils.py.

This is a convenience wrapper to Python’s built-in logging package. By default, this sets up log messages to be written to the screen, but the user can also request logging to a file.

Editing the WebbPSF config file to set autoconfigure_logging = True (and any of the logging settings you wish to persist) instructs WebbPSF to apply your settings on import. (This is not done by default in case you have configured logging yourself and don’t wish to overwrite your configuration.)

For more advanced log handling, see the Python logging module’s own documentation.

Parameters
  • level (str) – Name of log output to show. Defaults to ‘INFO’, set to ‘DEBUG’ for more extensive messages, or to ‘WARN’ or ‘ERROR’ for fewer.

  • filename (str, optional) – Filename to write the log output to. If not set, output will just be displayed on screen. (Default: None)

Examples

>>> pynrc.setup_logging(filename='pynrc_log.txt')

This will save all log messages to ‘pynrc_log.txt’ in the current directory.

>>> pynrc.setup_logging(level='WARN')

This will show only WARNING or ERROR messages on screen, and not save any logs to files at all (since the filename argument is None)