MessagePrinter.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. from EventLogger.Reader import Reader
  9. from EventLogger.Utils import EventNameHash, PrologId
  10. import argparse
  11. import os
  12. import sys
  13. AssertId = EventNameHash("Assert")
  14. ErrorId = EventNameHash("Error")
  15. MessageId = EventNameHash("Message")
  16. PrintfId = EventNameHash("Printf")
  17. WarningId = EventNameHash("Warning")
  18. def main(args):
  19. parser = argparse.ArgumentParser(description='Simple Event Logger Printer')
  20. parser.add_argument('file', type=str, help='Path log file')
  21. parsed_args = parser.parse_args(args)
  22. log_file = parsed_args.file
  23. if not os.path.exists(log_file):
  24. print('[ERROR] Invalid file path supplied')
  25. exit(1)
  26. log_reader = Reader()
  27. status = log_reader.read_log_file(log_file)
  28. if status == Reader.ReadStatus_InsufficientFileSize:
  29. print('File size too small to contain Event Logger information')
  30. return
  31. elif status == Reader.ReadStatus_InvalidFormat:
  32. print('Invalid Event Logger format detected')
  33. return
  34. log_header = log_reader.get_log_header()
  35. print(f'Log File: {log_file}')
  36. print(f'Format: {log_header.get_format()}')
  37. print(f'Version: {log_header.get_version()}')
  38. has_event = (status == Reader.ReadStatus_Success)
  39. while has_event:
  40. event_id = log_reader.get_event_name()
  41. if event_id == PrologId:
  42. print(f'Thread: {log_reader.get_thread_id()}')
  43. elif event_id in (AssertId, ErrorId, WarningId, PrintfId, MessageId):
  44. print(f'> {log_reader.get_event_string()}')
  45. else:
  46. print(f'Event ID {event_id}, Size {log_reader.get_event_size()}')
  47. has_event = log_reader.next()
  48. if __name__ == '__main__':
  49. main(sys.argv[1:])