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