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
name (str) β logger name
log_file (Optional[str]) β log file name; default is {name}.log
stdout_level (Union[int, str]) β logging level for stdout logger; default is βINFOβ (which is also logging.INFO and 10)
log_requests (bool) β set to True to add logging from the requests package logger
- 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ο