Logger#

class ansys.mechanical.core.logging.Logger(level=10, to_file=False, to_stdout=True, filename='pymechanical.log')#

Provides for adding handlers to the logger for each Mechanical session.

This class allows you to add handlers to the logger to output to a file or the standard output.

Parameters:
levelint, optional

Logging level for filtering the messages that are allowed in the logger. The default is 10, in which case the DEBUG level is used.

to_filebool, optional

Whether to write log messages to a file. The default is False.

to_stdoutbool, optional

Whether to write log messages to the standard output. The default is True.

filenamestr, optional

Name of the file to write log messages to. The default is pymechanical.log.

Examples

Demonstrate logger usage from a Mechanical instance. The logger is automatically created when a Mechanical instance is created.

>>> from ansys.mechanical.core import launch_mechanical
>>> mechanical = launch_mechanical(loglevel='DEBUG')
>>> mechanical.log.info('This is a useful message')
INFO -  -  <ipython-input-24-80df150fe31f> - <module> - This is LOG debug message.

Import the PyMechanical global logger and add a file output handler.

>>> import os
>>> from ansys.mechanical.core import LOG
>>> file_path = os.path.join(os.getcwd(), 'pymechanical.log')
>>> LOG.log_to_file(file_path)

Methods

Logger.add_child_logger(suffix[, level])

Add a child logger to the main logger.

Logger.add_handling_uncaught_exceptions(logger)

Redirect the output of an exception to a logger.

Logger.add_instance_logger(name, ...[, level])

Add a logger for a Mechanical instance.

Logger.log_to_file([filename, level])

Add a file handler to the logger.

Logger.log_to_stdout([level])

Add a standard output handler to the logger.

Logger.setLevel([level])

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

Attributes

Logger.file_handler

Logger.std_out_handler