The utils
module
- class magento.utils.ItemManager(items=None)[source]View on GitHub
Bases:
object
- __init__(items=None)[source]View on GitHub
- add(item)[source]View on GitHub
- get_attrs(attr)[source]View on GitHub
- sum_attrs(attr)[source]View on GitHub
- class magento.utils.LoggerUtils[source]View on GitHub
Bases:
object
Utility class that simplifies access to logger handler info
- static get_handler_names(logger)[source]View on GitHub
Get all handler names
- static get_stream_handlers(logger)[source]View on GitHub
Get all the StreamHandlers of the current logger (NOTE: StreamHandler subclasses excluded)
- static get_file_handlers(logger)[source]View on GitHub
Get all the FileHandlers of the current logger
- Return type
- static get_log_files(logger)[source]View on GitHub
Get the log file paths from all FileHandlers of a logger
- static get_handler_by_log_file(logger, log_file)[source]View on GitHub
Returns the FileHandler logging to the specified file, given it exists
- Return type
- static clear_handlers(logger)[source]View on GitHub
- Return type
- static clear_stream_handlers(logger)[source]View on GitHub
Removes all StreamHandlers from a logger
- Return type
- static clear_file_handlers(logger)[source]View on GitHub
Removes all FileHandlers from a logger
- Return type
- static map_handlers_by_name(logger)[source]View on GitHub
Map the handlers of a logger first by type, and then by their name
FileHandlers are mapped to both their handlers and log file, while StreamHandlers are just mapped to the handler Handlers without a name will be skipped, because look at the method name (:
- class magento.utils.MagentoLogger(name, log_file=None, stdout_level='INFO', log_requests=True)[source]View on GitHub
Bases:
object
Logging class used within the package
- Variables
PREFIX – hardcoded prefix to use in log messages
PACKAGE_LOG_NAME – the default name for the package logger
CLIENT_LOG_NAME – the default format for the client logger name
LOG_MESSAGE – the default format for the message component of log messages. (Use magento.logger.LOG_MESSAGE for easy access)
FORMATTER – the default logging format
HANDLER_NAME – the default format for the names of handlers created by this package
- PREFIX = 'MyMagento'
- PACKAGE_LOG_NAME = 'my-magento'
- CLIENT_LOG_NAME = '{domain}_{username}'
- HANDLER_NAME = 'MyMagento__{name}__{stdout_level}'
- LOG_MESSAGE = '|[ MyMagento | {name} ]|: {message}'
- FORMATTER = <logging.Formatter object>
- __init__(name, log_file=None, stdout_level='INFO', log_requests=True)[source]View on GitHub
Initialize the logger
Each Client object corresponds to a unique username/domain combination, which is used to attach it to its associated MagentoLogger and log file, allowing all activity across all endpoints to be tracked. A package logger exists as well, which logs all activity from the package. All log files have their log level set to DEBUG
- Parameters
- setup_logger(stdout_level='INFO', log_requests=True)[source]View on GitHub
Configures a logger and assigns it to the logger attribute.
- format_msg(msg)[source]View on GitHub
Formats the
LOG_MESSAGE
using the specified message- Return type
- debug(msg)[source]View on GitHub
Formats the
LOG_MESSAGE
with the specified message, then logs it with Logger.debug()
- info(msg)[source]View on GitHub
Formats the
LOG_MESSAGE
with the specified message, then logs it with Logger.info()
- error(msg)[source]View on GitHub
Formats the
LOG_MESSAGE
with the specified message, then logs it with Logger.error()
- warning(msg)[source]View on GitHub
Formats the
LOG_MESSAGE
with the specified message, then logs it with Logger.warning()
- critical(msg)[source]View on GitHub
Formats the
LOG_MESSAGE
with the specified message, then logs it with Logger.critical()
- property handlers
- property handler_names
- property handler_map
- property file_handlers
- property stream_handlers
- property log_files
- property log_path
- static get_magento_handlers(logger)[source]View on GitHub
- static clear_magento_handlers(logger, handler_type, clear_pkg=False)[source]View on GitHub
Clear all handlers from a logger that were created by MagentoLogger
- Parameters
logger (Logger) – any logger
handler_type (Union[Type[FileHandler], Type[StreamHandler]]) – the logging handler type to check for and remove
clear_pkg (bool) – if True, will delete the package handler for writing to my-magento.log (Default is False)
- static clear_magento_file_handlers(logger, clear_pkg=False)[source]View on GitHub
- static clear_magento_stdout_handlers(logger, clear_pkg=False)[source]View on GitHub
- static owns_handler(handler)[source]View on GitHub
Checks if a handler is a Stream/FileHandler from this package or not
- static get_package_handler()[source]View on GitHub
Returns the FileHandler object that writes to the magento.log file
- Return type
- static add_request_logging(handler)[source]View on GitHub
Adds the specified handler to the requests package logger, allowing for easier debugging of API calls
- magento.utils.get_agents()[source]View on GitHub
Scrapes a list of user agents. Returns a default list if the scrape fails.
- Return type
- magento.utils.get_agent(index=0)[source]View on GitHub
Returns a single user agent string from the specified index of the AGENTS list
- Return type
- magento.utils.get_package_file_handler()[source]View on GitHub