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:
- level
int
,optional
Logging level for filtering the messages that are allowed in the logger. The default is
10
, in which case theDEBUG
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
.- filename
str
,optional
Name of the file to write log messages to. The default is
pymechanical.log
.
- level
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.
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