Logger
#
- class ansys.health.heart.logger.Logger(level: LOG_LEVEL_TYPE = logging.DEBUG, to_file: bool = False, to_stdout: bool = True, filename: str = FILE_NAME)#
Provides the logger used for each PyAnsys Heart session.
This class lets you add handlers to the logger to output messages to a file or to the standard output (stdout).
- Parameters:
- level
int
, default:logging.DEBUG
Logging level to filter the message severity allowed in the logger.
- to_filebool, default:
False
Whether to write log messages to a file.
- to_stdoutbool, default:
True
Whether to write the log messages to stdout.
- filename
str
, default:FILE_NAME
Name of the file to write log messages to.
- level
Examples
Demonstrate logger usage from a PyAnsys Heart instance, which is automatically created when a PyAnsys Heart instance is created.
Import the global PyAnsys Heart logger and add a file output handler.
>>> import os >>> from ansys.health.heart import LOG >>> file_path = os.path.join(os.getcwd(), "PyAnsys Heart.log") >>> LOG.log_to_file(file_path)
Overview#
Add a file handler to the logger. |
|
Add a stdout handler to the logger. |
|
Set the log level for the logger and its handlers. |
|
Add a child logger to the main logger. |
|
Redirect the output of an exception to a logger. |
Overload the access method by item for the |
Import detail#
from ansys.health.heart.logger import Logger
Attribute detail#
- Logger.file_handler: logging.FileHandler | None = None#
- Logger.std_out_handler: logging.StreamHandler | None = None#
- Logger.logger: logging.Logger#
- Logger.level = 0#
- Logger.debug#
- Logger.info#
- Logger.warning#
- Logger.error#
- Logger.critical#
- Logger.log#
Method detail#
- Logger.log_to_file(filename: str = FILE_NAME, level: LOG_LEVEL_TYPE = LOG_LEVEL_FILE, remove_other_file_handlers: bool = False) None #
Add a file handler to the logger.
- Parameters:
Examples
Write to the
PyAnsys Heart.log
file in the current working directory.>>> from ansys.health.heart import LOG >>> import os >>> file_path = os.path.join(os.getcwd(), "PyAnsys Heart.log") >>> LOG.log_to_file(file_path)
- Logger.log_to_stdout(level: LOG_LEVEL_TYPE = LOG_LEVEL_STDOUT)#
Add a stdout handler to the logger.
- Logger.setLevel(level: LOG_LEVEL_TYPE = 'DEBUG')#
Set the log level for the logger and its handlers.
- Logger.add_child_logger(suffix: str, level: LOG_LEVEL_TYPE | None = None)#
Add a child logger to the main logger.
This logger is more general than an instance logger, which is designed to track the state of PyAnsys Heart instances.
If the logging level is in the arguments, a new logger with a reference to the
_global
logger handlers is created instead of a child logger.
- Logger.__getitem__(key)#
Overload the access method by item for the
Logger
class.
- Logger.add_handling_uncaught_expections(logger: logging.Logger)#
Redirect the output of an exception to a logger.
- Parameters:
- logger
str
Name of the logger.
- logger