The logger.py
module#
Summary#
Provides a common messaging style for the |
|
Provides a |
|
Provides the logger used for each PyAdditive session. |
Check if the code is running in a Jupyter notebook. |
|
Add a file handler to the input. |
|
Add a standout handler to the logger. |
Description#
Provides a general framework for logging in PyAdditive.
Logger usage#
Global logger#
There is a global logger named PyAdditive_global
that is created when
ansys.additive.core.__init__
is called. If you want to use this global
logger, you must call it at the top of your module:
from ansys.additive.core import LOG
You can rename this logger to avoid conflicts with other loggers (if any):
from ansys.additive.core import LOG as logger
The default logging level of LOG
is WARNING
.
You can change this level and output lower-level messages with
this code:
LOG.logger.setLevel("DEBUG")
LOG.file_handler.setLevel("DEBUG") # If present.
LOG.stdout_handler.setLevel("DEBUG") # If present.
Alternatively, you can ensure that 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(), "pyadditive.log")
LOG.log_to_file(file_path)
Module detail#
- logger.is_notebook() bool #
Check if the code is running in a Jupyter notebook.
- Returns:
bool: True if running in a Jupyter notebook, False otherwise.
- logger.addfile_handler(logger, filename=FILE_NAME, level=LOG_LEVEL)#
Add a file handler to the input.
- Parameters:
- logger
logging.Logger
Logger to add the file handler to.
- filenamestr, default: obj:FILE_NAME
Name of the output file.
- level
default
DEBUG
Logging level to filter the message severity allowed in the logger.
- logger
- Returns:
Logger
Logger
orlogging.Logger
object.
- logger.add_stdout_handler(logger, level=LOG_LEVEL)#
Add a standout handler to the logger.
- Parameters:
- logger
logging.Logger
Logger to add the file handler to.
- level
default
DEBUG
Logging level to filter the message severity allowed in the logger.
- logger
- Returns:
Logger
Logger
orlogging.Logger
object.
- logger.LOG_LEVEL#
- logger.FILE_NAME = 'pyadditive.log'#
- logger.STDOUT_MSG_FORMAT = '%(asctime)s - %(levelname)s - %(module)s - %(funcName)s - %(message)s'#
- logger.FILE_MSG_FORMAT#
- logger.DATE_FORMAT = '%Y-%m-%d %H:%M:%S'#
- logger.LOG#