aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2020-06-05 11:46:08 -0400
committerJake Hunsaker <jhunsake@redhat.com>2020-06-17 12:11:29 -0400
commit4ee616eb584c9a5d3982d6fe9ce7996c7ebf97b1 (patch)
tree16c446262344761ee3d20c74f82386fe661a4537
parent0779f8cdc76baca874e51fce091dbb2ef5da60ff (diff)
downloadsos-4ee616eb584c9a5d3982d6fe9ce7996c7ebf97b1.tar.gz
[cleaner] Write log file to disk separately when run directly from CLI
When run via `report` or `collect`, the log entries from `SoSCleaner` will be included in the "normal" logging for those components. However, when run directly from the CLI, `sos clean` does not add its own logging to the archive(s) processed. Instead, now write the log file to disk in the same directory the processed archive gets written to, rather than losing the logging entirely.
-rw-r--r--sos/cleaner/__init__.py17
-rw-r--r--sos/report/__init__.py15
2 files changed, 25 insertions, 7 deletions
diff --git a/sos/cleaner/__init__.py b/sos/cleaner/__init__.py
index 5c0feb7a..30396edf 100644
--- a/sos/cleaner/__init__.py
+++ b/sos/cleaner/__init__.py
@@ -331,6 +331,8 @@ third party.
with open(os.path.join(self.sys_tmp, chksum_name), 'w') as cf:
cf.write(checksum)
+ self.write_cleaner_log()
+
final_path = self.obfuscate_string(
os.path.join(self.sys_tmp, arc_path.split('/')[-1])
)
@@ -374,7 +376,7 @@ third party.
def write_map_for_archive(self, _map):
try:
map_path = self.obfuscate_string(
- os.path.join(self.sys_tmp, "%s_private_map" % self.arc_name)
+ os.path.join(self.sys_tmp, "%s-private_map" % self.arc_name)
)
return self.write_map_to_file(_map, map_path)
except Exception as err:
@@ -393,6 +395,19 @@ third party.
self.log_error("Could not update mapping config file: %s"
% err)
+ def write_cleaner_log(self):
+ """When invoked via the command line, the logging from SoSCleaner will
+ not be added to the archive(s) it processes, so we need to write it
+ separately to disk
+ """
+ log_name = os.path.join(
+ self.sys_tmp, "%s-obfuscation.log" % self.arc_name
+ )
+ with open(log_name, 'w') as logfile:
+ self.sos_log_file.seek(0)
+ for line in self.sos_log_file.readlines():
+ logfile.write(line)
+
def get_new_checksum(self, archive_path):
"""Calculate a new checksum for the obfuscated archive, as the previous
checksum will no longer be valid
diff --git a/sos/report/__init__.py b/sos/report/__init__.py
index 17a3d0a0..0ff102d6 100644
--- a/sos/report/__init__.py
+++ b/sos/report/__init__.py
@@ -1119,12 +1119,6 @@ class SoSReport(SoSComponent):
fp.close()
def final_work(self):
- # This must come before archive creation to ensure that log
- # files are closed and cleaned up at exit.
- #
- # All subsequent terminal output must use print().
- self._add_sos_logs()
-
if self.manifest is not None:
self.archive.add_final_manifest_data(self.opts.compression_type)
@@ -1147,6 +1141,15 @@ class SoSReport(SoSComponent):
except Exception as err:
print(_("ERROR: Unable to obfuscate report: %s" % err))
+ self._add_sos_logs()
+ # Now, separately clean the log files that cleaner also wrote to
+ if self.opts.clean:
+ _dir = os.path.join(self.tmpdir, self.archive._name, 'sos_logs')
+ cleaner.obfuscate_file(os.path.join(_dir, 'sos.log'),
+ short_name='sos.log')
+ cleaner.obfuscate_file(os.path.join(_dir, 'ui.log'),
+ short_name='ui.log')
+
# package up and compress the results
if not self.opts.build:
old_umask = os.umask(0o077)