Skip to content
Snippets Groups Projects
Commit dcbad73c authored by Sven Mäder's avatar Sven Mäder :speech_balloon:
Browse files

Prepare for multiple loggers

parent 0b50c9f4
No related branches found
No related tags found
1 merge request!12Deltalogparse
...@@ -18,12 +18,23 @@ log_path = '/var/log/ldap/delta.log' ...@@ -18,12 +18,23 @@ log_path = '/var/log/ldap/delta.log'
search_base = 'cn=deltalog' search_base = 'cn=deltalog'
object_classes = '(|(objectClass=auditModify)(objectClass=auditAdd)(objectClass=auditDelete))' object_classes = '(|(objectClass=auditModify)(objectClass=auditAdd)(objectClass=auditDelete))'
logging.basicConfig( #logging.basicConfig(
filename='/var/log/ldap/deltalogparse.log', # filename='/var/log/ldap/deltalogparse.log',
level=loglevel, # level=loglevel,
format='%(asctime)s ' + process_name + '[%(process)d]:%(levelname)s: %(message)s', # format='%(asctime)s ' + process_name + '[%(process)d]:%(levelname)s: %(message)s',
# datefmt='%Y-%m-%d %H:%M:%S'
#)
log = logging.getLogger('deltalogparse')
log.setLevel(loglevel)
log_fh = logging.FileHandler('/var/log/ldap/deltalogparse.log')
log_fh.setLevel(loglevel)
log_formatter = logging.Formatter(
fmt='%(asctime)s ' + process_name + '[%(process)d]:%(levelname)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S' datefmt='%Y-%m-%d %H:%M:%S'
) )
log_fh.setFormatter(log_formatter)
log.addHandler(log_fh)
rgx_skip = re.compile( rgx_skip = re.compile(
r'^(' r'^('
...@@ -53,7 +64,7 @@ def is_skipped(attributes): ...@@ -53,7 +64,7 @@ def is_skipped(attributes):
return True return True
def log(entry): def deltalog(entry):
req_type = entry['attributes']['reqType'][0] req_type = entry['attributes']['reqType'][0]
req_dn = entry['attributes']['reqDN'][0] req_dn = entry['attributes']['reqDN'][0]
...@@ -61,8 +72,8 @@ def log(entry): ...@@ -61,8 +72,8 @@ def log(entry):
entry['attributes'] = attributes entry['attributes'] = attributes
del entry['raw_attributes'] del entry['raw_attributes']
logging.debug(pprint.pformat(entry, indent=4)) log.debug(pprint.pformat(entry, indent=4))
logging.info('log: %s %s' % (req_type, req_dn)) log.info('log: %s %s' % (req_type, req_dn))
def sleep(start_time): def sleep(start_time):
...@@ -70,7 +81,7 @@ def sleep(start_time): ...@@ -70,7 +81,7 @@ def sleep(start_time):
elapsed_time = current_time - start_time elapsed_time = current_time - start_time
sleep_time = update_every - elapsed_time sleep_time = update_every - elapsed_time
logging.info('runtime %0.3fs, sleeping %0.3fs' % (elapsed_time, sleep_time)) log.info('runtime %0.3fs, sleeping %0.3fs' % (elapsed_time, sleep_time))
if sleep_time > 0: if sleep_time > 0:
time.sleep(sleep_time) time.sleep(sleep_time)
...@@ -90,9 +101,9 @@ def main(): ...@@ -90,9 +101,9 @@ def main():
try: try:
response = slapd.search(search_base, search_filter) response = slapd.search(search_base, search_filter)
except: except:
logging.error('socket error!') log.error('socket error!')
if slapd.reconnect(): if slapd.reconnect():
logging.error('socket reconnected.') log.error('socket reconnected.')
if response: if response:
for entry in slapd.response(): for entry in slapd.response():
...@@ -103,15 +114,15 @@ def main(): ...@@ -103,15 +114,15 @@ def main():
req_type = entry['attributes']['reqType'][0] req_type = entry['attributes']['reqType'][0]
req_dn = entry['attributes']['reqDN'][0] req_dn = entry['attributes']['reqDN'][0]
logging.info(' '.join(['processing:', req_start, entry['dn']])) log.info(' '.join(['processing:', req_start, entry['dn']]))
if req_type == 'modify': if req_type == 'modify':
req_mods = entry['attributes']['reqMod'] req_mods = entry['attributes']['reqMod']
if is_skipped(req_mods): if is_skipped(req_mods):
logging.info('skip: %s %s' % (req_type, req_dn)) log.info('skip: %s %s' % (req_type, req_dn))
continue continue
log(entry) deltalog(entry)
sleep(start_time) sleep(start_time)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment