diff --git a/r11k/main.py b/r11k/main.py index 91d33a070109173dc7e474676699f01efbdfbc0e..d9b8da67f264132f8e1b654a419e593092b3189b 100644 --- a/r11k/main.py +++ b/r11k/main.py @@ -31,6 +31,8 @@ def __main() -> int: parser.add_argument('--env-name', help='Force name of environment', dest='environment_name') parser.add_argument('--force', help='Refresh all caches', dest='force', action='store_true') + parser.add_argument('--log', help='Set outptu verbosity', + dest='loglevel', action='store') args = parser.parse_args() @@ -38,12 +40,24 @@ def __main() -> int: r11k.config.config.http_ttl = 0 r11k.config.config.git_ttl = 0 - logger.setLevel(logging.DEBUG) + root_logger = logging.getLogger('') + root_logger.setLevel(logging.WARNING) + if args.loglevel: + root_logger.setLevel(args.loglevel) + ch = logging.StreamHandler() - ch.setLevel(logging.DEBUG) - formatter = logging.Formatter('%(name)s %(lineno)i - %(levelname)s - %(message)s') + + formatter: logging.Formatter + try: + import colorlog + formatter = colorlog.ColoredFormatter('%(log_color)s%(levelname)s:%(name)s:%(message)s') + except ModuleNotFoundError: + formatter = logging.Formatter('%(name)s %(lineno)i - %(levelname)s - %(message)s') + ch.setFormatter(formatter) - logger.addHandler(ch) + root_logger.addHandler(ch) + + root_logger.debug('Logging initialized') puppetfile = load_puppetfile(args.puppetfile) diff --git a/r11k/puppetfile.py b/r11k/puppetfile.py index f47a8de8eeb9b3e1681960c89e1eeb4c5e5eb447..4fd7ca67e7ce68fbf700df77057a620f0284a2d1 100644 --- a/r11k/puppetfile.py +++ b/r11k/puppetfile.py @@ -166,7 +166,7 @@ class ResolvedPuppetFile(PuppetFile): logger.info('== Building actual environment ==') util.ensure_directory(destination) for module in self.modules.values(): - logger.info(module) + logger.debug('Including %s', module) path = os.path.join(destination, 'modules', module.module_path) module.publish(path) @@ -227,6 +227,7 @@ def parse_puppetfile(data: dict[str, Any], def load_puppetfile(filepath: str) -> PuppetFile: """Load puppetfile.yaml.""" + logger.debug('Loading %s', filepath) with open(filepath) as f: data = yaml.full_load(f) return parse_puppetfile(data, path=filepath) @@ -275,7 +276,7 @@ def find_all_modules_for_environment(puppetfile: PuppetFile) -> ResolvedPuppetFi # For each module in puppetfile for module in modules: - logger.debug(module) + logger.debug('Handling %s', module) # collect its dependencies for depspec in module.metadata.dependencies: # and merge them to the dependency set diff --git a/r11k/puppetmodule/git.py b/r11k/puppetmodule/git.py index b937718bf3c70c46d13a5017896a788152075c28..bfe6a732d8be56596c5b9d40f48e2064f146b2f5 100644 --- a/r11k/puppetmodule/git.py +++ b/r11k/puppetmodule/git.py @@ -141,6 +141,7 @@ class GitPuppetModule(PuppetModule): # NOTE force without a warning isn't the best idea, but will # have to do for now. checkout(repo, self.version, force=True) + logger.info('Published module %s', self) def versions(self) -> list[VersionInfo]: """ diff --git a/r11k/util.py b/r11k/util.py index bf19410c4436e72133d1128c83431efa11a61af7..774b46caece4d1e94b9009aade6ce00d47b45d97 100644 --- a/r11k/util.py +++ b/r11k/util.py @@ -18,7 +18,7 @@ def ensure_directory(path: str) -> None: # pragma: no cover def download_file(url: str, outfile: str) -> None: """Fetch file from url, save it to outfile.""" - logger.info('Downloading', outfile) + logger.info('Downloading %s', outfile) r = requests.get(url, stream=True) if r.status_code != requests.codes.ok: r.raise_for_status()