Skip to content

Commit

Permalink
#11 Added to the demo parser and analyser some extra log calls to dem…
Browse files Browse the repository at this point in the history
…onstrate how-to log
  • Loading branch information
dario-br committed Oct 17, 2024
1 parent 8739172 commit 10fc4e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
15 changes: 11 additions & 4 deletions src/sysdiagnose/analysers/demo_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ def execute(self):
Load parsers here, and use the parser.get_result() to get the data.
By doing so you will get the parser output even if it never ran before.
"""
print("DO SOMETHING HERE")
logger.info("log something here", extra={'analyser': __name__})

# json_data = p_fooparser.get_result()
try:
print("DO SOMETHING HERE")
logger.info("log something here", extra={'analyser': __name__})
if True:
logger.warning("This will log a warning")
# logger.error("This will log an error")

# json_data = p_fooparser.get_result()
except Exception as e:
logger.exception("This will log an error with the exception information")
# logger.warning("This will log a warning with the exception information", exc_info=True)

result = {'foo': 'bar'}
return result
19 changes: 12 additions & 7 deletions src/sysdiagnose/parsers/demo_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ def execute(self) -> list | dict:
log_files = self.get_log_files()
for log_file in log_files:
entry = {}

# timestamp = datetime.strptime(item['timestamp'], '%Y-%m-%d %H:%M:%S.%f %z')
# entry['datetime'] = timestamp.isoformat(timespec='microseconds')
# entry['timestamp'] = timestamp.timestamp()
result.append(entry)
logger.info(f"Processing file {log_file}, new entry added", extra={'log_file': log_file, 'entry': entry})

try:
# timestamp = datetime.strptime(item['timestamp'], '%Y-%m-%d %H:%M:%S.%f %z')
# entry['datetime'] = timestamp.isoformat(timespec='microseconds')
# entry['timestamp'] = timestamp.timestamp()
result.append(entry)
logger.info(f"Processing file {log_file}, new entry added", extra={'log_file': log_file, 'entry': entry})
if not entry:
logger.warning("Empty entry.")
# logger.error("Empty entry.")
except Exception as e:
logger.exception("This will log an error with the exception information")
# logger.warning("This will log a warning with the exception information", exc_info=True)
return result

0 comments on commit 10fc4e7

Please sign in to comment.