# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. # A copy of the License is located at # # http://www.apache.org/licenses/LICENSE-2.0 # # or in the "license" file accompanying this file. This file is distributed # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either # express or implied. See the License for the specific language governing # permissions and limitations under the License. from __future__ import absolute_import import logging import stepfunctions def append_user_agent_to_client(boto_client): user_agent_suffix = str.format(" {package_useragent}/{package_version}", package_useragent=stepfunctions.__useragent__, package_version=stepfunctions.__version__) if user_agent_suffix not in boto_client._client_config.user_agent: boto_client._client_config.user_agent += user_agent_suffix class CustomColorFormatter(logging.Formatter): GREY = "\x1b[0m" GREEN = "\x1b[32m" YELLOW = "\x1b[33m" RED = "\x1b[31m" BOLD_RED = "\x1b[31;1m" RESET = "\x1b[0m" FORMAT = "[%(levelname)s] %(message)s" LEVEL_FORMATS = { logging.DEBUG: GREY + FORMAT + RESET, logging.INFO: GREEN + FORMAT + RESET, logging.WARNING: YELLOW + FORMAT + RESET, logging.ERROR: RED + FORMAT + RESET, logging.CRITICAL: BOLD_RED + FORMAT + RESET } def format(self, record): log_fmt = self.LEVEL_FORMATS.get(record.levelno) formatter = logging.Formatter(log_fmt) return formatter.format(record)