Warning, /FWCore/MessageLogger/scripts/edmMLParser is written in an unsupported language. File is not indexed.
0001 #! /usr/bin/env python3
0002
0003 from __future__ import print_function
0004
0005 def manipulate_log(logfile_name,category_names,printBeginEvent,printMessageLabel,verbosityLevel):
0006
0007 # open file and read it
0008 logfile=open(logfile_name,'r')
0009
0010 writeOut = False
0011
0012 for line in logfile:
0013
0014 # real line a split content
0015 line = line[:-1] # no \n
0016 line_content_list = line.split(' ')
0017
0018 # select interesting fields
0019 identifier = line_content_list[0]
0020 if len(line_content_list) > 1 :
0021 category = line_content_list[1]
0022
0023 # end of message record
0024 if writeOut == True and identifier != '%MSG' :
0025 print(line)
0026
0027 # begin of message record
0028 if identifier.find('%MSG') != -1 :
0029 if identifier == '%MSG' :
0030 writeOut = False
0031 else :
0032 isCategory = False
0033 if len(category_names) == 1 and category_names[0] == '':
0034 isCategory = True
0035 else:
0036 for value in category_names :
0037 if value+":" == category :
0038 isCategory = True
0039 if isCategory == True:
0040 if verbosityLevel == '' :
0041 writeOut = True
0042 elif identifier == '%MSG-'+verbosityLevel :
0043 writeOut = True
0044 if printMessageLabel and writeOut :
0045 print(line)
0046
0047 # begin event record
0048 if printBeginEvent and identifier == 'Begin' and category == 'processing' :
0049 print(line)
0050
0051 logfile.close()
0052
0053 #################################################################################################
0054
0055 if __name__ == '__main__':
0056
0057 import argparse
0058 import os
0059
0060 # Here we define an option parser to handle commandline options..
0061 parser = argparse.ArgumentParser(description='edmMLParser <options> <input file>')
0062 parser.add_argument('logfile_name',
0063 metavar='file',
0064 help='input file name')
0065
0066 parser.add_argument('-c', '--category',
0067 help='List of MessageLogger categories to be searched, separated by ","',
0068 default='',
0069 dest='category_name')
0070
0071 parser.add_argument('-b', '--print-begin-event',
0072 help='Print the begin event record',
0073 action='store_true',
0074 dest='printBeginEvent')
0075
0076 parser.add_argument('-m', '--print-message-label',
0077 help='Print the MessageLogger label for the selected message',
0078 action='store_true',
0079 dest='printMessageLabel')
0080
0081 allowedVerbosityLevels = ['!','i','w','e']
0082
0083 parser.add_argument('-v', '--select-verbosity-level',
0084 help='Select a particular verbosity level for the chosen category, possible values are: '+''.join(allowedVerbosityLevels),
0085 default='',
0086 dest='verbosityLevel')
0087
0088 args = parser.parse_args()
0089
0090 # Now some fault control..If an error is found we raise an exception
0091 if args.logfile_name=='':
0092 raise Exception('Please select a file name and a MessageLogger category!')
0093
0094 if not os.path.exists(args.logfile_name):
0095 raise Exception('File to be parsed not present!')
0096
0097 if args.verbosityLevel != '' and args.verbosityLevel not in allowedVerbosityLevels :
0098 raise Exception('Selected verbosity level not supported')
0099
0100 category_names = args.category_name.split(',')
0101
0102 #launch the function!
0103 manipulate_log(args.logfile_name,category_names,args.printBeginEvent,args.printMessageLabel,args.verbosityLevel)