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