Add option to load logging conf from JSON file

New option `--logging-conf-file` to load `logging` conf from a JSON
file.

Prefer JSON over the `configparser` format supported by
`logging.config.fileConfig` because JSON format is much better (nesting
is supported) and its easier to detect errors.
This commit is contained in:
Vangelis Banos 2019-03-20 11:53:32 +00:00
parent c70bf2e2b9
commit 6e6b43eb79

View File

@ -29,7 +29,9 @@ try:
except ImportError:
import Queue as queue
import json
import logging
import logging.config
import sys
import hashlib
import argparse
@ -239,6 +241,9 @@ def _build_arg_parser(prog='warcprox', show_hidden=False):
arg_parser.add_argument(
'--trace', dest='trace', action='store_true',
help='very verbose logging')
arg_parser.add_argument(
'--logging-conf-file', dest='logging_conf_file', default=None,
help=('reads logging configuration from a JSON file'))
arg_parser.add_argument(
'--version', action='version',
version="warcprox {}".format(warcprox.__version__))
@ -302,6 +307,11 @@ def main(argv=None):
'%(asctime)s %(process)d %(levelname)s %(threadName)s '
'%(name)s.%(funcName)s(%(filename)s:%(lineno)d) %(message)s'))
if args.logging_conf_file:
with open(args.logging_conf_file, 'r') as fd:
conf = json.load(fd)
logging.config.dictConfig(conf)
# see https://github.com/pyca/cryptography/issues/2911
cryptography.hazmat.backends.openssl.backend.activate_builtin_random()