aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Sebastiaan Zeeff <[email protected]>2020-03-01 14:53:10 +0100
committerGravatar Sebastiaan Zeeff <[email protected]>2020-03-01 14:53:10 +0100
commit0b106f08f364d7a20b9fc30f9558cfce94c02377 (patch)
treea1a7ef07c5c94c1fcca49262b03b55188efb62c8
parentMigrate snekbox tests to Python 3.8's unittest (diff)
parentMerge pull request #806 from python-discord/feat/frontend/b000/coloured-logs (diff)
Merge branch 'master' into python38-migration
I have resolved a merge conflict in Pipfile.lock by relocking with the newly added dependencies of `coloredlogs` and `colorama`.
-rw-r--r--Pipfile2
-rw-r--r--Pipfile.lock68
-rw-r--r--bot/__init__.py30
3 files changed, 71 insertions, 29 deletions
diff --git a/Pipfile b/Pipfile
index e08b5b41d..9ac32886a 100644
--- a/Pipfile
+++ b/Pipfile
@@ -19,6 +19,8 @@ requests = "~=2.22"
more_itertools = "~=7.2"
urllib3 = ">=1.24.2,<1.25"
sentry-sdk = "~=0.14"
+coloredlogs = "~=14.0"
+colorama = {version = "~=0.4.3", sys_platform = "== 'win32'"}
[dev-packages]
coverage = "~=4.5"
diff --git a/Pipfile.lock b/Pipfile.lock
index 7c11f1860..91d7d5430 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
- "sha256": "513182efe8c06f5d8acb494ebdfb8670cd68f426fd87085778421872c2c3acc8"
+ "sha256": "1128d3fc064359337cba08ddf7236982c09f714ca148861a22c4ef623e728c49"
},
"pipfile-spec": 6,
"requires": {
@@ -140,6 +140,23 @@
],
"version": "==3.0.4"
},
+ "colorama": {
+ "hashes": [
+ "sha256:7d73d2a99753107a36ac6b455ee49046802e59d9d076ef8e47b61499fa29afff",
+ "sha256:e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1"
+ ],
+ "index": "pypi",
+ "markers": "sys_platform == 'win32'",
+ "version": "==0.4.3"
+ },
+ "coloredlogs": {
+ "hashes": [
+ "sha256:346f58aad6afd48444c2468618623638dadab76e4e70d5e10822676f2d32226a",
+ "sha256:a1fab193d2053aa6c0a97608c4342d031f1f93a3d1218432c59322441d31a505"
+ ],
+ "index": "pypi",
+ "version": "==14.0"
+ },
"deepdiff": {
"hashes": [
"sha256:b3fa588d1eac7fa318ec1fb4f2004568e04cb120a1989feda8e5e7164bcbf07a",
@@ -170,6 +187,13 @@
"index": "pypi",
"version": "==0.18.0"
},
+ "humanfriendly": {
+ "hashes": [
+ "sha256:5e5c2b82fb58dcea413b48ab2a7381baa5e246d47fe94241d7d83724c11c0565",
+ "sha256:a9a41074c24dc5d6486e8784dc8f057fec8b963217e941c25fb7c7c383a4a1c1"
+ ],
+ "version": "==7.1.1"
+ },
"idna": {
"hashes": [
"sha256:7588d1c14ae4c77d74036e8c22ff447b26d0fde8f007354fd48a7814db15b7cb",
@@ -415,11 +439,11 @@
},
"sentry-sdk": {
"hashes": [
- "sha256:b06dd27391fd11fb32f84fe054e6a64736c469514a718a99fb5ce1dff95d6b28",
- "sha256:e023da07cfbead3868e1e2ba994160517885a32dfd994fc455b118e37989479b"
+ "sha256:480eee754e60bcae983787a9a13bc8f155a111aef199afaa4f289d6a76aa622a",
+ "sha256:a920387dc3ee252a66679d0afecd34479fb6fc52c2bc20763793ed69e5b0dcc0"
],
"index": "pypi",
- "version": "==0.14.1"
+ "version": "==0.14.2"
},
"six": {
"hashes": [
@@ -452,17 +476,17 @@
},
"sphinxcontrib-applehelp": {
"hashes": [
- "sha256:edaa0ab2b2bc74403149cb0209d6775c96de797dfd5b5e2a71981309efab3897",
- "sha256:fb8dee85af95e5c30c91f10e7eb3c8967308518e0f7488a2828ef7bc191d0d5d"
+ "sha256:806111e5e962be97c29ec4c1e7fe277bfd19e9652fb1a4392105b43e01af885a",
+ "sha256:a072735ec80e7675e3f432fcae8610ecf509c5f1869d17e2eecff44389cdbc58"
],
- "version": "==1.0.1"
+ "version": "==1.0.2"
},
"sphinxcontrib-devhelp": {
"hashes": [
- "sha256:6c64b077937330a9128a4da74586e8c2130262f014689b4b89e2d08ee7294a34",
- "sha256:9512ecb00a2b0821a146736b39f7aeb90759834b07e81e8cc23a9c70bacb9981"
+ "sha256:8165223f9a335cc1af7ffe1ed31d2871f325254c0423bc0c4c7cd1c1e4734a2e",
+ "sha256:ff7f1afa7b9642e7060379360a67e9c41e8f3121f2ce9164266f61b9f4b338e4"
],
- "version": "==1.0.1"
+ "version": "==1.0.2"
},
"sphinxcontrib-htmlhelp": {
"hashes": [
@@ -480,17 +504,17 @@
},
"sphinxcontrib-qthelp": {
"hashes": [
- "sha256:513049b93031beb1f57d4daea74068a4feb77aa5630f856fcff2e50de14e9a20",
- "sha256:79465ce11ae5694ff165becda529a600c754f4bc459778778c7017374d4d406f"
+ "sha256:4c33767ee058b70dba89a6fc5c1892c0d57a54be67ddd3e7875a18d14cba5a72",
+ "sha256:bd9fc24bcb748a8d51fd4ecaade681350aa63009a347a8c14e637895444dfab6"
],
- "version": "==1.0.2"
+ "version": "==1.0.3"
},
"sphinxcontrib-serializinghtml": {
"hashes": [
- "sha256:c0efb33f8052c04fd7a26c0a07f1678e8512e0faec19f4aa8f2473a8b81d5227",
- "sha256:db6615af393650bf1151a6cd39120c29abaf93cc60db8c48eb2dddbfdc3a9768"
+ "sha256:eaa0eccc86e982a9b939b2b82d12cc5d013385ba5eadcc7e4fed23f4405f77bc",
+ "sha256:f242a81d423f59617a8e5cf16f5d4d74e28ee9a66f9e5b637a18082991db5a9a"
],
- "version": "==1.1.3"
+ "version": "==1.1.4"
},
"urllib3": {
"hashes": [
@@ -581,10 +605,10 @@
},
"cfgv": {
"hashes": [
- "sha256:04b093b14ddf9fd4d17c53ebfd55582d27b76ed30050193c14e560770c5360eb",
- "sha256:f22b426ed59cd2ab2b54ff96608d846c33dfb8766a67f0b4a6ce130ce244414f"
+ "sha256:1ccf53320421aeeb915275a196e23b3b8ae87dea8ac6698b1638001d4a486d53",
+ "sha256:c8e8f552ffcc6194f4e18dd4f68d9aef0c0d58ae7e7be8c82bee3c5e9edfa513"
],
- "version": "==3.0.0"
+ "version": "==3.1.0"
},
"chardet": {
"hashes": [
@@ -878,10 +902,10 @@
},
"virtualenv": {
"hashes": [
- "sha256:531b142e300d405bb9faedad4adbeb82b4098b918e35209af2adef3129274aae",
- "sha256:5dd42a9f56307542bddc446cfd10ef6576f11910366a07609fe8d0d88fa8fb7e"
+ "sha256:30ea90b21dabd11da5f509710ad3be2ae47d40ccbc717dfdd2efe4367c10f598",
+ "sha256:4a36a96d785428278edd389d9c36d763c5755844beb7509279194647b1ef47f1"
],
- "version": "==20.0.5"
+ "version": "==20.0.7"
}
}
}
diff --git a/bot/__init__.py b/bot/__init__.py
index f7a410706..c9dbc3f40 100644
--- a/bot/__init__.py
+++ b/bot/__init__.py
@@ -1,9 +1,11 @@
import logging
import os
import sys
-from logging import Logger, StreamHandler, handlers
+from logging import Logger, handlers
from pathlib import Path
+import coloredlogs
+
TRACE_LEVEL = logging.TRACE = 5
logging.addLevelName(TRACE_LEVEL, "TRACE")
@@ -25,10 +27,9 @@ Logger.trace = monkeypatch_trace
DEBUG_MODE = 'local' in os.environ.get("SITE_URL", "local")
-log_format = logging.Formatter("%(asctime)s | %(name)s | %(levelname)s | %(message)s")
-
-stream_handler = StreamHandler(stream=sys.stdout)
-stream_handler.setFormatter(log_format)
+log_level = TRACE_LEVEL if DEBUG_MODE else logging.INFO
+format_string = "%(asctime)s | %(name)s | %(levelname)s | %(message)s"
+log_format = logging.Formatter(format_string)
log_file = Path("logs", "bot.log")
log_file.parent.mkdir(exist_ok=True)
@@ -36,10 +37,25 @@ file_handler = handlers.RotatingFileHandler(log_file, maxBytes=5242880, backupCo
file_handler.setFormatter(log_format)
root_log = logging.getLogger()
-root_log.setLevel(TRACE_LEVEL if DEBUG_MODE else logging.INFO)
-root_log.addHandler(stream_handler)
+root_log.setLevel(log_level)
root_log.addHandler(file_handler)
+if "COLOREDLOGS_LEVEL_STYLES" not in os.environ:
+ coloredlogs.DEFAULT_LEVEL_STYLES = {
+ **coloredlogs.DEFAULT_LEVEL_STYLES,
+ "trace": {"color": 246},
+ "critical": {"background": "red"},
+ "debug": coloredlogs.DEFAULT_LEVEL_STYLES["info"]
+ }
+
+if "COLOREDLOGS_LOG_FORMAT" not in os.environ:
+ coloredlogs.DEFAULT_LOG_FORMAT = format_string
+
+if "COLOREDLOGS_LOG_LEVEL" not in os.environ:
+ coloredlogs.DEFAULT_LOG_LEVEL = log_level
+
+coloredlogs.install(logger=root_log, stream=sys.stdout)
+
logging.getLogger("discord").setLevel(logging.WARNING)
logging.getLogger("websockets").setLevel(logging.WARNING)
logging.getLogger(__name__)