Logger#

class ansys.geometry.core.logger.Logger(level=logging.DEBUG, to_file=False, to_stdout=True, filename=FILE_NAME)#

Provides the logger used for each PyAnsys Geometry session.

This class allows you to add handlers to the logger to output messages to a file or to the standard output (stdout).

Parameters:
levelint, default: 10

Logging level to filter the message severity allowed in the logger. The default is 10, in which case the logging.DEBUG level is used.

to_filebool, default: False

Whether to write log messages to a file.

to_stdoutbool, default: True

Whether to write log messages to the standard output.

filenamestr, default: “pyansys-geometry.log”

Name of the file to write log log messages to.

Examples

Demonstrate logger usage from the Modeler instance, which is automatically created when a Geometry service instance is created.

>>> from ansys.geometry.core import Modeler
>>> modeler = Modeler(loglevel='DEBUG')
>>> modeler._log.info('This is a useful message')
INFO -  -   -  - This is LOG debug message.

Import the global PyAnsys Geometry logger and add a file output handler.

>>> import os
>>> from ansys.geometry.core import LOG
>>> file_path = os.path.join(os.getcwd(), 'pyansys-geometry.log')
>>> LOG.log_to_file(file_path)

Overview#

log_to_file

Add a file handler to the logger.

log_to_stdout

Add the standard output handler to the logger.

setLevel

Change the log level of the object and the attached handlers.

add_child_logger

Add a child logger to the main logger.

add_instance_logger

Add a logger for a Geometry service instance.

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.geometry.core.logger import Logger

Attribute detail#

Logger.file_handler = None#
Logger.std_out_handler = None#

Method detail#

Logger.log_to_file(filename=FILE_NAME, level=LOG_LEVEL)#

Add a file handler to the logger.

Parameters:
filenamestr, default: “pyansys-geometry.log”

Name of the file to write log messages to.

levelint, default: 10

Level of logging. The default is 10, in which case the logging.DEBUG level is used.

Examples

Write to the "pyansys-geometry.log" file in the current working directory:

>>> from ansys.geometry.core import LOG
>>> import os
>>> file_path = os.path.join(os.getcwd(), 'pyansys-geometry.log')
>>> LOG.log_to_file(file_path)
Logger.log_to_stdout(level=LOG_LEVEL)#

Add the standard output handler to the logger.

Parameters:
levelint, default: 10

Level of logging. The default is 10, in which case the logging.DEBUG level is used.

Logger.setLevel(level='DEBUG')#

Change the log level of the object and the attached handlers.

Logger.add_child_logger(suffix: str, level: beartype.typing.Optional[str] = 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 Geometry service 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 child logger.

levelstr, default: None

Level of logging.

Returns:
logging.Logger

Logger class.

Logger.add_instance_logger(name: str, client_instance: ansys.geometry.core.connection.client.GrpcClient, level: beartype.typing.Optional[int] = None) PyGeometryCustomAdapter#

Add a logger for a Geometry service instance.

The Geometry service instance logger is a logger with an adapter that adds contextual information such as the Geometry service instance name. This logger is returned, and you can use it to log events as a normal logger. It is stored in the _instances field.

Parameters:
namestr

Name for the new instance logger.

client_instanceGrpcClient

Geometry service GrpcClient object, which should contain the get_name method.

levelint, default: None

Level of logging.

Returns:
PyGeometryCustomAdapter

Logger adapter customized to add Geometry service information to the logs. You can use this class to log events in the same way you would with the Logger class.

Logger.__getitem__(key)#

Overload the access method by item for the Logger class.

Logger.add_handling_uncaught_expections(logger)#

Redirect the output of an exception to a logger.

Parameters:
loggerstr

Name of the logger.