logging#
Module controlling PyCFX’s logging functionality.
Functions:
Check if a |
|
|
Enable PyCFX logging to file. |
Get the default configuration dictionary obtained from parsing from the PyCFX |
|
|
Get the logger. |
Check whether PyCFX logging to file is active. |
|
List all PyCFX loggers. |
|
Set up the root PyCFX logger that outputs messages to stdout, but not to files. |
|
|
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_LOGGINGenvironment 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. SettingPYCFX_LOGGINGto0orOFFis the same as if no environment variable is set. If logging debug output to file by default is desired, without having to use theenable()function every time, set thePYCFX_LOGGINGenvironment variable toDEBUG.
- ansys.cfx.core.logging.enable(level: str | int = 'DEBUG', custom_config: dict | None = None)#
Enable PyCFX logging to file.
- Parameters:
- level
strorint, default: “DEBUG” Logging level to set PyCFX loggers to.
- custom_config
dict, default:None Customized logging configuration file to use instead of the
logging_config.yamlfile. (See also theget_default_config()function.)
- level
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.yamlfile.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.list_loggers()#
List all PyCFX loggers.
- Returns:
listofstrEach 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.
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.