The logger.py
module#
Summary#
Keeps the reference to the PyAnsys Heart service instance dynamic. |
|
Ensures that the |
|
Provides the logger used for each PyAnsys Heart session. |
Add a file handler to the input. |
|
Add a stdout handler to the logger. |
Description#
Logging module.
The logging module supplies a general framework for logging in PyAnsys Heart.
This module is built on the Python logging
library. It does not intend to replace it but rather provide a way to interact between
the Python logging
library and PyAnsys Heart.
The loggers used in the module include the name of the instance, which is intended to be unique. This name is printed in all the active outputs and is used to track the different PyAnsys Heart modules.
Usage#
Global logger#
There is a global logger named PyAnsys Heart_global
that is created when
ansys.health.heart.__init__
is called. If you want to use this global logger,
you must call it at the top of your module:
from ansys.health.heart import LOG
You can rename this logger to avoid conflicts with other loggers (if any):
from ansys.health.heart import LOG as logger
The default logging level of LOG
is ERROR
.
You can change this level and output lower-level messages:
LOG.logger.setLevel("DEBUG")
LOG.file_handler.setLevel("DEBUG") # If present.
LOG.std_out_handler.setLevel("DEBUG") # If present.
Alternatively, you can ensure all the handlers are set to the input log level with this code:
LOG.setLevel("DEBUG")
This logger does not log to a file by default. If you want, you can add a file handler with this code:
import os
file_path = os.path.join(os.getcwd(), "pymapdl.log")
LOG.log_to_file(file_path)
This also sets the logger to be redirected to this file. If you want
to change the characteristics of this global logger from the beginning
of the execution, you must edit the file __init__
file in the
ansys.health.heart
directory.
To log using this logger, call the desired method as a normal logger:
>>> import logging
>>> from ansys.health.heart.logging import Logger
>>> LOG = Logger(level=logging.DEBUG, to_file=False, to_stdout=True)
>>> LOG.debug("This is LOG debug message.")
DEBUG - - - - This is LOG debug message.
Other loggers#
You can create your own loggers using the Python logging
library as
you would do in any other script. There would be no conflicts between
these loggers.
Module detail#
- logger.addfile_handler(logger, filename=FILE_NAME, level=LOG_LEVEL_STDOUT, write_headers=False)#
Add a file handler to the input.
- Parameters:
- logger
logging.Logger
Logger to add the file handler to.
- filename
str
, default:FILE_NAME
Name of the output file, which is
'pyconv-de.log'
by default.- level
int
, default: 10 Level of logging. The default is
10
, in which case thelogging.DEBUG
level is used.- write_headersbool, default:
False
Whether to write headers to the file.
- logger
- Returns:
Logger
Logger
orlogging.Logger
object.
- logger.add_stdout_handler(logger, level=LOG_LEVEL_STDOUT, write_headers=False)#
Add a stdout handler to the logger.
- Parameters:
- logger
logging.Logger
Logger to add the stdout handler to.
- level
int
, default:10
Level of logging. The default is
10
, in which case thelogging.DEBUG
level is used.- write_headersbool, default:
False
Whether to write headers to the file.
- logger
- Returns:
Logger
Logger
orlogging.Logger
object.
- logger.LOG_LEVEL_STDOUT = 20#
- logger.LOG_LEVEL_FILE = 10#
- logger.FILE_NAME = 'PyAnsys Heart.log'#
- logger.DEBUG = 10#
- logger.INFO = 20#
- logger.WARN = 30#
- logger.ERROR = 40#
- logger.CRITICAL = 50#
- logger.STDOUT_MSG_FORMAT = '%(asctime)s - %(levelname)s - %(instance_name)s - %(module)s - %(funcName)s - %(message)s'#
- logger.DATEFORMAT = '%Y/%m/%d %H:%M:%S'#
- logger.FILE_MSG_FORMAT = '%(asctime)s - %(levelname)s - %(instance_name)s - %(module)s - %(funcName)s - %(message)s'#
- logger.DEFAULT_STDOUT_HEADER = Multiline-String#
Show Value
""" LEVEL - INSTANCE NAME - MODULE - FUNCTION - MESSAGE """
- logger.DEFAULT_FILE_HEADER = Multiline-String#
Show Value
""" LEVEL - INSTANCE NAME - MODULE - FUNCTION - MESSAGE """
- logger.NEW_SESSION_HEADER = Multiline-String#
Show Value
""" =============================================================================== NEW SESSION - Uninferable ==============================================================================="""
- logger.LOG_LEVEL_STRING_TYPE#
- logger.LOG_LEVEL_TYPE#