Logger#

class ansys.mapdl.core.logging.Logger(level=10, to_file=False, to_stdout=True, filename='pymapdl.log')[source]#

Logger used for each Pymapdl session.

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

Parameters:
levelint, optional

Logging level to filter the message severity allowed in the logger. The default is logging.DEBUG.

to_filetbool, optional

Write log messages to a file. The default is False.

to_stdoutbool, optional

Write log messages into the standard output. The default is True.

filenamestr, optional

Name of the file where log messages are written to. The default is None.

Examples

Demonstrate logger usage from an instance mapdl. This is automatically created when creating an Mapdl instance.

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

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

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

Methods

Logger.add_child_logger(sufix[, level])

Add a child logger to the main logger.

Logger.add_handling_uncaught_expections(logger)

This just redirect the output of an exception to the logger.

Logger.add_instance_logger(name, mapdl_instance)

Create a logger for a MAPDL instance.

Logger.log_to_file([filename, level])

Add file handler to logger.

Logger.log_to_stdout([level])

Add 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