Browse Source

Merge pull request #945 from octodns/quiet-cmd-line

--quiet and --logging-config cmd line options
pull/947/head
Ross McFarland 3 years ago
committed by GitHub
parent
commit
e9c413e51e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 7 deletions
  1. +30
    -4
      octodns/cmds/args.py
  2. +4
    -3
      octodns/manager.py
  3. +1
    -0
      octodns/provider/plan.py

+ 30
- 4
octodns/cmds/args.py View File

@ -3,9 +3,11 @@
#
from argparse import ArgumentParser as _Base
from logging import DEBUG, INFO, WARN, Formatter, StreamHandler, getLogger
from logging import DEBUG, INFO, WARNING, Formatter, StreamHandler, getLogger
from logging.config import dictConfig
from logging.handlers import SysLogHandler
from sys import stderr, stdout
from yaml import safe_load
from octodns import __VERSION__
@ -50,11 +52,27 @@ class ArgumentParser(_Base):
'--debug', action='store_true', default=False, help=_help
)
_help = 'Decrease verbosity to show only warnings, errors, and the plan'
self.add_argument(
'--quiet', action='store_true', default=False, help=_help
)
_help = 'Configure logging with a YAML file, see https://docs.python.org/3/library/logging.config.html#logging-config-dictschema for schema details'
self.add_argument('--logging-config', default=False, help=_help)
args = super().parse_args()
self._setup_logging(args, default_log_level)
return args
def _setup_logging(self, args, default_log_level):
if args.logging_config:
with open(args.logging_config) as fh:
config = safe_load(fh.read())
dictConfig(config)
# if we're provided a logging_config we won't do any of our normal
# configuration
return
fmt = '%(asctime)s [%(thread)d] %(levelname)-5s %(name)s %(message)s'
formatter = Formatter(fmt=fmt, datefmt='%Y-%m-%dT%H:%M:%S ')
stream = stdout if args.log_stream_stdout else stderr
@ -74,9 +92,17 @@ class ArgumentParser(_Base):
handler.setFormatter(Formatter(fmt=fmt))
logger.addHandler(handler)
logger.level = DEBUG if args.debug else default_log_level
logger.level = default_log_level
if args.debug:
logger.level = DEBUG
elif args.quiet:
logger.level = WARNING
# we still want plans to come out during quite so set the plan
# logger output to info in case the PlanLogger is being used
getLogger('Plan').setLevel(INFO)
# TODO: these should move out of octoDNS core...
# boto is noisy, set it to warn
getLogger('botocore').level = WARN
getLogger('botocore').level = WARNING
# DynectSession is noisy too
getLogger('DynectSession').level = WARN
getLogger('DynectSession').level = WARNING

+ 4
- 3
octodns/manager.py View File

@ -5,9 +5,9 @@
from collections import deque
from concurrent.futures import ThreadPoolExecutor
from importlib import import_module
from logging import getLogger
from os import environ
from sys import stdout
import logging
from . import __VERSION__
from .idna import IdnaDict, idna_decode, idna_encode
@ -90,7 +90,8 @@ class ManagerException(Exception):
class Manager(object):
log = logging.getLogger('Manager')
log = getLogger('Manager')
plan_log = getLogger('Plan')
@classmethod
def _plan_keyer(cls, p):
@ -629,7 +630,7 @@ class Manager(object):
plans.sort(key=self._plan_keyer, reverse=True)
for output in self.plan_outputs.values():
output.run(plans=plans, log=self.log, fh=plan_output_fh)
output.run(plans=plans, log=self.plan_log, fh=plan_output_fh)
if not force:
self.log.debug('sync: checking safety')


+ 1
- 0
octodns/provider/plan.py View File

@ -189,6 +189,7 @@ class PlanLogger(_PlanOutput):
buf.write('No changes were planned\n')
buf.write(hr)
buf.write('\n')
log.log(self.level, buf.getvalue())


Loading…
Cancel
Save