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 PyFluent logging to a rotating log file. |
Load PyFluent's default logging configuration. |
|
|
Return a standard-library logger for a PyFluent component. |
Return whether PyFluent file logging is currently enabled. |
|
|
Set the minimum level of PyFluent messages written to the console. |
|
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.yamlfile and writes topyfluent.login the current working directory. Calling this function again reconfigures logging with the supplied configuration.- Parameters:
- level
strorint,optional Minimum level for PyFluent loggers writing to the file. If omitted,
"DEBUG"is used.- custom_config
dict,optional A
logging.config.dictConfig-compatible configuration. Useget_default_config()as a starting point when customizing the default configuration.
- level
See also
get_default_configLoad the packaged logging configuration for customization.
Notes
File logging can also be enabled automatically by setting the
PYFLUENT_LOGGINGenvironment 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:
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.LoggerThe 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.
- ansys.fluent.core.diagnostics.logger.set_console_logging_level(level)#
Set the minimum level of PyFluent messages written to the console.
- Parameters:
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-levelsExamples
>>> 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.
Notes
File logging must be enabled with
enable()first. This function does not change the console logger level; useset_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')