summaryrefslogtreecommitdiff
path: root/tests
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 /tests
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 'tests')
-rw-r--r--tests/config_files/dummy_logging.py19
-rw-r--r--tests/test_cli.py5
2 files changed, 24 insertions, 0 deletions
diff --git a/tests/config_files/dummy_logging.py b/tests/config_files/dummy_logging.py
new file mode 100644
index 0000000..e84af64
--- /dev/null
+++ b/tests/config_files/dummy_logging.py
@@ -0,0 +1,19 @@
+# example config taken from <https://stackoverflow.com/a/7507842/784804>
+DICT_CONFIG = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'formatters': {
+ 'standard': {'format': 'MY_LOG_FMT: %(asctime)s [%(levelname)s] %(name)s: %(message)s'},
+ },
+ 'handlers': {
+ 'default': {
+ 'level': 'DEBUG',
+ 'formatter': 'standard',
+ 'class': 'logging.StreamHandler',
+ 'stream': 'ext://sys.stdout', # Default is stderr
+ },
+ },
+ 'loggers': {
+ 'root': {'handlers': ['default'], 'level': 'DEBUG', 'propagate': False}, # root logger
+ },
+}
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 1767a3e..874eace 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -67,6 +67,11 @@ class TestRQCli(CLITestCase):
self.assertIn('REDIS_HOST', settings)
self.assertEqual(settings['REDIS_HOST'], 'testhost.example.com')
+ def test_config_file_logging(self):
+ runner = CliRunner()
+ result = runner.invoke(main, ['worker', '-u', self.redis_url, '-b', '-c', 'tests.config_files.dummy_logging'])
+ self.assert_normal_execution(result)
+
def test_config_file_option(self):
""""""
cli_config = CliConfig(config='tests.config_files.dummy')