From 248656b81fe761626085daec7bafb0354cfca811 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 28 Jun 2017 23:36:42 +0200 Subject: [PATCH] First iteration of logging cleanup. --- cdist/config.py | 24 ++++++++++++------------ cdist/core/explorer.py | 20 ++++++++++---------- cdist/core/manifest.py | 2 +- cdist/emulator.py | 6 +++--- cdist/exec/local.py | 18 +++++++++--------- cdist/exec/remote.py | 20 ++++++++++---------- cdist/shell.py | 4 ++-- scripts/cdist | 4 ++-- 8 files changed, 49 insertions(+), 49 deletions(-) diff --git a/cdist/config.py b/cdist/config.py index 19679a4c..f6b0cc20 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -144,7 +144,7 @@ class Config(object): hostcnt += 1 if args.parallel: - log.debug("Creating child process for %s", host) + log.trace("Creating child process for %s", host) process[host] = multiprocessing.Process( target=cls.onehost, args=(host, host_base_path, hostdir, args, True)) @@ -159,7 +159,7 @@ class Config(object): # Catch errors in parallel mode when joining if args.parallel: for host in process.keys(): - log.debug("Joining process %s", host) + log.trace("Joining process %s", host) process[host].join() if not process[host].exitcode == 0: @@ -300,7 +300,7 @@ class Config(object): return objects_changed def _iterate_once_sequential(self): - self.log.info("Iteration in sequential mode") + self.log.debug("Iteration in sequential mode") objects_changed = False for cdist_object in self.object_list(): @@ -327,7 +327,7 @@ class Config(object): return objects_changed def _iterate_once_parallel(self): - self.log.info("Iteration in parallel mode in {} jobs".format( + self.log.debug("Iteration in parallel mode in {} jobs".format( self.jobs)) objects_changed = False @@ -350,15 +350,15 @@ class Config(object): self.object_prepare(cargo[0]) objects_changed = True elif cargo: - self.log.debug("Multiprocessing start method is {}".format( + self.log.trace("Multiprocessing start method is {}".format( multiprocessing.get_start_method())) - self.log.debug(("Starting multiprocessing Pool for {} parallel " + self.log.trace(("Starting multiprocessing Pool for {} parallel " "objects preparation".format(n))) args = [ (c, ) for c in cargo ] mp_pool_run(self.object_prepare, args, jobs=self.jobs) - self.log.debug(("Multiprocessing for parallel object " + self.log.trace(("Multiprocessing for parallel object " "preparation finished")) objects_changed = True @@ -386,15 +386,15 @@ class Config(object): self.object_run(cargo[0]) objects_changed = True elif cargo: - self.log.debug("Multiprocessing start method is {}".format( + self.log.trace("Multiprocessing start method is {}".format( multiprocessing.get_start_method())) - self.log.debug(("Starting multiprocessing Pool for {} parallel " + self.log.trace(("Starting multiprocessing Pool for {} parallel " "object run".format(n))) args = [ (c, ) for c in cargo ] mp_pool_run(self.object_run, args, jobs=self.jobs) - self.log.debug(("Multiprocessing for parallel object " + self.log.trace(("Multiprocessing for parallel object " "run finished")) objects_changed = True @@ -473,7 +473,7 @@ class Config(object): def object_run(self, cdist_object): """Run gencode and code for an object""" - self.log.debug("Trying to run object %s" % (cdist_object.name)) + self.log.verbose("Trying to run object %s" % (cdist_object.name)) if cdist_object.state == core.CdistObject.STATE_DONE: raise cdist.Error(("Attempting to run an already finished " "object: %s"), cdist_object) @@ -500,5 +500,5 @@ class Config(object): self.log.info("Skipping code execution due to DRY RUN") # Mark this object as done - self.log.debug("Finishing run of " + cdist_object.name) + self.log.trace("Finishing run of " + cdist_object.name) cdist_object.state = core.CdistObject.STATE_DONE diff --git a/cdist/core/explorer.py b/cdist/core/explorer.py index 45afc5c0..aea17d83 100644 --- a/cdist/core/explorer.py +++ b/cdist/core/explorer.py @@ -95,7 +95,7 @@ class Explorer(object): out_path directory. """ - self.log.info("Running global explorers") + self.log.trace("Running global explorers") self.transfer_global_explorers() if self.jobs is None: self._run_global_explorers_seq(out_path) @@ -109,22 +109,22 @@ class Explorer(object): fd.write(output) def _run_global_explorers_seq(self, out_path): - self.log.info("Running global explorers sequentially") + self.log.debug("Running global explorers sequentially") for explorer in self.list_global_explorer_names(): self._run_global_explorer(explorer, out_path) def _run_global_explorers_parallel(self, out_path): - self.log.info("Running global explorers in {} parallel jobs".format( + self.log.debug("Running global explorers in {} parallel jobs".format( self.jobs)) - self.log.debug("Multiprocessing start method is {}".format( + self.log.trace("Multiprocessing start method is {}".format( multiprocessing.get_start_method())) - self.log.debug(("Starting multiprocessing Pool for global " + self.log.trace(("Starting multiprocessing Pool for global " "explorers run")) args = [ (e, out_path, ) for e in self.list_global_explorer_names() ] mp_pool_run(self._run_global_explorer, args, jobs=self.jobs) - self.log.debug(("Multiprocessing run for global explorers " + self.log.trace(("Multiprocessing run for global explorers " "finished")) # logger is not pickable, so remove it when we pickle @@ -168,15 +168,15 @@ class Explorer(object): in the object. """ - self.log.debug("Transfering type explorers for type: %s", + self.log.trace("Transfering type explorers for type: %s", cdist_object.cdist_type) self.transfer_type_explorers(cdist_object.cdist_type) - self.log.debug("Transfering object parameters for object: %s", + self.log.trace("Transfering object parameters for object: %s", cdist_object.name) self.transfer_object_parameters(cdist_object) for explorer in self.list_type_explorer_names(cdist_object.cdist_type): output = self.run_type_explorer(explorer, cdist_object) - self.log.debug("Running type explorer '%s' for object '%s'", + self.log.trace("Running type explorer '%s' for object '%s'", explorer, cdist_object.name) cdist_object.explorers[explorer] = output @@ -203,7 +203,7 @@ class Explorer(object): remote side.""" if cdist_type.explorers: if cdist_type.name in self._type_explorers_transferred: - self.log.debug("Skipping retransfer of type explorers for: %s", + self.log.trace("Skipping retransfer of type explorers for: %s", cdist_type) else: source = os.path.join(self.local.type_path, diff --git a/cdist/core/manifest.py b/cdist/core/manifest.py index 29f96c4f..cd0fde9c 100644 --- a/cdist/core/manifest.py +++ b/cdist/core/manifest.py @@ -145,7 +145,7 @@ class Manifest(object): else: user_supplied = True - self.log.info("Running initial manifest " + initial_manifest) + self.log.trace("Running initial manifest " + initial_manifest) if not os.path.isfile(initial_manifest): raise NoInitialManifestError(initial_manifest, user_supplied) diff --git a/cdist/emulator.py b/cdist/emulator.py index cdbe5b08..09813d64 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -98,7 +98,7 @@ class Emulator(object): self.save_stdin() self.record_requirements() self.record_auto_requirements() - self.log.debug("Finished %s %s" % ( + self.log.trace("Finished %s %s" % ( self.cdist_object.path, self.parameters)) def __init_log(self): @@ -148,7 +148,7 @@ class Emulator(object): # And finally parse/verify parameter self.args = parser.parse_args(self.argv[1:]) - self.log.debug('Args: %s' % self.args) + self.log.trace('Args: %s' % self.args) def setup_object(self): # Setup object - and ensure it is not in args @@ -240,7 +240,7 @@ class Emulator(object): self.object_source))) raise - self.log.debug("Recording requirement: %s", requirement) + self.log.trace("Recording requirement: %s", requirement) # Save the sanitised version, not the user supplied one # (__file//bar => __file/bar) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index fc2e7c09..be3cde4c 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -163,7 +163,7 @@ class Local(object): with open(self.object_marker_file, 'w') as fd: fd.write("%s\n" % self.object_marker_name) - self.log.debug("Object marker %s saved in %s" % ( + self.log.trace("Object marker %s saved in %s" % ( self.object_marker_name, self.object_marker_file)) def _init_cache_dir(self, cache_dir): @@ -178,12 +178,12 @@ class Local(object): def rmdir(self, path): """Remove directory on the local side.""" - self.log.debug("Local rmdir: %s", path) + self.log.trace("Local rmdir: %s", path) shutil.rmtree(path) def mkdir(self, path): """Create directory on the local side.""" - self.log.debug("Local mkdir: %s", path) + self.log.trace("Local mkdir: %s", path) os.makedirs(path, exist_ok=True) def run(self, command, env=None, return_output=False, message_prefix=None, @@ -192,7 +192,7 @@ class Local(object): Return the output as a string. """ - self.log.debug("Local run: %s", command) + self.log.trace("Local run: %s", command) assert isinstance(command, (list, tuple)), ( "list or tuple argument expected, got: %s" % command) @@ -214,9 +214,9 @@ class Local(object): try: if save_output: output, errout = exec_util.call_get_output(command, env=env) - self.log.debug("Local stdout: {}".format(output)) + self.log.trace("Local stdout: {}".format(output)) # Currently, stderr is not captured. - # self.log.debug("Local stderr: {}".format(errout)) + # self.log.trace("Local stderr: {}".format(errout)) if return_output: return output.decode() else: @@ -279,7 +279,7 @@ class Local(object): return cache_subpath def save_cache(self, start_time=time.time()): - self.log.debug("cache subpath pattern: {}".format( + self.log.trace("cache subpath pattern: {}".format( self.cache_path_pattern)) cache_subpath = self._cache_subpath(start_time, self.cache_path_pattern) @@ -340,7 +340,7 @@ class Local(object): if os.path.exists(dst): os.unlink(dst) - self.log.debug("Linking %s to %s ..." % (src, dst)) + self.log.trace("Linking %s to %s ..." % (src, dst)) try: os.symlink(src, dst) except OSError as e: @@ -352,7 +352,7 @@ class Local(object): src = os.path.abspath(self.exec_path) for cdist_type in core.CdistType.list_types(self.type_path): dst = os.path.join(self.bin_path, cdist_type.name) - self.log.debug("Linking emulator: %s to %s", src, dst) + self.log.trace("Linking emulator: %s to %s", src, dst) try: os.symlink(src, dst) diff --git a/cdist/exec/remote.py b/cdist/exec/remote.py index 042b7103..ff4ad30a 100644 --- a/cdist/exec/remote.py +++ b/cdist/exec/remote.py @@ -111,17 +111,17 @@ class Remote(object): def rmdir(self, path): """Remove directory on the remote side.""" - self.log.debug("Remote rmdir: %s", path) + self.log.trace("Remote rmdir: %s", path) self.run(["rm", "-rf", path]) def mkdir(self, path): """Create directory on the remote side.""" - self.log.debug("Remote mkdir: %s", path) + self.log.trace("Remote mkdir: %s", path) self.run(["mkdir", "-p", path]) def transfer(self, source, destination, jobs=None): """Transfer a file or directory to the remote side.""" - self.log.debug("Remote transfer: %s -> %s", source, destination) + self.log.trace("Remote transfer: %s -> %s", source, destination) self.rmdir(destination) if os.path.isdir(source): self.mkdir(destination) @@ -147,11 +147,11 @@ class Remote(object): def _transfer_dir_parallel(self, source, destination, jobs): """Transfer a directory to the remote side in parallel mode.""" - self.log.info("Remote transfer in {} parallel jobs".format( + self.log.debug("Remote transfer in {} parallel jobs".format( jobs)) - self.log.debug("Multiprocessing start method is {}".format( + self.log.trace("Multiprocessing start method is {}".format( multiprocessing.get_start_method())) - self.log.debug(("Starting multiprocessing Pool for parallel " + self.log.trace(("Starting multiprocessing Pool for parallel " "remote transfer")) args = [] for f in glob.glob1(source, '*'): @@ -161,7 +161,7 @@ class Remote(object): _wrap_addr(self.target_host[0]), destination)]) args.append((command, )) mp_pool_run(self._run_command, args, jobs=jobs) - self.log.debug(("Multiprocessing for parallel transfer " + self.log.trace(("Multiprocessing for parallel transfer " "finished")) def run_script(self, script, env=None, return_output=False): @@ -226,12 +226,12 @@ class Remote(object): os_environ['__target_hostname'] = self.target_host[1] os_environ['__target_fqdn'] = self.target_host[2] - self.log.debug("Remote run: %s", command) + self.log.trace("Remote run: %s", command) try: output, errout = exec_util.call_get_output(command, env=os_environ) - self.log.debug("Remote stdout: {}".format(output)) + self.log.trace("Remote stdout: {}".format(output)) # Currently, stderr is not captured. - # self.log.debug("Remote stderr: {}".format(errout)) + # self.log.trace("Remote stderr: {}".format(errout)) if return_output: return output.decode() except subprocess.CalledProcessError as e: diff --git a/cdist/shell.py b/cdist/shell.py index 9378efc3..662f8f7d 100644 --- a/cdist/shell.py +++ b/cdist/shell.py @@ -86,10 +86,10 @@ class Shell(object): self._init_files_dirs() self._init_environment() - log.info("Starting shell...") + log.trace("Starting shell...") # save_output=False -> do not catch stdout and stderr self.local.run([self.shell], self.env, save_output=False) - log.info("Finished shell.") + log.trace("Finished shell.") @classmethod def commandline(cls, args): diff --git a/scripts/cdist b/scripts/cdist index 9719e6ee..492bbec6 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -44,8 +44,8 @@ def commandline(): if retval: log.warning(retval) - log.debug(args) - log.info("version %s" % cdist.VERSION) + log.trace(args) + log.verbose("version %s" % cdist.VERSION) # Work around python 3.3 bug: # http://bugs.python.org/issue16308