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:
levelint, 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.

filenamestr, default: FILE_NAME

Name of the file to write log messages to.

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#

log_to_file

Add a file handler to the logger.

log_to_stdout

Add a stdout handler to the logger.

setLevel

Set the log level for the logger and its handlers.

add_child_logger

Add a child logger to the main logger.

add_handling_uncaught_expections

Redirect the output of an exception to a logger.

__getitem__

Overload the access method by item for the Logger class.

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:
filenamestr, default:

Name of the file to record logs to, which is 'PyAnsys Heart.log' by default.

levelstr or int, default: LOG_LEVEL_FILE

Level of logging, which is 'DEBUG' by default.

remove_other_file_handlersbool, default: False

Whether to remove all other file handlers.

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.

Parameters:
levelstr or int, default: LOG_LEVEL_STDOUT

Level of logging record, which is 'DEBUG' by default.

Logger.setLevel(level: LOG_LEVEL_TYPE = 'DEBUG')#

Set the log level for the logger and its handlers.

Parameters:
levelstr or int, default: “DEBUG”

Logging level to set.

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.

Parameters:
suffixstr

Name of the logger.

levelstr or int, default: None

Level of logging.

Returns:
logging.logger

Logger class.

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:
loggerstr

Name of the logger.