logger#

Configure and control PyFluent logging.

This module builds on Python’s standard logging package and provides PyFluent-specific defaults and helpers. PyFluent messages use the pyfluent logger hierarchy and are written to the console at warning level by default. File logging can be enabled with enable(), which uses a rotating file handler and the configuration in logging_config.yaml. The PYFLUENT_LOGGING environment variable can enable file logging automatically during PyFluent initialization.

The public helpers support enabling file logging, changing console and file log levels, checking whether file logging is active, obtaining a logger, loading the default configuration, and providing a custom logging configuration. Startup and logger-discovery helpers are kept internal to the module.

Functions:

enable([level, custom_config])

Enable PyFluent logging to a rotating log file.

get_default_config()

Load PyFluent's default logging configuration.

get_logger(*args, **kwargs)

Return a standard-library logger for a PyFluent component.

is_active()

Return whether PyFluent file logging is currently enabled.

set_console_logging_level(level)

Set the minimum level of PyFluent messages written to the console.

set_global_level(level)

Set the level of all registered PyFluent file loggers.

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

Enable PyFluent logging to a rotating log file.

By default, PyFluent uses the packaged logging_config.yaml file and writes to pyfluent.log in the current working directory. Calling this function again reconfigures logging with the supplied configuration.

Parameters:
levelstr or int, optional

Minimum level for PyFluent loggers writing to the file. If omitted, "DEBUG" is used.

custom_configdict, optional

A logging.config.dictConfig-compatible configuration. Use get_default_config() as a starting point when customizing the default configuration.

See also

get_default_config

Load the packaged logging configuration for customization.

Notes

File logging can also be enabled automatically by setting the PYFLUENT_LOGGING environment variable before importing PyFluent.

Examples

Using the default logging setup:

>>> import ansys.fluent.core as pyfluent
>>> pyfluent.diagnostics.logger.enable()

Customizing logging configuration (see also get_default_config()):

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

Load PyFluent’s default logging configuration.

Returns:
dict

A dictionary parsed from PyFluent’s logging_config.yaml file. The dictionary can be modified and passed to enable() through its custom_config parameter.

Examples

>>> import ansys.fluent.core as pyfluent
>>> pyfluent.diagnostics.logger.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.expressions': {'handlers': ['pyfluent_file'],
                                       'level': 'DEBUG'},
             'pyfluent.field_data': {'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.settings_api': {'handlers': ['pyfluent_file'],
                                       'level': 'DEBUG'},
             'pyfluent.tui': {'handlers': ['pyfluent_file'], 'level': 'DEBUG'}},
 'version': 1}
ansys.fluent.core.diagnostics.logger.get_logger(*args, **kwargs)#

Return a standard-library logger for a PyFluent component.

Parameters:
*args, **kwargs

Arguments forwarded to logging.getLogger(). Passing a name such as "pyfluent.launcher" is recommended for component-specific logging.

Returns:
logging.Logger

The requested logger instance.

Examples

>>> import ansys.fluent.core as pyfluent
>>> logger = pyfluent.get_logger("pyfluent.my_component")
>>> logger.info("Component initialized")
ansys.fluent.core.diagnostics.logger.is_active()#

Return whether PyFluent file logging is currently enabled.

Returns:
bool

True after enable() has configured file logging; otherwise False.

ansys.fluent.core.diagnostics.logger.set_console_logging_level(level)#

Set the minimum level of PyFluent messages written to the console.

Parameters:
levelstr or int

Logging level, such as "INFO", "DEBUG", or logging.INFO. Messages below this level are filtered from the console handler.

Notes

This changes console output only. Use set_global_level() to change the levels of loggers writing to the PyFluent log file. See logging levels in https://docs.python.org/3/library/logging.html#logging-levels

Examples

>>> import ansys.fluent.core as pyfluent
>>> pyfluent.set_console_logging_level("INFO")
ansys.fluent.core.diagnostics.logger.set_global_level(level)#

Set the level of all registered PyFluent file loggers.

Parameters:
levelstr or int

Logging level, such as "DEBUG", "INFO", or logging.WARNING.

Notes

File logging must be enabled with enable() first. This function does not change the console logger level; use set_console_logging_level() for console output.

Examples

>>> import ansys.fluent.core as pyfluent
>>> pyfluent.enable()
>>> pyfluent.set_global_level("INFO")
>>> pyfluent.diagnostics.logger.set_global_level(10)

or

>>> pyfluent.diagnostics.logger.set_global_level('DEBUG')