layup_logging
Classes
This logger configures the root-level logger for Layup to emit messages |
Module Contents
- class LayupLogger(log_directory='.')[source]
This logger configures the root-level logger for Layup to emit messages to potentially three locations 1) STDERR 2) layup-<datetime>.log and 3) layup-<datetime>.err depending on the log level. See the _prepare_logger method for details about which levels are sent to which handlers.
LayupLogger is intended to be used in one of two ways in general. Either instantiated within the execute() function in one of the layup_cmdline verbs or as a context manager when calling the API directly.
Example 1 - LayupLogger in a command line verb (See layup_cmdline/log.py for a working example) ``` def execute():
from layup.utilities.layup_logging import LayupLogger
layup_logger = LayupLogger()
# Create a child logger. NOTE - that the name starts with “layup.<blah>” # Failure to specify a name with that form could result in lost logs. logger = layup_logger.get_logger(“layup.log_cmdline”)
logger.info(“Sending a log message.”) # Use the logger
Example 2 - LayupLogger in a context manager This would likely be the usage within a Jupyter notebook ``` from layup.utilities.layup_logging import LayupLogger
- with LayupLogger() as layup_logger:
# Create a child logger. NOTE - that the name starts with “layup.<blah>” # Failure to specify a name with that form could result in lost logs. logger = layup_logger.get_logger(“layup.interactive”)
logger.info(“Sending a log message from a notebook.”)
- get_logger(name)[source]
Convenience function to return a logger under the top level logger. This is identical to calling logger = logging.getLogger(__name__)
- Parameters:
name (str) – The name to use when emitting messages using this logger.
- Returns:
The logger to use to emit message.
- Return type:
Logger
- __enter__()[source]
Entry point for using LayupLogger as a context manager
- Returns:
An instance of the LayupLogger object
- Return type:
self