From 37ef82fc51f8c59d58c8b7066ad76eab5a5fd11c Mon Sep 17 00:00:00 2001 From: Mark Grassi <17365607+markgras@users.noreply.github.com> Date: Sun, 5 Mar 2023 18:14:22 -0500 Subject: [PATCH] Defer logger string formatting --- utils/apparmor/aa.py | 8 ++++---- utils/apparmor/common.py | 12 ++++++------ utils/apparmor/logparser.py | 8 ++++---- utils/apparmor/notify.py | 12 ++++++------ utils/apparmor/ui.py | 12 ++++++------ 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/utils/apparmor/aa.py b/utils/apparmor/aa.py index 24c781744..ebb62dd87 100644 --- a/utils/apparmor/aa.py +++ b/utils/apparmor/aa.py @@ -492,7 +492,7 @@ def create_new_profile(localfile, is_stub=False): created.append(localfile) changed[localfile] = True - debug_logger.debug("Profile for %s:\n\t%s" % (localfile, local_profile.__str__())) + debug_logger.debug("Profile for %s:\n\t%s", localfile, local_profile) return local_profile @@ -1125,7 +1125,7 @@ def ask_the_questions(log_dict): # Ignore log events for a non-existing profile or child profile. Such events can occur # after deleting a profile or hat manually, or when processing a foreign log. # (Checking for 'file' is a simplified way to check if it's a ProfileStorage.) - debug_logger.debug("Ignoring events for non-existing profile %s" % full_profile) + debug_logger.debug("Ignoring events for non-existing profile %s", full_profile) continue ans = '' @@ -1806,7 +1806,7 @@ def read_profile(file, active_profile): data = f_in.readlines() except IOError as e: aaui.UI_Important('WARNING: Error reading file %s, skipping.\n %s' % (file, e)) - debug_logger.debug("read_profile: can't read %s - skipping" % file) + debug_logger.debug("read_profile: can't read %s - skipping", file) return profile_data = parse_profile_data(data, file, 0, True) @@ -2304,7 +2304,7 @@ def write_profile(profile, is_attachment=False): if profile in changed: changed.pop(profile) else: - debug_logger.info("Unchanged profile written: %s (not listed in 'changed' list)" % profile) + debug_logger.info("Unchanged profile written: %s (not listed in 'changed' list)", profile) original_aa[profile] = deepcopy(aa[profile]) diff --git a/utils/apparmor/common.py b/utils/apparmor/common.py index 5a853d977..626440942 100644 --- a/utils/apparmor/common.py +++ b/utils/apparmor/common.py @@ -340,17 +340,17 @@ class DebugLogger: ) self.logger = logging.getLogger(__name__) - def error(self, message): + def error(self, message, *args): if self.debugging: - self.logger.error(message) + self.logger.error(message, *args) - def info(self, message): + def info(self, message, *args): if self.debugging: - self.logger.info(message) + self.logger.info(message, *args) - def debug(self, message): + def debug(self, message, *args): if self.debugging: - self.logger.debug(message) + self.logger.debug(message, *args) def shutdown(self): logging.shutdown() diff --git a/utils/apparmor/logparser.py b/utils/apparmor/logparser.py index b1648515c..f224e8ec0 100644 --- a/utils/apparmor/logparser.py +++ b/utils/apparmor/logparser.py @@ -81,7 +81,7 @@ class ReadLog: def parse_event(self, msg): """Parse the event from log into key value pairs""" msg = msg.strip() - self.debug_logger.info('parse_event: %s' % msg) + self.debug_logger.info('parse_event: %s', msg) event = LibAppArmor.parse_record(msg) ev = dict() ev['resource'] = event.info @@ -266,7 +266,7 @@ class ReadLog: return else: - self.debug_logger.debug('UNHANDLED: %s' % e) + self.debug_logger.debug('UNHANDLED: %s', e) def read_log(self, logmark): self.logmark = logmark @@ -284,11 +284,11 @@ class ReadLog: if not line: break line = line.strip() - self.debug_logger.debug('read_log: %s' % line) + self.debug_logger.debug('read_log: %s', line) if self.logmark in line: seenmark = True - self.debug_logger.debug('read_log: seenmark = %s' % seenmark) + self.debug_logger.debug('read_log: seenmark = %s', seenmark) if not seenmark: continue diff --git a/utils/apparmor/notify.py b/utils/apparmor/notify.py index 84aaaf3e1..08e381716 100644 --- a/utils/apparmor/notify.py +++ b/utils/apparmor/notify.py @@ -37,12 +37,12 @@ def get_last_login_timestamp(username, filename='/var/log/wtmp'): timestamp = 0 last_login = 0 - debug_logger.debug('Username: {}'.format(username)) + debug_logger.debug('Username: %s', username) with open(filename, "rb") as wtmp_file: offset = 0 wtmp_filesize = os.path.getsize(filename) - debug_logger.debug('WTMP filesize: {}'.format(wtmp_filesize)) + debug_logger.debug('WTMP filesize: %s', wtmp_filesize) if wtmp_filesize < 356: return 0 # (nearly) empty wtmp file, no entries @@ -52,8 +52,8 @@ def get_last_login_timestamp(username, filename='/var/log/wtmp'): timestamp_x86_64 = struct.unpack("L", wtmp_file.read(4))[0] # noqa: E221 - debug_logger.debug('WTMP timestamps: x86_64 %s, aarch64 %s, s390x %s' - % (timestamp_x86_64, timestamp_aarch64, timestamp_s390x)) + debug_logger.debug('WTMP timestamps: x86_64 %s, aarch64 %s, s390x %s', + timestamp_x86_64, timestamp_aarch64, timestamp_s390x) if sane_timestamp(timestamp_x86_64): endianness = '<' # little endian @@ -77,7 +77,7 @@ def get_last_login_timestamp(username, filename='/var/log/wtmp'): offset += 384 + extra_offset_before + extra_offset_after # Increment for next entry type = struct.unpack('%sH' % endianness, wtmp_file.read(2))[0] - debug_logger.debug('WTMP entry type: {}'.format(type)) + debug_logger.debug('WTMP entry type: %s', type) wtmp_file.read(2) # skip padding # Only parse USER lines @@ -98,7 +98,7 @@ def get_last_login_timestamp(username, filename='/var/log/wtmp'): wtmp_file.read(extra_offset_after) usec = struct.unpack("