Logging#

Module controlling PyFluent’s logging functionality.

For a basic user guide, see the logging user guide.

ansys.fluent.core.logging.configure_env_var()#

Verifies whether PYFLUENT_LOGGING environment variable was defined in the system. Executed once automatically on PyFluent initialization.

Notes

The usual way to enable PyFluent logging to file is through enable(). PYFLUENT_LOGGING set to 0 or OFF is the same as if no environment variable was set. If logging debug output to file by default is desired, without having to use enable() every time, set environment variable PYFLUENT_LOGGING to DEBUG. See also the user guide environment variable subsection.

ansys.fluent.core.logging.enable(level='DEBUG', custom_config=None)#

Enables PyFluent logging to file.

Parameters:
levelstr or int, optional

Specified logging level to set PyFluent loggers to. If omitted, level is set to DEBUG.

custom_configdict, optional

Used to provide a customized logging configuration file that will be used instead of the logging_config.yaml file (see also get_default_config()).

Notes

See logging levels in https://docs.python.org/3/library/logging.html#logging-levels

Examples

Using the default logging setup:

>>> import ansys.fluent.core as pyfluent
>>> pyfluent.logging.enable()

Customizing logging configuration (see also get_default_config()):

>>> import ansys.fluent.core as pyfluent
>>> config_dict = pyfluent.logging.get_default_config()
>>> config_dict['handlers']['pyfluent_file']['filename'] = 'test.log'
>>> pyfluent.logging.enable(custom_config=config_dict)
ansys.fluent.core.logging.get_default_config()#

Returns the default configuration dictionary obtained from parsing from the PyFluent logging_config.yaml file.

Examples

>>> import ansys.fluent.core as pyfluent
>>> pyfluent.logging.get_default_config()
{'disable_existing_loggers': False,
 'formatters': {'logfile_fmt': {'format': '%(asctime)s %(name)-21s '
                                          '%(levelname)-8s %(message)s'}},
 'handlers': {'pyfluent_file': {'backupCount': 9,
                                'class': 'logging.handlers.RotatingFileHandler',
                                'filename': 'pyfluent.log',
                                'formatter': 'logfile_fmt',
                                'level': 'NOTSET',
                                'maxBytes': 10485760}},
 'loggers': {'pyfluent.datamodel': {'handlers': ['pyfluent_file'],
                                    'level': 'DEBUG'},
             'pyfluent.general': {'handlers': ['pyfluent_file'],
                                  'level': 'DEBUG'},
             'pyfluent.launcher': {'handlers': ['pyfluent_file'],
                                   'level': 'DEBUG'},
             'pyfluent.networking': {'handlers': ['pyfluent_file'],
                                     'level': 'DEBUG'},
             'pyfluent.post_objects': {'handlers': ['pyfluent_file'],
                                       'level': 'DEBUG'},
             'pyfluent.settings_api': {'handlers': ['pyfluent_file'],
                                       'level': 'DEBUG'},
             'pyfluent.tui': {'handlers': ['pyfluent_file'], 'level': 'DEBUG'}},
 'version': 1}
ansys.fluent.core.logging.get_logger(*args, **kwargs)#

Retrieves logger.

Convenience wrapper for Python’s logging.getLogger() function.

ansys.fluent.core.logging.is_active()#

Returns whether PyFluent logging to file is active.

ansys.fluent.core.logging.list_loggers()#

List all PyFluent loggers.

Returns:
list of str

Each list element is a PyFluent logger name that can be individually controlled through ansys.fluent.core.logging.get_logger().

Notes

PyFluent loggers use the standard Python logging library, for more details see https://docs.python.org/3/library/logging.html#logger-objects

Examples

>>> import ansys.fluent.core as pyfluent
>>> pyfluent.logging.enable()
>>> pyfluent.logging.list_loggers()
['pyfluent.general', 'pyfluent.launcher', 'pyfluent.networking', ...]
>>> logger = pyfluent.logging.get_logger('pyfluent.networking')
>>> logger
<Logger pyfluent.networking (DEBUG)>
>>> logger.setLevel('ERROR')
>>> logger
<Logger pyfluent.networking (ERROR)>
ansys.fluent.core.logging.root_config()#

Sets up the root PyFluent logger that outputs messages to stdout, but not to files.

ansys.fluent.core.logging.set_global_level(level)#

Changes the levels of all PyFluent loggers that write to log file.

Parameters:
levelstr or int

Specified logging level to set PyFluent loggers to.

Notes

See logging levels in https://docs.python.org/3/library/logging.html#logging-levels

Examples

>>> import ansys.fluent.core as pyfluent
>>> pyfluent.logging.set_global_level(10)

or

>>> pyfluent.logging.set_global_level('DEBUG')