The logger.py
module#
Summary#
Provides a common messaging style for the |
|
Provides a |
|
Provides the logger used for each PyAdditive session. |
|
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#
- class logger.PyAdditivePercentStyle(fmt, *, defaults=None)#
Bases:
logging.PercentStyle
Provides a common messaging style for the
PyAdditiveFormatter
class.
Import detail#
from ansys.additive.core.logger import PyAdditivePercentStyle
- class logger.PyAdditiveFormatter(fmt=STDOUT_MSG_FORMAT, datefmt=None, style='%', validate=True, defaults=None)#
Bases:
logging.Formatter
Provides a
Formatter
class for overwriting default format styles.
Import detail#
from ansys.additive.core.logger import PyAdditiveFormatter
- class logger.Logger(level=logging.DEBUG, to_file=False, to_stdout=True, filename=FILE_NAME)#
Provides the logger used for each PyAdditive session.
This class allows you to add handlers to the logger to output messages to a file or to the standard output (stdout).
- Parameters:
- level
default
DEBUG
Logging level to filter the message severity allowed in the logger.
- to_filebool, default:
False
Whether to write log messages to a file.
- to_stdoutbool, default:
True
Whether to write log messages to the standard output.
- filenamestr, default: obj:FILE_NAME
Name of the file to write log log messages to.
- level
Overview#
Add a file handler to the logger. |
|
Add the standard output handler to the logger. |
|
Redirect the output of an exception to a logger. |
Import detail#
from ansys.additive.core.logger import Logger
Attribute detail#
- Logger.file_handler#
- Logger.std_out_handler#
Method detail#
- Logger.log_to_file(filename=FILE_NAME, level=LOG_LEVEL)#
Add a file handler to the logger.
- Parameters:
- filenamestr, default: obj:FILE_NAME
Name of the file to write log messages to.
- level
default
DEBUG
Logging level to filter the message severity allowed in the logger.
- Logger.log_to_stdout(level=LOG_LEVEL)#
Add the standard output handler to the logger.
- Parameters:
- level
default
DEBUG
Logging level to filter the message severity allowed in the logger.
- level
- Logger.add_handling_uncaught_expections(logger)#
Redirect the output of an exception to a logger.
- Parameters:
- logger
str
Name of the logger.
- logger
- 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.LOG#