mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 03:30:01 +08:00
change: remove dependency colorama and colorlog
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
- replace logging with [loguru](https://github.com/Delgan/loguru)
|
- replace logging with [loguru](https://github.com/Delgan/loguru)
|
||||||
- remove support for Python 2.7
|
- remove support for Python 2.7
|
||||||
- replace string format with f-string
|
- replace string format with f-string
|
||||||
|
- remove dependency colorama and colorlog
|
||||||
|
|
||||||
## 2.5.7 (2020-02-21)
|
## 2.5.7 (2020-02-21)
|
||||||
|
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
import logging
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from colorama import Fore, init
|
|
||||||
from colorlog import ColoredFormatter
|
|
||||||
|
|
||||||
init(autoreset=True)
|
|
||||||
|
|
||||||
LOG_LEVEL = "INFO"
|
|
||||||
LOG_FILE_PATH = ""
|
|
||||||
|
|
||||||
log_colors_config = {
|
|
||||||
'DEBUG': 'cyan',
|
|
||||||
'INFO': 'green',
|
|
||||||
'WARNING': 'yellow',
|
|
||||||
'ERROR': 'red',
|
|
||||||
'CRITICAL': 'red',
|
|
||||||
}
|
|
||||||
loggers = {}
|
|
||||||
|
|
||||||
|
|
||||||
def setup_logger(log_level, log_file=None):
|
|
||||||
global LOG_LEVEL
|
|
||||||
LOG_LEVEL = log_level
|
|
||||||
|
|
||||||
if log_file:
|
|
||||||
global LOG_FILE_PATH
|
|
||||||
LOG_FILE_PATH = log_file
|
|
||||||
|
|
||||||
|
|
||||||
def get_logger(name=None):
|
|
||||||
"""setup logger with ColoredFormatter."""
|
|
||||||
name = name or "httprunner"
|
|
||||||
logger_key = "".join([name, LOG_LEVEL, LOG_FILE_PATH])
|
|
||||||
if logger_key in loggers:
|
|
||||||
return loggers[logger_key]
|
|
||||||
|
|
||||||
_logger = logging.getLogger(name)
|
|
||||||
|
|
||||||
log_level = LOG_LEVEL
|
|
||||||
level = getattr(logging, log_level.upper(), None)
|
|
||||||
if not level:
|
|
||||||
color_print("Invalid log level: %s" % log_level, "RED")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# hide traceback when log level is INFO/WARNING/ERROR/CRITICAL
|
|
||||||
if level >= logging.INFO:
|
|
||||||
sys.tracebacklimit = 0
|
|
||||||
|
|
||||||
_logger.setLevel(level)
|
|
||||||
if LOG_FILE_PATH:
|
|
||||||
log_dir = os.path.dirname(LOG_FILE_PATH)
|
|
||||||
if not os.path.isdir(log_dir):
|
|
||||||
os.makedirs(log_dir)
|
|
||||||
handler = logging.FileHandler(LOG_FILE_PATH, encoding="utf-8")
|
|
||||||
else:
|
|
||||||
handler = logging.StreamHandler(sys.stdout)
|
|
||||||
|
|
||||||
formatter = ColoredFormatter(
|
|
||||||
u"%(log_color)s%(bg_white)s%(levelname)-8s%(reset)s %(message)s",
|
|
||||||
datefmt=None,
|
|
||||||
reset=True,
|
|
||||||
log_colors=log_colors_config
|
|
||||||
)
|
|
||||||
handler.setFormatter(formatter)
|
|
||||||
_logger.addHandler(handler)
|
|
||||||
|
|
||||||
loggers[logger_key] = _logger
|
|
||||||
return _logger
|
|
||||||
|
|
||||||
|
|
||||||
def coloring(text, color="WHITE"):
|
|
||||||
fore_color = getattr(Fore, color.upper())
|
|
||||||
return fore_color + text
|
|
||||||
|
|
||||||
|
|
||||||
def color_print(msg, color="WHITE"):
|
|
||||||
fore_color = getattr(Fore, color.upper())
|
|
||||||
print(fore_color + msg)
|
|
||||||
|
|
||||||
|
|
||||||
def log_with_color(level):
|
|
||||||
""" log with color by different level
|
|
||||||
"""
|
|
||||||
def wrapper(text):
|
|
||||||
color = log_colors_config[level.upper()]
|
|
||||||
_logger = get_logger()
|
|
||||||
getattr(_logger, level.lower())(coloring(text, color))
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
|
|
||||||
log_debug = log_with_color("debug")
|
|
||||||
log_info = log_with_color("info")
|
|
||||||
log_warning = log_with_color("warning")
|
|
||||||
log_error = log_with_color("error")
|
|
||||||
log_critical = log_with_color("critical")
|
|
||||||
Generated
+2
-16
@@ -53,22 +53,12 @@ version = "7.0"
|
|||||||
[[package]]
|
[[package]]
|
||||||
category = "main"
|
category = "main"
|
||||||
description = "Cross-platform colored terminal text."
|
description = "Cross-platform colored terminal text."
|
||||||
|
marker = "sys_platform == \"win32\""
|
||||||
name = "colorama"
|
name = "colorama"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
category = "main"
|
|
||||||
description = "Log formatting with colors!"
|
|
||||||
name = "colorlog"
|
|
||||||
optional = false
|
|
||||||
python-versions = "*"
|
|
||||||
version = "4.0.2"
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
colorama = "*"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
category = "main"
|
category = "main"
|
||||||
description = "PEP 567 Backport"
|
description = "PEP 567 Backport"
|
||||||
@@ -491,7 +481,7 @@ docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"]
|
|||||||
testing = ["pathlib2", "contextlib2", "unittest2"]
|
testing = ["pathlib2", "contextlib2", "unittest2"]
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
content-hash = "de60904b4e9b6fc9ac23540a8ba8b743463603d9a2c5be99e9c521d5e4f8b541"
|
content-hash = "57ff78f24ca37a3421d5c64007bd71eba394d6751fdbb2d0b446f523cfed9c62"
|
||||||
python-versions = "^3.6"
|
python-versions = "^3.6"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
@@ -519,10 +509,6 @@ colorama = [
|
|||||||
{file = "colorama-0.4.3-py2.py3-none-any.whl", hash = "sha256:7d73d2a99753107a36ac6b455ee49046802e59d9d076ef8e47b61499fa29afff"},
|
{file = "colorama-0.4.3-py2.py3-none-any.whl", hash = "sha256:7d73d2a99753107a36ac6b455ee49046802e59d9d076ef8e47b61499fa29afff"},
|
||||||
{file = "colorama-0.4.3.tar.gz", hash = "sha256:e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1"},
|
{file = "colorama-0.4.3.tar.gz", hash = "sha256:e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1"},
|
||||||
]
|
]
|
||||||
colorlog = [
|
|
||||||
{file = "colorlog-4.0.2-py2.py3-none-any.whl", hash = "sha256:450f52ea2a2b6ebb308f034ea9a9b15cea51e65650593dca1da3eb792e4e4981"},
|
|
||||||
{file = "colorlog-4.0.2.tar.gz", hash = "sha256:3cf31b25cbc8f86ec01fef582ef3b840950dea414084ed19ab922c8b493f9b42"},
|
|
||||||
]
|
|
||||||
contextvars = [
|
contextvars = [
|
||||||
{file = "contextvars-2.4.tar.gz", hash = "sha256:f38c908aaa59c14335eeea12abea5f443646216c4e29380d7bf34d2018e2c39e"},
|
{file = "contextvars-2.4.tar.gz", hash = "sha256:f38c908aaa59c14335eeea12abea5f443646216c4e29380d7bf34d2018e2c39e"},
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ requests-toolbelt = "^0.9.1"
|
|||||||
pyyaml = "^5.1.2"
|
pyyaml = "^5.1.2"
|
||||||
jinja2 = "^2.10.3"
|
jinja2 = "^2.10.3"
|
||||||
har2case = "^0.3.1"
|
har2case = "^0.3.1"
|
||||||
colorama = "^0.4.1"
|
|
||||||
colorlog = "^4.0.2"
|
|
||||||
filetype = "^1.0.5"
|
filetype = "^1.0.5"
|
||||||
jsonpath = "^0.82"
|
jsonpath = "^0.82"
|
||||||
sentry-sdk = "^0.13.5"
|
sentry-sdk = "^0.13.5"
|
||||||
|
|||||||
Reference in New Issue
Block a user