Open oguizol opened 2 years ago
I ran into this following error during the test stage. Found its due to not using the % format style which this PR would fix
======================================================================
ERROR: testSignalHandling (tests.test_cli.TestCLI)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.8/unittest/mock.py", line 1325, in patched
return func(*newargs, **newkeywargs)
File "/home/ryant/prometheus-pgbouncer-exporter/.pybuild/cpython3_3.8_prometheus-pgbouncer-exporter/build/tests/test_cli.py", line 89, in testSignalHandling
cli.main()
File "/home/ryant/prometheus-pgbouncer-exporter/.pybuild/cpython3_3.8_prometheus-pgbouncer-exporter/build/prometheus_pgbouncer_exporter/cli.py", line 47, in main
formatter = jsonlogger.JsonFormatter("(asctime) (levelname) (message)", datefmt="%Y-%m-%d %H:%M:%S")
File "/usr/lib/python3/dist-packages/pythonjsonlogger/jsonlogger.py", line 112, in __init__
logging.Formatter.__init__(self, *args, **kwargs)
File "/usr/lib/python3.8/logging/__init__.py", line 580, in __init__
self._style.validate()
File "/usr/lib/python3.8/logging/__init__.py", line 433, in validate
raise ValueError("Invalid format '%s' for '%s' style" % (self._fmt, self.default_format[0]))
ValueError: Invalid format '(asctime) (levelname) (message)' for '%' style
----------------------------------------------------------------------
Ran 32 tests in 0.020s
FAILED (errors=1)
E: pybuild pybuild:341: test: plugin distutils failed with: exit code=1: cd /home/ryant/prometheus-pgbouncer-exporter/.pybuild/cpython3_3.8_prometheus-pgbouncer-exporter/build; python3.8 -m unittest discover -v
dh_auto_test: error: pybuild --test -i python{version} -p 3.8 returned exit code 13
make: *** [debian/rules:7: build] Error 13
dpkg-buildpackage: error: debian/rules build subprocess returned exit status 2
I also found related info for this issue here:
Tested using the % format style:
ryant@pop-os:~ ➜ cat test.py
#!/usr/bin/env python3
import logging
from pythonjsonlogger import jsonlogger
logger = logging.getLogger()
logHandler = logging.StreamHandler()
formatter = jsonlogger.JsonFormatter("%(asctime)s %(levelname)s %(message)s")
logHandler.setFormatter(formatter)
logger.handlers = [logHandler]
logger.setLevel(logging.INFO)
logger.info("Hello world")
ryant@pop-os:~ ➜ ./test.py
{"asctime": "2022-05-14 21:39:12,363", "levelname": "INFO", "message": "Hello world"}
ryant@pop-os:~ ➜
Solves the same issue that this PR but in a different manner