:class:`Logger`
===============

.. py:class:: ansys.speos.core.logger.Logger(level=logging.DEBUG, to_file=False, to_stdout=True, filename=FILE_NAME)

   
   Provides the logger used for each PySpeos session.

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

   :Parameters:

       **level** : :class:`python:int`, default: 10
           Logging level to filter the message severity allowed in the logger.
           By default, the ``logging.DEBUG`` level is used.

       **to_file** : :ref:`bool <python:bltin-boolean-values>`, default: :data:`python:False`
           Whether to write log messages to a file.

       **to_stdout** : :ref:`bool <python:bltin-boolean-values>`, default: :data:`python:True`
           Whether to write log messages to the standard output (stdout).

       **filename** : :class:`python:str`, default: "pyspeos.log"
           Name of the file to write log log messages to.













   .. rubric:: Examples

   Demonstrate logger usage from the ``Speos`` instance, which is automatically
   created when a speos instance is created.

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

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

   >>> import os
   >>> from ansys.speos.core import LOG
   >>> file_path = os.path.join(os.getcwd(), "pyspeos.log")
   >>> LOG.log_to_file(file_path)

   ..
       !! processed by numpydoc !!



.. py:currentmodule:: Logger

Overview
--------

.. tab-set::



   .. tab-item:: Methods

      .. list-table::
          :header-rows: 0
          :widths: auto

          * - :py:attr:`~log_to_file`
            - Add file handler to logger.
          * - :py:attr:`~log_to_stdout`
            - Add the standard output handler to the logger.
          * - :py:attr:`~setLevel`
            - Change the log level of the object and the attached handlers.
          * - :py:attr:`~add_child_logger`
            - Add a child logger to the main logger.
          * - :py:attr:`~add_instance_logger`
            - Add a logger for a speos instance.
          * - :py:attr:`~add_handling_uncaught_expections`
            - Redirect the output of an exception to a logger.



   .. tab-item:: Attributes

      .. list-table::
          :header-rows: 0
          :widths: auto

          * - :py:attr:`~file_handler`
            - 
          * - :py:attr:`~std_out_handler`
            - 
          * - :py:attr:`~logger`
            - 
          * - :py:attr:`~debug`
            - 
          * - :py:attr:`~info`
            - 
          * - :py:attr:`~warning`
            - 
          * - :py:attr:`~error`
            - 
          * - :py:attr:`~critical`
            - 
          * - :py:attr:`~log`
            - 



   .. tab-item:: Special methods

      .. list-table::
          :header-rows: 0
          :widths: auto

          * - :py:attr:`~__getitem__`
            - Magic method to allow retrieval of instances.




Import detail
-------------

.. code-block:: python

    from ansys.speos.core.logger import Logger


Attribute detail
----------------

.. py:attribute:: file_handler
   :value: None


.. py:attribute:: std_out_handler
   :value: None


.. py:attribute:: logger

.. py:attribute:: debug

.. py:attribute:: info

.. py:attribute:: warning

.. py:attribute:: error

.. py:attribute:: critical

.. py:attribute:: log



Method detail
-------------

.. py:method:: log_to_file(filename=FILE_NAME, level=LOG_LEVEL)

   
   Add file handler to logger.


   :Parameters:

       **filename** : :class:`python:str`, :obj:`optional`
           Name of the file to write log messages to. The default
           is ``"pyspeos.log"``.

       **level** : :class:`python:int`, :obj:`optional`
           Level of logging. The default is ``10``, in which case the
           ``logging.DEBUG`` level is used.













   .. rubric:: Examples

   Write to the ``"pyspeos.log"`` file in the current working directory.

   >>> from ansys.speos.core import LOG
   >>> import os
   >>> file_path = os.path.join(os.getcwd(), "pyspeos.log")
   >>> LOG.log_to_file(file_path)

   ..
       !! processed by numpydoc !!

.. py:method:: log_to_stdout(level=LOG_LEVEL)

   
   Add the standard output handler to the logger.


   :Parameters:

       **level** : :class:`python:int`, :obj:`optional`
           Level of logging. The default is ``10``, in which case the
           ``logging.DEBUG`` level is used.














   ..
       !! processed by numpydoc !!

.. py:method:: setLevel(level='DEBUG')

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
















   ..
       !! processed by numpydoc !!

.. py:method:: add_child_logger(suffix, level = 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 speos 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:

       **suffix** : :class:`python:str`
           Name of the child logger.

       **level** : :class:`python:str`, :obj:`optional`
           Level of logging. The default is ``None``.



   :Returns:

       :obj:`logging.logger`
           Logger class.











   ..
       !! processed by numpydoc !!

.. py:method:: add_instance_logger(name, client_instance, level = None)

   
   Add a logger for a speos instance.

   The speos instance logger is a logger with an adapter that adds
   contextual information such as the speos 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:

       **name** : :class:`python:str`
           Name for the new instance logger.

       **client_instance** : :obj:`ansys.speos.core.kernel.client.SpeosClient`
           speos SpeosClient object, which should contain the ``get_name`` method.

       **level** : :class:`python:int`, :obj:`optional`
           Level of logging. The default is ``None``.



   :Returns:

       :obj:`PySpeosCustomAdapter`
           Logger adapter customized to add speos information to the
           logs. You can use this class to log events in the same
           way you would with the ``Logger`` class.











   ..
       !! processed by numpydoc !!

.. py:method:: __getitem__(key)

   
   Magic method to allow retrieval of instances.
















   ..
       !! processed by numpydoc !!

.. py:method:: add_handling_uncaught_expections(logger)

   
   Redirect the output of an exception to a logger.


   :Parameters:

       **logger** : :class:`python:str`
           Name of the logger.














   ..
       !! processed by numpydoc !!