#!/usr/bin/python import logging import datetime def main(cmdArgs): # Most of the information to publish messages is done by # by passing around and updating a dictionary if not create_rotating_log(): return False LOG = logging.getLogger(__name__) dirPart = cmdArgs[1].split(' ')[0] filePart = cmdArgs[1].split(' ')[2] # guard against partial files and the file qc.txt if filePart[0:1] == '.': return False elif filePart == 'qc.txt': return False processFile = os.path.join(dirPart, filePart) LOG.debug(' ') LOG.debug('------------------------------------------') LOG.debug(processFile) if 'ASCAT' in dirPart: initDict = init_ascat(processFile) if not initDict['status']: return False elif 'IASI' in dirPart: initDict = init_iasi(processFile) if not initDict['status']: return False elif 'MIRS' in dirPart: initDict = init_mirs(processFile) if not initDict['status']: return False else: initDict = init_generic(processFile) if not initDict['status']: return False status = publish_message(initDict) if not status: return False else: return True def init_generic(incomingFile): LOG = logging.getLogger(__name__) eventInfo = {} eventInfo['status'] = True dirName = os.path.dirname(incomingFile) baseName = os.path.basename(incomingFile) try: fileParts = baseName.split('.') except Exception as e: LOG.error('failed splitting up file name' + ' ' + baseName) LOG.error(str(e)) eventInfo['status'] = False return eventInfo eventInfo['server_ip'] = 'dsserve4.ssec.wisc.edu' eventInfo['medium'] = 'file' eventInfo['server_type'] = 'realtime' eventInfo['satellite_family'] = '' eventInfo['instrument'] = '' eventInfo['server_type'] = 'realtime' eventInfo['path'] = incomingFile eventInfo['message_type'] = 'image' eventInfo['status'] = 'complete' eventInfo['start_time'] = '' eventInfo['satellite_ID'] = '' eventInfo['band'] = '' eventInfo['data_type'] = '' eventInfo['wavelength'] = '' eventInfo['coverage'] = '' eventInfo['title'] = '' eventInfo['format'] = 'native' familyTitle = '' try: if 'nc' in fileParts[-1]: eventInfo['format'] = 'ncdf' elif 'h5' or 'hdf5' in fileParts[-1]: eventInfo['format'] = 'hdf' except Exception as e: LOG.error('Failed to check for extention') LOG.error(str(e)) satellite = fileParts[2] if 'NK' in satellite: eventInfo['satellite_ID'] = 'NOAA-15' eventInfo['satellite_family'] = 'noaa-klm' familyTitle = 'NOAA-15' elif 'NL' in satellite: eventInfo['satellite_ID'] = 'NOAA-16' eventInfo['satellite_family'] = 'noaa-klm' familyTitle = 'NOAA-16' elif 'NM' in satellite: eventInfo['satellite_ID'] = 'NOAA-17' eventInfo['satellite_family'] = 'noaa-klm' familyTitle = 'NOAA-17' elif 'NN' in satellite: eventInfo['satellite_ID'] = 'NOAA-18' eventInfo['satellite_family'] = 'noaa-klm' familyTitle = 'NOAA-18' elif 'NP' in satellite: eventInfo['satellite_ID'] = 'NOAA-19' eventInfo['satellite_family'] = 'noaa-klm' familyTitle = 'NOAA-19' elif 'M1' in satellite: eventInfo['satellite_ID'] = 'MetOp-1' eventInfo['satellite_family'] = 'metop' familyTitle = 'MetOp-1' elif 'M2' in satellite: eventInfo['satellite_ID'] = 'MetOp-2' eventInfo['satellite_family'] = 'metop' familyTitle = 'MetOp-2' elif 'M3' in satellite: eventInfo['satellite_ID'] = 'MetOp-3' eventInfo['satellite_family'] = 'metop' familyTitle = 'MetOp-3' elif 'SA' in satellite: eventInfo['satellite_ID'] = 'DMSP-16' eventInfo['satellite_family'] = 'dmsp' familyTitle = 'DMSP-16' elif 'SB' in satellite: eventInfo['satellite_ID'] = 'DMSP-17' eventInfo['satellite_family'] = 'dmsp' familyTitle = 'DMSP-17' elif 'SC' in satellite: eventInfo['satellite_ID'] = 'DMSP-18' eventInfo['satellite_family'] = 'dmsp' familyTitle = 'DMSP-18' elif 'SD' in satellite: eventInfo['satellite_ID'] = 'DMSP-19' eventInfo['satellite_family'] = 'dmsp' familyTitle = 'DMSP-19' elif 'S9' in satellite: eventInfo['satellite_ID'] = 'DMSP-15' eventInfo['satellite_family'] = 'dmsp' familyTitle = 'DMSP-15' instrument = fileParts[1] if 'HIR' in instrument: eventInfo['instrument'] = 'hirs' eventInfo['title'] = familyTitle + \ ' High Resolution Infrared Radiation Sounder' elif 'AMAX' in instrument: eventInfo['instrument'] = 'amsu' eventInfo['title'] = familyTitle + \ ' Advanced Microwave Sounder' elif 'FRAC' in instrument and 'METOP' in dirName: eventInfo['instrument'] = 'avhrr' eventInfo['title'] = familyTitle + \ ' Half Orbit 1km Advanced High Resolution Radiometer' elif 'CLAV' in dirName: eventInfo['instrument'] = 'avhrr' if 'GAC' in dirName: eventInfo['title'] = familyTitle + \ ' Global 4km Advanced High Resolution Radiometer ' elif 'FRAC' in dirName: eventInfo['title'] = familyTitle + \ ' Half Orbit 1km Advanced High Resolution Radiometer' else: eventInfo['title'] = familyTitle + \ ' Advanced High Resolution Radiometer' elif 'MHS' in instrument: eventInfo['instrument'] = 'mhs' eventInfo['title'] = familyTitle + \ ' Microwave Humidity Sounder' elif 'DCS' in instrument: eventInfo['instrument'] = 'argos' eventInfo['title'] = familyTitle + \ ' Argos Data Collection System' elif 'SSMI' in dirName: if 'SDIB' in instrument: eventInfo['instrument'] = 'ssmi' eventInfo['title'] = familyTitle + \ ' Special Sensor Microwave Imager/Sounder' elif 'SDLB' in instrument: eventInfo['instrument'] = 'ssmi' eventInfo['title'] = familyTitle + \ ' Special Sensor Microwave Sounder Lower Atomosphere' elif 'SDUB' in instrument: eventInfo['instrument'] = 'ssmi' eventInfo['title'] = familyTitle + \ ' Special Sensor Microwave Sounder Upper Atomosphere' elif 'TDRN' in instrument: eventInfo['instrument'] = 'ssmi' eventInfo['title'] = familyTitle + \ ' Special Sensor Microwave Imager/Sonder Temperature Data Record' elif 'TDRR' in instrument: eventInfo['instrument'] = 'ssmi' eventInfo['title'] = familyTitle + \ ' Special Sensor Microwave Imager Temperature Data Record' elif 'SDR' in instrument: eventInfo['instrument'] = 'ssmi' eventInfo['title'] = familyTitle + \ ' Special Sensor Microwave Sounder' elif 'SDEB' in instrument: eventInfo['instrument'] = 'ssmi' eventInfo['title'] = familyTitle + \ ' Special Sensor Microwave Sounder' elif 'SDEB' in instrument: eventInfo['instrument'] = 'ssmi' eventInfo['title'] = familyTitle + \ ' Special Sensor Microwave Sounder' else: eventInfo['instrument'] = 'ssmi' elif 'GHR' in instrument: eventInfo['instrument'] = 'avhrr' eventInfo['title'] = familyTitle + \ ' Global 4km Advanced High Resolution Radiometer' elif 'HRPT' in instrument: eventInfo['instrument'] = 'avhrr' eventInfo['title'] = familyTitle + \ ' High Resolution Picture Transmission Advanced High Resolution Radiometer' try: startDayObj = datetime.datetime.strptime(fileParts[3], 'D%y%j') except Exception as e: LOG.error('invalid start day ' + fileParts[3]) try: startTimeObj = datetime.datetime.strptime(fileParts[4], 'S%H%M') except Exception as e: LOG.error('invalid start time ' + fileParts[3]) eventInfo['start_time'] = datetime.datetime.strftime(startDayObj, '%Y-%m-%d ') + \ datetime.datetime.strftime(startTimeObj, '%H:%M:%S.0') try: endDayObj = datetime.datetime.strptime(fileParts[3], 'D%y%j') except Exception as e: LOG.error('invalid start day ' + fileParts[3]) try: endTimeObj = datetime.datetime.strptime(fileParts[5], 'E%H%M') except Exception as e: LOG.error('invalid start time ' + fileParts[3]) if endTimeObj < startTimeObj: endDayObj = endDayObj + datetime.timedelta(days=+1) eventInfo['end_time'] = datetime.datetime.strftime(endDayObj, '%Y-%m-%d ') + \ datetime.datetime.strftime(endTimeObj, '%H:%M:%S.0') # startDayObj = datetime.datetime.strptime(fileParts[3], 'D%y%j') # startTimeObj = datetime.datetime.strptime(fileParts[4], 'S%H%M') # eventInfo['start_time'] = datetime.datetime.strftime(startDayObj, '%Y-%m-%d ') + \ # datetime.datetime.strftime(startTimeObj, '%H:%M:%S.0') # endDayObj = datetime.datetime.strptime(fileParts[3], 'D%y%j') # endTimeObj = datetime.datetime.strptime(fileParts[5], 'E%H%M') # if endTimeObj < startTimeObj: # endDayObj = endDayObj + datetime.timedelta(days=+1) # eventInfo['end_time'] = datetime.datetime.strftime(endDayObj, '%Y-%m-%d ') + \ # datetime.datetime.strftime(endTimeObj, '%H:%M:%S.0') acquisitionSource = fileParts[7] if 'CF' in acquisitionSource: eventInfo['acquisition_source'] = 'Cape Ferguson, Queensland, Australia' elif 'DU' in acquisitionSource: eventInfo['acquisition_source'] = 'Dundee, Scotland, UK' elif 'EB' in acquisitionSource: eventInfo['acquisition_source'] = 'Ewa Beach, Oahu, Hawaii' elif 'GC' in acquisitionSource: eventInfo['acquisition_source'] = 'Fairbanks, Alaska, USA' elif 'HO' in acquisitionSource: eventInfo['acquisition_source'] = 'Honolulu, Hawaii, USA' elif 'MI' in acquisitionSource: eventInfo['acquisition_source'] = 'Miami, Florida, USA' elif 'MM' in acquisitionSource: eventInfo['acquisition_source'] = 'McMurdo, Antarctica, USA' elif 'MO' in acquisitionSource: eventInfo['acquisition_source'] = 'Monterey, California, USA' elif 'SF' in acquisitionSource: eventInfo['acquisition_source'] = 'Sioux Falls, South Dakota, USA' elif 'SN' in acquisitionSource: eventInfo['acquisition_source'] = 'Svalbard, Norway' elif 'SO' in acquisitionSource: eventInfo['acquisition_source'] = 'Suitland, Maryland, USA' elif 'SV' in acquisitionSource: eventInfo['acquisition_source'] = 'Arctic Circle, Svalbard, Norway' elif 'WE' in acquisitionSource: eventInfo['acquisition_source'] = 'Western Europe, Lannion, France' elif 'WI' in acquisitionSource: eventInfo['acquisition_source'] = 'Wallops Island, Virginia, USA' return eventInfo def init_ascat(incomingFile): LOG = logging.getLogger(__name__) eventInfo = {} eventInfo['status'] = True dirName = os.path.dirname(incomingFile) baseName = os.path.basename(incomingFile) try: fileParts = baseName.split('_') except Exception as e: LOG.error('Failed to split fileParts ' + baseName) LOG.error(str(e)) eventInfo['status'] = False return eventInfo eventInfo['server_ip'] = 'dsserve4.ssec.wisc.edu' eventInfo['medium'] = 'file' eventInfo['server_type'] = 'realtime' eventInfo['satellite_family'] = '' eventInfo['instrument'] = '' eventInfo['server_type'] = 'realtime' eventInfo['path'] = incomingFile eventInfo['message_type'] = 'image' eventInfo['status'] = 'complete' eventInfo['start_time'] = '' eventInfo['satellite_ID'] = '' eventInfo['band'] = '' eventInfo['data_type'] = '' eventInfo['wavelength'] = '' eventInfo['coverage'] = '' eventInfo['title'] = '' eventInfo['format'] = 'native' eventInfo['acquisition_source'] = '' try: if 'nc' in fileParts[-1]: eventInfo['format'] = 'ncdf' elif 'h5' or 'hdf5' in fileParts[-1]: eventInfo['format'] = 'hdf' except Exception as e: LOG.error('Failed to check for extention') LOG.error(str(e)) satellite = fileParts[3] if 'metopa' in satellite: eventInfo['satellite_ID'] = satellite[0:1].upper() + satellite[1:5] + '-' + '2' elif 'metopb' in satellite: eventInfo['satellite_ID'] = satellite[0:1].upper() + satellite[1:5] + '-' + '1' elif 'metopc' in satellite: eventInfo['satellite_ID'] = satellite[0:1].upper() + satellite[1:5] + '-' + '3' eventInfo['satellite_family'] = 'metop' eventInfo['instrument'] = 'ascat' eventInfo['title'] = 'Advanced Scatterometer' startDayObj = datetime.datetime.strptime(fileParts[1], '%Y%m%d') startTimeObj = datetime.datetime.strptime(fileParts[2], '%H%M%S') eventInfo['start_time'] = datetime.datetime.strftime(startDayObj, '%Y-%m-%d ') + \ datetime.datetime.strftime(startTimeObj, '%H:%M:%S.0') eventInfo['end_time'] = '' dataType = baseName.split('.')[1] eventInfo['data_type'] = dataType.replace('_', ' ') return eventInfo def init_iasi(incomingFile): LOG = logging.getLogger(__name__) eventInfo = {} eventInfo['status'] = True dirName = os.path.dirname(incomingFile) baseName = os.path.basename(incomingFile) try: fileParts = baseName.split('_') except Exception as e: LOG.error('Failed to split fileParts ' + baseName) LOG.error(str(e)) eventInfo['status'] = False return eventInfo eventInfo['server_ip'] = 'dsserve4.ssec.wisc.edu' eventInfo['medium'] = 'file' eventInfo['server_type'] = 'realtime' eventInfo['satellite_family'] = '' eventInfo['instrument'] = '' eventInfo['server_type'] = 'realtime' eventInfo['path'] = incomingFile eventInfo['message_type'] = 'image' eventInfo['status'] = 'complete' eventInfo['start_time'] = '' eventInfo['satellite_ID'] = '' eventInfo['band'] = '' eventInfo['data_type'] = '' eventInfo['wavelength'] = '' eventInfo['coverage'] = '' eventInfo['title'] = '' eventInfo['format'] = 'native' eventInfo['acquisition_source'] = '' try: if 'nc' in fileParts[-1]: eventInfo['format'] = 'ncdf' elif 'h5' or 'hdf5' in fileParts[-1]: eventInfo['format'] = 'hdf' except Exception as e: LOG.error('Failed to check for extention') LOG.error(str(e)) # IASI_xxx_1C_M02_20210603075959Z_20210603080255Z_N_O_20210603093846Z__20210603094241 satellite = fileParts[3] eventInfo['satellite_family'] = 'metop' if '01' in satellite: eventInfo['satellite_ID'] = 'MetOp-1' elif '02' in satellite: eventInfo['satellite_ID'] = 'MetOp-2' elif '03' in satellite: eventInfo['satellite_ID'] = 'MetOp-3' eventInfo['instrument'] = 'iasi' eventInfo['title'] = eventInfo['satellite_ID'] + \ ' Infrared Atmospheric Sounding Interferometer' startTimeObj = datetime.datetime.strptime(fileParts[4], '%Y%m%d%H%M%SZ') eventInfo['start_time'] = datetime.datetime.strftime(startTimeObj, '%Y-%m-%d %H:%M:%S.0') endTimeObj = datetime.datetime.strptime(fileParts[5], '%Y%m%d%H%M%SZ') eventInfo['end_time'] = datetime.datetime.strftime(endTimeObj, '%Y-%m-%d %H:%M:%S.0') return eventInfo def init_mirs(incomingFile): LOG = logging.getLogger(__name__) eventInfo = {} eventInfo['status'] = True dirName = os.path.dirname(incomingFile) baseName = os.path.basename(incomingFile) try: fileParts = baseName.split('_') except Exception as e: LOG.error('Failed to split fileParts ' + baseName) LOG.error(str(e)) eventInfo['status'] = False return eventInfo eventInfo['server_ip'] = 'dsserve4.ssec.wisc.edu' eventInfo['medium'] = 'file' eventInfo['server_type'] = 'realtime' eventInfo['satellite_family'] = '' eventInfo['instrument'] = '' eventInfo['server_type'] = 'realtime' eventInfo['path'] = incomingFile eventInfo['message_type'] = 'image' eventInfo['status'] = 'complete' eventInfo['start_time'] = '' eventInfo['satellite_ID'] = '' eventInfo['band'] = '' eventInfo['data_type'] = '' eventInfo['wavelength'] = '' eventInfo['coverage'] = '' eventInfo['title'] = '' eventInfo['format'] = 'native' eventInfo['acquisition_source'] = '' familyTitle = '' try: if 'nc' in fileParts[-1]: eventInfo['format'] = 'ncdf' elif 'h5' or 'hdf5' in fileParts[-1]: eventInfo['format'] = 'hdf' except Exception as e: LOG.error('Failed to check for extention') LOG.error(str(e)) # /data/noaa/20210602/MIRS/MIRS-IMG-HIGHRES/NPR-MIRS-IMG_v11r4_f17_s202106021755000_e202106021950000_c202106022054580.nc satellite = fileParts[2] # NPR-MIRS-SND_v11r4_gpm_s202106022350180_e202106022355170_c202106030037370.nc startTimeObj = datetime.datetime.strptime(fileParts[3], 's%Y%m%d%H%M%S%f') eventInfo['start_time'] = datetime.datetime.strftime(startTimeObj, '%Y-%m-%d %H:%M:%S.0') endTimeObj = datetime.datetime.strptime(fileParts[4], 'e%Y%m%d%H%M%S%f') eventInfo['end_time'] = datetime.datetime.strftime(endTimeObj, '%Y-%m-%d %H:%M:%S.0') if 'f17' in satellite: eventInfo['satellite_ID'] = 'dmsp17' eventInfo['satellite_family'] = 'dmsp' familyTitle = 'DMSP-17' elif 'f18' in satellite: eventInfo['satellite_ID'] = 'dmsp18' eventInfo['satellite_family'] = 'dmsp' familyTitle = 'DMSP-18' elif 'n18' in satellite: eventInfo['satellite_ID'] = 'n18' eventInfo['satellite_family'] = 'noaa-klm' familyTitle = 'NOAA-18' elif 'n19' in satellite: eventInfo['satellite_ID'] = 'n19' eventInfo['satellite_family'] = 'noaa-klm' familyTitle = 'NOAA-19' elif 'ma1' in satellite: eventInfo['satellite_ID'] = 'MetOp-1' eventInfo['satellite_family'] = 'metop' familyTitle = 'METOP-A' elif 'ma2' in satellite: eventInfo['satellite_ID'] = 'MetOp-2' eventInfo['satellite_family'] = 'metop' familyTitle = 'METOP-B' elif 'ma3' in satellite: eventInfo['satellite_ID'] = 'MetOp-3' eventInfo['satellite_family'] = 'metop' familyTitle = 'METOP-C' elif 'atm' in satellite: eventInfo['satellite_ID'] = 'snpp' eventInfo['satellite_family'] = 'jpss' familyTitle = 'SNPP' elif 'gpm' in satellite: eventInfo['satellite_ID'] = 'composite' eventInfo['satellite_family'] = 'satellite' familyTitle = 'GPM' eventInfo['instrument'] = 'mirs' if 'SND' in baseName: eventInfo['title'] = familyTitle + \ ' Microwave Integrated Retrieval System Sounder' else: eventInfo['title'] = familyTitle + \ ' Microwave Integrated Retrieval System Imager' return eventInfo def publish_message(publishInfo): import logging.handlers import traceback as tb import socket import json LOG = logging.getLogger(__name__) try: publishInfo['server_ip'] = socket.gethostname() except Exception as e: LOG.error(' could not create server_ip ') LOG.error(str(e)) publishInfo['__injector_script__'] = os.environ['SCRIPT'] try: payloadMessage = json.dumps(publishInfo) except Exception as e: LOG.info('json dump failed') message = 'Error: ' + str(e) LOG.error(message) return False # # publish actual message # satellite_type = 'leo' satellite_family = publishInfo['satellite_family'].lower() if '-' in publishInfo['satellite_ID']: splitID = publishInfo['satellite_ID'].split('-') satellite_ID = splitID[0][0:1].lower() + str(splitID[1]) else: satellite_ID = publishInfo['satellite_ID'].lower() satellite_instrument = publishInfo['instrument'].lower() medium = publishInfo['medium'].lower() server_type = publishInfo['server_type'].lower() format = publishInfo['format'] classification = publishInfo['message_type'].lower() status = publishInfo['status'].lower() keys = (satellite_type, satellite_family, satellite_ID, satellite_instrument, medium, server_type, format, classification, status) for key in keys: if len(str(key)) == 0: LOG.error(' found bad key ' + publishInfo['path']) routing_key = '.'.join(keys) connectionParameters = open_rabbitmq_connection(os.environ['PRIMARY_MQ_SERVER']) channel = connectionParameters['channel'] try: channel.basic_publish(exchange=connectionParameters['exchange'], routing_key=routing_key, body=payloadMessage, properties=connectionParameters['properties'] ) except Exception as e: message = 'Error: ' + str(e) LOG.error('failed to publish message: ') LOG.error(message) LOG.error(routing_key) LOG.error(payloadMessage) tb.print_exc() return False message = 'Published message ' + satellite_ID + ' ' + publishInfo['data_type'] + ' ' + publishInfo['start_time'] + \ ' ' + classification + ' ' + status + ' ' + publishInfo['title'] + ' ' + publishInfo['server_ip'] +\ ' ' + os.environ['PRIMARY_MQ_SERVER'] LOG.debug(message) message = routing_key LOG.debug(message) connectionParameters = open_rabbitmq_connection(os.environ['SECONDARY_MQ_SERVER']) if not connectionParameters: LOG.error('failed to create connection') return False channel = connectionParameters['channel'] try: channel.basic_publish(exchange=connectionParameters['exchange'], routing_key=routing_key, body=payloadMessage, properties=connectionParameters['properties'] ) except Exception as e: message = 'Error: ' + str(e) LOG.error('failed to publish message: ') LOG.error(message) LOG.error(routing_key) LOG.error(payloadMessage) tb.print_exc() return False message = 'Published message ' + satellite_ID + ' ' + publishInfo['start_time'] + \ ' ' + classification + ' ' + status + ' ' + publishInfo['title'] + ' ' + publishInfo['server_ip'] + \ ' ' + os.environ['SECONDARY_MQ_SERVER'] LOG.debug(message) message = routing_key LOG.debug(message) return True def open_rabbitmq_connection(mqServer): import logging.handlers import ast import pika LOG = logging.getLogger(__name__) # # open connection to rabbitmq # rabbitmqConfigFile = os.path.join(os.environ['ADMIN_DIR'], 'rabbitmq.conf') try: fileID = open(rabbitmqConfigFile, 'r') except Exception as e: message = 'Error: ' + str(e) LOG.error(message) return False rabbitmqParam = {} for lines in fileID: lines = lines.rstrip() param = lines.split(' = ') rabbitmqParam[param[0]] = ast.literal_eval(param[1]) try: credentials = pika.PlainCredentials(rabbitmqParam['rabbitmq_user'], rabbitmqParam['rabbitmq_pass']) except Exception as e: message = 'Error: ' + str(e) LOG.error(message) LOG.error('failed credentials') return False try: conn_params = pika.ConnectionParameters(host=mqServer, credentials=credentials) except Exception as e: message = 'Error: ' + str(e) LOG.error(message) LOG.error('failed connection parameter') return False try: connection = pika.BlockingConnection(conn_params) except Exception as e: message = 'Error: ' + str(e) LOG.error(message) LOG.error('failed blocking connection') return False try: channel = connection.channel() except Exception as e: message = 'Error: ' + str(e) LOG.error(message) LOG.error('failed connection') return False try: properties = pika.BasicProperties(delivery_mode=2) except Exception as e: message = 'Error: ' + str(e) LOG.error(message) LOG.error('failed Basic Properties') return False # publishProperties = {} publishProperties = dict( exchange=rabbitmqParam['rabbitmq_exchange'], properties=properties, channel=channel ) return publishProperties def create_rotating_log(): import logging.handlers LOG = logging.getLogger(__name__) # # setup logging # outLogFile = os.path.join(os.environ['LOG_DIR'], 'noaa-leo-event-processing.log') if outLogFile is None: return logFormat = '%(asctime)s - %(levelname)s - %(message)s' logger = logging.getLogger() logger.setLevel(logging.DEBUG) logging.getLogger('pika').propagate = False handler = logging.handlers.RotatingFileHandler(outLogFile, maxBytes=100000000, backupCount=5) formatter = logging.Formatter(logFormat, datefmt='%m/%d/%Y %H:%M:%S ') handler.setFormatter(formatter) logger.addHandler(handler) return True if __name__ == '__main__': import sys import os import socket hostName = socket.gethostname() scriptName = sys.argv[0] inject_script = 'oper@' + hostName + ':' + scriptName os.environ['SCRIPT'] = inject_script main(sys.argv)