mirror of
https://github.com/thegeeklab/ansible-later.git
synced 2024-11-29 08:10:36 +00:00
fix small logging issues
This commit is contained in:
parent
397c92a27b
commit
66d5ceec76
@ -2,7 +2,7 @@
|
||||
"""Main program."""
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import json
|
||||
|
||||
from ansiblelater import LOG, __version__, logger
|
||||
from ansiblelater.command import base, candidates
|
||||
@ -16,11 +16,11 @@ def main():
|
||||
help="Location of configuration file")
|
||||
parser.add_argument("-r", "--rules", dest="rules.standards",
|
||||
help="Location of standards rules")
|
||||
parser.add_argument("-q", "--quiet", dest="logging.level", action="store_const",
|
||||
const=logging.ERROR, help="Only output errors")
|
||||
parser.add_argument("-q", "--quiet", dest="logging.level", action="append_const",
|
||||
const=1, help="Only output errors")
|
||||
parser.add_argument("-s", "--standards", dest="rules.filter", action="append",
|
||||
help="limit standards to specific names")
|
||||
parser.add_argument("-v", dest="logging.level", action="count",
|
||||
parser.add_argument("-v", dest="logging.level", action="append_const", const=-1,
|
||||
help="Show more verbose output")
|
||||
parser.add_argument("rules.files", nargs="*")
|
||||
parser.add_argument("--version", action="version", version="%(prog)s {}".format(__version__))
|
||||
@ -29,7 +29,7 @@ def main():
|
||||
|
||||
settings = base.get_settings(args)
|
||||
config = settings.config
|
||||
# print(json.dumps(settings.config, indent=4, sort_keys=True))
|
||||
print(json.dumps(settings.config["logging"], indent=4, sort_keys=True))
|
||||
|
||||
logger.update_logger(LOG, config["logging"]["level"], config["logging"]["json"])
|
||||
|
||||
|
@ -79,7 +79,7 @@ class Candidate(object):
|
||||
LOG.warn("%s %s does not present standards version. "
|
||||
"Using latest standards version %s" %
|
||||
(type(self).__name__, self.path, version))
|
||||
|
||||
else:
|
||||
LOG.info("%s %s declares standards version %s" %
|
||||
(type(self).__name__, self.path, version))
|
||||
|
||||
@ -96,7 +96,6 @@ class Candidate(object):
|
||||
else:
|
||||
target_standards = standards
|
||||
|
||||
# print(target_standards)
|
||||
return target_standards
|
||||
|
||||
def review(self, settings, lines=None):
|
||||
@ -142,13 +141,13 @@ class Candidate(object):
|
||||
path=self.path,
|
||||
error=err), extra=flag_extra(err_labels))
|
||||
errors = errors + 1
|
||||
if not result.errors:
|
||||
if not standard.version:
|
||||
LOG.info("Best practice '%s' met" % standard.name, extra=flag_extra(labels))
|
||||
elif LooseVersion(standard.version) > LooseVersion(self.version):
|
||||
LOG.info("Future standard '%s' met" % standard.name, extra=flag_extra(labels))
|
||||
else:
|
||||
LOG.info("Standard '%s' met" % standard.name)
|
||||
# if not result.errors:
|
||||
# if not standard.version:
|
||||
# LOG.info("Best practice '%s' met" % standard.name, extra=flag_extra(labels))
|
||||
# elif LooseVersion(standard.version) > LooseVersion(self.version):
|
||||
# LOG.info("Future standard '%s' met" % standard.name, extra=flag_extra(labels))
|
||||
# else:
|
||||
# LOG.info("Standard '%s' met" % standard.name)
|
||||
|
||||
return errors
|
||||
|
||||
@ -272,7 +271,6 @@ def classify(filename, settings={}, standards=[]):
|
||||
"filter_plugins"] or filename.endswith(".py"):
|
||||
return Code(filename, settings, standards)
|
||||
if "inventory" in basename or "hosts" in basename or parentdir in ["inventory"]:
|
||||
print("hosts" in filename)
|
||||
return Inventory(filename, settings, standards)
|
||||
if "rolesfile" in basename or "requirements" in basename:
|
||||
return Rolesfile(filename, settings, standards)
|
||||
|
@ -42,6 +42,7 @@ class Settings(object):
|
||||
self._update_filelist()
|
||||
|
||||
def _set_args(self, args):
|
||||
defaults = self._get_defaults()
|
||||
self.config_file = args.get("config_file") or default_config_file
|
||||
|
||||
args.pop("config_file", None)
|
||||
@ -52,10 +53,12 @@ class Settings(object):
|
||||
tmp_dict = utils.add_dict_branch(tmp_dict, key.split("."), value)
|
||||
|
||||
# Override correct log level from argparse
|
||||
levels = [logging.WARNING, logging.INFO, logging.DEBUG]
|
||||
levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
|
||||
log_level = levels.index(logging.getLevelName(defaults["logging"]["level"]))
|
||||
if tmp_dict.get("logging"):
|
||||
tmp_dict["logging"]["level"] = levels[
|
||||
min(len(levels) - 1, tmp_dict["logging"]["level"] - 1)]
|
||||
for adjustment in tmp_dict["logging"]["level"]:
|
||||
log_level = min(len(levels) - 1, max(log_level + adjustment, 0))
|
||||
tmp_dict["logging"]["level"] = logging.getLevelName(levels[log_level])
|
||||
|
||||
tmp_dict["rules"]["files"] = self._get_files(tmp_dict)
|
||||
|
||||
@ -87,7 +90,7 @@ class Settings(object):
|
||||
"exclude_files": []
|
||||
},
|
||||
"logging": {
|
||||
"level": logging.WARN,
|
||||
"level": logging.getLevelName("WARNING"),
|
||||
"json": False
|
||||
},
|
||||
"ansible": {
|
||||
|
Loading…
Reference in New Issue
Block a user