logging#

Module controlling PyCFX’s logging functionality.

Functions:

configure_env_var()

Check if a PYCFX_LOGGING environment variable is defined in the system.

enable([level, custom_config])

Enable PyCFX logging to file.

get_default_config()

Get the default configuration dictionary obtained from parsing from the PyCFX logging_config.yaml file.

get_logger(*args, **kwargs)

Get the logger.

is_active()

Check whether PyCFX logging to file is active.

list_loggers()

List all PyCFX loggers.

root_config()

Set up the root PyCFX logger that outputs messages to stdout, but not to files.

set_global_level(level)

Set the levels of all PyCFX loggers that write to the log file.

ansys.cfx.core.logging.configure_env_var() None#

Check if a PYCFX_LOGGING environment variable is defined in the system. This function is executed once automatically on PyCFX initialization.

Notes

The usual way to enable PyCFX logging to file is by using the enable() function. Setting PYCFX_LOGGING to 0 or OFF is the same as if no environment variable is set. If logging debug output to file by default is desired, without having to use the enable() function every time, set the PYCFX_LOGGING environment variable to DEBUG.

ansys.cfx.core.logging.enable(level: str | int = 'DEBUG', custom_config: dict | None = None)#

Enable PyCFX logging to file.

Parameters:
levelstr or int, default: “DEBUG”

Logging level to set PyCFX loggers to.

custom_configdict, default: None

Customized logging configuration file to use instead of the logging_config.yaml file. (See also the get_default_config() function.)

Notes

See Logging Levels in the Python documentation.

Examples

Usd the default logging setup:

>>> import ansys.cfx.core as pycfx
>>> pycfx.logging.enable()
PyCFX logging file ...
Setting PyCFX global logging level to DEBUG.

Customize the logging configuration (see also the get_default_config() function):

>>> import ansys.cfx.core as pycfx
>>> config_dict = pycfx.logging.get_default_config()
>>> config_dict['handlers']['pycfx_file']['filename'] = 'test.log'
>>> pycfx.logging.enable(custom_config=config_dict)
PyCFX logging file ...
Setting PyCFX global logging level to DEBUG.
ansys.cfx.core.logging.get_default_config() dict#

Get the default configuration dictionary obtained from parsing from the PyCFX logging_config.yaml file.

Examples

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

Get the logger.

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

ansys.cfx.core.logging.is_active() bool#

Check whether PyCFX logging to file is active.

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

List all PyCFX loggers.

Returns:
list of str

Each list element is a PyCFX logger name that can be individually controlled through the ansys.cfx.core.logging.get_logger() function.

Notes

PyCFX loggers use the standard Python logging library. For more information, see Logger Objects in the Python documentation.

Examples

>>> import ansys.cfx.core as pycfx
>>> pycfx.logging.enable()
PyCFX logging file ...
Setting PyCFX global logging level to DEBUG.
>>> all_loggers = pycfx.logging.list_loggers()
>>> all_loggers.sort()
>>> all_loggers
['pycfx', 'pycfx.general', 'pycfx.launcher', 'pycfx.networking', ...
>>> logger = pycfx.logging.get_logger('pycfx.networking')
>>> logger
<Logger pycfx.networking (DEBUG)>
>>> logger.setLevel('ERROR')
>>> logger
<Logger pycfx.networking (ERROR)>
ansys.cfx.core.logging.root_config()#

Set up the root PyCFX logger that outputs messages to stdout, but not to files.

ansys.cfx.core.logging.set_global_level(level: str | int)#

Set the levels of all PyCFX loggers that write to the log file.

Parameters:
levelstr or int

Logging level to set PyCFX loggers to.

Notes

See Logging Levels in the Python documentation.

Examples

>>> import ansys.cfx.core as pycfx
>>> pycfx.logging.set_global_level(10)
Setting PyCFX global logging level to 10.
>>> pycfx.logging.set_global_level('DEBUG')
Setting PyCFX global logging level to DEBUG.