mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-25 11:37:49 +00:00
Defer logger string formatting
This commit is contained in:
parent
b8a14e29b7
commit
37ef82fc51
@ -492,7 +492,7 @@ def create_new_profile(localfile, is_stub=False):
|
|||||||
created.append(localfile)
|
created.append(localfile)
|
||||||
changed[localfile] = True
|
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
|
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
|
# 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.
|
# 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.)
|
# (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
|
continue
|
||||||
|
|
||||||
ans = ''
|
ans = ''
|
||||||
@ -1806,7 +1806,7 @@ def read_profile(file, active_profile):
|
|||||||
data = f_in.readlines()
|
data = f_in.readlines()
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
aaui.UI_Important('WARNING: Error reading file %s, skipping.\n %s' % (file, 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
|
return
|
||||||
|
|
||||||
profile_data = parse_profile_data(data, file, 0, True)
|
profile_data = parse_profile_data(data, file, 0, True)
|
||||||
@ -2304,7 +2304,7 @@ def write_profile(profile, is_attachment=False):
|
|||||||
if profile in changed:
|
if profile in changed:
|
||||||
changed.pop(profile)
|
changed.pop(profile)
|
||||||
else:
|
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])
|
original_aa[profile] = deepcopy(aa[profile])
|
||||||
|
|
||||||
|
@ -340,17 +340,17 @@ class DebugLogger:
|
|||||||
)
|
)
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def error(self, message):
|
def error(self, message, *args):
|
||||||
if self.debugging:
|
if self.debugging:
|
||||||
self.logger.error(message)
|
self.logger.error(message, *args)
|
||||||
|
|
||||||
def info(self, message):
|
def info(self, message, *args):
|
||||||
if self.debugging:
|
if self.debugging:
|
||||||
self.logger.info(message)
|
self.logger.info(message, *args)
|
||||||
|
|
||||||
def debug(self, message):
|
def debug(self, message, *args):
|
||||||
if self.debugging:
|
if self.debugging:
|
||||||
self.logger.debug(message)
|
self.logger.debug(message, *args)
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
logging.shutdown()
|
logging.shutdown()
|
||||||
|
@ -81,7 +81,7 @@ class ReadLog:
|
|||||||
def parse_event(self, msg):
|
def parse_event(self, msg):
|
||||||
"""Parse the event from log into key value pairs"""
|
"""Parse the event from log into key value pairs"""
|
||||||
msg = msg.strip()
|
msg = msg.strip()
|
||||||
self.debug_logger.info('parse_event: %s' % msg)
|
self.debug_logger.info('parse_event: %s', msg)
|
||||||
event = LibAppArmor.parse_record(msg)
|
event = LibAppArmor.parse_record(msg)
|
||||||
ev = dict()
|
ev = dict()
|
||||||
ev['resource'] = event.info
|
ev['resource'] = event.info
|
||||||
@ -266,7 +266,7 @@ class ReadLog:
|
|||||||
return
|
return
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.debug_logger.debug('UNHANDLED: %s' % e)
|
self.debug_logger.debug('UNHANDLED: %s', e)
|
||||||
|
|
||||||
def read_log(self, logmark):
|
def read_log(self, logmark):
|
||||||
self.logmark = logmark
|
self.logmark = logmark
|
||||||
@ -284,11 +284,11 @@ class ReadLog:
|
|||||||
if not line:
|
if not line:
|
||||||
break
|
break
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
self.debug_logger.debug('read_log: %s' % line)
|
self.debug_logger.debug('read_log: %s', line)
|
||||||
if self.logmark in line:
|
if self.logmark in line:
|
||||||
seenmark = True
|
seenmark = True
|
||||||
|
|
||||||
self.debug_logger.debug('read_log: seenmark = %s' % seenmark)
|
self.debug_logger.debug('read_log: seenmark = %s', seenmark)
|
||||||
if not seenmark:
|
if not seenmark:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -37,12 +37,12 @@ def get_last_login_timestamp(username, filename='/var/log/wtmp'):
|
|||||||
timestamp = 0
|
timestamp = 0
|
||||||
last_login = 0
|
last_login = 0
|
||||||
|
|
||||||
debug_logger.debug('Username: {}'.format(username))
|
debug_logger.debug('Username: %s', username)
|
||||||
|
|
||||||
with open(filename, "rb") as wtmp_file:
|
with open(filename, "rb") as wtmp_file:
|
||||||
offset = 0
|
offset = 0
|
||||||
wtmp_filesize = os.path.getsize(filename)
|
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:
|
if wtmp_filesize < 356:
|
||||||
return 0 # (nearly) empty wtmp file, no entries
|
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
|
timestamp_x86_64 = struct.unpack("<L", wtmp_file.read(4))[0] # noqa: E221
|
||||||
timestamp_aarch64 = struct.unpack("<L", wtmp_file.read(4))[0]
|
timestamp_aarch64 = struct.unpack("<L", wtmp_file.read(4))[0]
|
||||||
timestamp_s390x = struct.unpack(">L", wtmp_file.read(4))[0] # noqa: E221
|
timestamp_s390x = struct.unpack(">L", wtmp_file.read(4))[0] # noqa: E221
|
||||||
debug_logger.debug('WTMP timestamps: x86_64 %s, aarch64 %s, s390x %s'
|
debug_logger.debug('WTMP timestamps: x86_64 %s, aarch64 %s, s390x %s',
|
||||||
% (timestamp_x86_64, timestamp_aarch64, timestamp_s390x))
|
timestamp_x86_64, timestamp_aarch64, timestamp_s390x)
|
||||||
|
|
||||||
if sane_timestamp(timestamp_x86_64):
|
if sane_timestamp(timestamp_x86_64):
|
||||||
endianness = '<' # little endian
|
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
|
offset += 384 + extra_offset_before + extra_offset_after # Increment for next entry
|
||||||
|
|
||||||
type = struct.unpack('%sH' % endianness, wtmp_file.read(2))[0]
|
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
|
wtmp_file.read(2) # skip padding
|
||||||
|
|
||||||
# Only parse USER lines
|
# Only parse USER lines
|
||||||
@ -98,7 +98,7 @@ def get_last_login_timestamp(username, filename='/var/log/wtmp'):
|
|||||||
wtmp_file.read(extra_offset_after)
|
wtmp_file.read(extra_offset_after)
|
||||||
usec = struct.unpack("<L", wtmp_file.read(4))[0]
|
usec = struct.unpack("<L", wtmp_file.read(4))[0]
|
||||||
entry = (pid, line, id, user, host, term, exit, session, timestamp, usec)
|
entry = (pid, line, id, user, host, term, exit, session, timestamp, usec)
|
||||||
debug_logger.debug('WTMP entry: {}'.format(entry))
|
debug_logger.debug('WTMP entry: %s', entry)
|
||||||
|
|
||||||
# Store login timestamp for requested user
|
# Store login timestamp for requested user
|
||||||
if user == username:
|
if user == username:
|
||||||
|
@ -116,7 +116,7 @@ def get_translated_hotkey(translated, cmsg=''):
|
|||||||
|
|
||||||
|
|
||||||
def UI_YesNo(text, default):
|
def UI_YesNo(text, default):
|
||||||
debug_logger.debug('UI_YesNo: %s: %s %s' % (UI_mode, text, default))
|
debug_logger.debug('UI_YesNo: %s: %s %s', UI_mode, text, default)
|
||||||
default = default.lower()
|
default = default.lower()
|
||||||
yes = CMDS['CMD_YES']
|
yes = CMDS['CMD_YES']
|
||||||
no = CMDS['CMD_NO']
|
no = CMDS['CMD_NO']
|
||||||
@ -156,7 +156,7 @@ def UI_YesNo(text, default):
|
|||||||
|
|
||||||
|
|
||||||
def UI_YesNoCancel(text, default):
|
def UI_YesNoCancel(text, default):
|
||||||
debug_logger.debug('UI_YesNoCancel: %s: %s %s' % (UI_mode, text, default))
|
debug_logger.debug('UI_YesNoCancel: %s: %s %s', UI_mode, text, default)
|
||||||
default = default.lower()
|
default = default.lower()
|
||||||
yes = CMDS['CMD_YES']
|
yes = CMDS['CMD_YES']
|
||||||
no = CMDS['CMD_NO']
|
no = CMDS['CMD_NO']
|
||||||
@ -207,7 +207,7 @@ def UI_YesNoCancel(text, default):
|
|||||||
|
|
||||||
|
|
||||||
def UI_GetString(text, default):
|
def UI_GetString(text, default):
|
||||||
debug_logger.debug('UI_GetString: %s: %s %s' % (UI_mode, text, default))
|
debug_logger.debug('UI_GetString: %s: %s %s', UI_mode, text, default)
|
||||||
string = default
|
string = default
|
||||||
if UI_mode == 'json':
|
if UI_mode == 'json':
|
||||||
jsonout = {'dialog': 'getstring', 'text': text, 'default': default}
|
jsonout = {'dialog': 'getstring', 'text': text, 'default': default}
|
||||||
@ -225,7 +225,7 @@ def UI_GetString(text, default):
|
|||||||
|
|
||||||
|
|
||||||
def UI_GetFile(file):
|
def UI_GetFile(file):
|
||||||
debug_logger.debug('UI_GetFile: %s' % UI_mode)
|
debug_logger.debug('UI_GetFile: %s', UI_mode)
|
||||||
filename = None
|
filename = None
|
||||||
if UI_mode == 'json':
|
if UI_mode == 'json':
|
||||||
jsonout = {'dialog': 'getfile', 'text': file['description']}
|
jsonout = {'dialog': 'getfile', 'text': file['description']}
|
||||||
@ -238,12 +238,12 @@ def UI_GetFile(file):
|
|||||||
|
|
||||||
|
|
||||||
def UI_BusyStart(message):
|
def UI_BusyStart(message):
|
||||||
debug_logger.debug('UI_BusyStart: %s' % UI_mode)
|
debug_logger.debug('UI_BusyStart: %s', UI_mode)
|
||||||
UI_Info(message)
|
UI_Info(message)
|
||||||
|
|
||||||
|
|
||||||
def UI_BusyStop():
|
def UI_BusyStop():
|
||||||
debug_logger.debug('UI_BusyStop: %s' % UI_mode)
|
debug_logger.debug('UI_BusyStop: %s', UI_mode)
|
||||||
|
|
||||||
|
|
||||||
def diff(oldprofile, newprofile):
|
def diff(oldprofile, newprofile):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user