SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/env python
  2.  
  3. # Simple tool to take the logs generated by yarn logs -applicationId
  4. # and convert them into separate log files.
  5. # Current implementation deconstructs the monolith log dump
  6. # into multiple files in the format <container_id>.<log_file_name>
  7. # For example, container_1400495557557_0001_01_000001.syslog
  8.  
  9. import argparse
  10. import os
  11. from os.path import isfile,join
  12.  
  13. parser = argparse.ArgumentParser(description='Apache Dev Setup')
  14. parser.add_argument('--app-logs', required=True,
  15.                    help='Application Logs file')
  16. parser.add_argument('--container-log-dir', required=True,
  17.                    help='Location to where container logs should be generated')
  18.  
  19. args = parser.parse_args()
  20.  
  21. print "Using app-logs: " + args.app_logs
  22. print "Using container-log-dir: " + args.container_log_dir
  23.  
  24. base_dir = args.container_log_dir
  25. app_logs_file = args.app_logs
  26.  
  27. if (not os.path.exists(base_dir)):
  28.   os.makedirs(base_dir, 0755)
  29.  
  30. current_container_id = ""
  31. current_log_file = ""
  32. current_log_file_handle = None
  33. log_started = False
  34.  
  35. with open(app_logs_file) as f:
  36.   for line in f:
  37.     l = line.strip()
  38.     if (l.startswith("Container: container")):
  39.       entry = l.split(":")[1].strip()
  40.       current_container_id = entry.expandtabs(1).split(" ")[0].strip()
  41.       log_started = False
  42.       continue
  43.  
  44.     if (current_container_id == ""):
  45.       continue
  46.        
  47.     if (l.startswith("LogType:")):
  48.       if (current_log_file_handle):
  49.         current_log_file_handle.close()
  50.       file_name = current_container_id + "." + l.split(":")[1].strip()
  51.       current_log_file = os.path.join(base_dir, file_name)
  52.       current_log_file_handle = open(current_log_file, "w")
  53.       log_started = False
  54.       continue
  55.  
  56.     if (l.startswith("LogLength:")):
  57.       continue
  58.    
  59.     if (l.startswith("Log Contents:")):
  60.       log_started = True
  61.       continue
  62.  
  63.     if (log_started and current_log_file_handle):
  64.       current_log_file_handle.write(l + os.linesep)
  65.        
  66. if (current_log_file_handle):
  67.   current_log_file_handle.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top