summaryrefslogtreecommitdiff
path: root/rq/cli/cli.py
diff options
context:
space:
mode:
authorjuur <juur@users.noreply.github.com>2023-05-18 01:04:57 +0100
committerGitHub <noreply@github.com>2023-05-18 07:04:57 +0700
commit107221fd9ef1db5eca0d55459a318ad65dd253f5 (patch)
tree7f77e992d3773a704aa0a06cff9f467f6659b790 /rq/cli/cli.py
parentbdbc9a4f9ca79727316f7e41473981593773e34c (diff)
downloadrq-master.tar.gz
Update cli.py to support custom loggers (#1906)HEADmaster
* Update cli.py to support custom loggers Allows a config.py file (via rq worker --config) to support things like this for logfmt logging: DICT_CONFIG = { "version": 1, "formatters": {"logfmt": { "()": "logfmter.Logfmter", "keys": ["level","when","pid"], "mapping": {"level":"levelname","when":"asctime","pid":"process"}, "datefmt": "%Y-%m-%dT%H:%M:%S%z" }}, "handlers": {"console": {"class": "logging.StreamHandler","formatter": "logfmt" }}, "loggers": { "root": {"handlers":["console"], "level": "INFO"}, "rq": {"handlers":["console"], "level": "INFO", "propagate": False}, } } * added simple test and documentation for DICT_CONFIG * further attempt to get testing right for dictConfig * move import to correct location * fix * remove meaningless options.get() usage * linting checks and added missing test config file
Diffstat (limited to 'rq/cli/cli.py')
-rwxr-xr-xrq/cli/cli.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/rq/cli/cli.py b/rq/cli/cli.py
index eb18293..7f8b6d0 100755
--- a/rq/cli/cli.py
+++ b/rq/cli/cli.py
@@ -2,6 +2,8 @@
RQ command line tool
"""
+import logging
+import logging.config
import os
import sys
import warnings
@@ -229,6 +231,10 @@ def worker(
sentry_debug = sentry_debug or settings.get('SENTRY_DEBUG')
sentry_dsn = sentry_dsn or settings.get('SENTRY_DSN')
name = name or settings.get('NAME')
+ dict_config = settings.get('DICT_CONFIG')
+
+ if dict_config:
+ logging.config.dictConfig(dict_config)
if pid:
with open(os.path.expanduser(pid), "w") as fp:
@@ -303,7 +309,7 @@ def worker(
dequeue_strategy=dequeue_strategy,
)
except ConnectionError as e:
- print(e)
+ logging.error(e)
sys.exit(1)