def __init__(self): # setting the Environment try: self.Env = Environment() self.Logging = Logging() self.Global = Global() self.Utility = Utility() self.initInfra = False self.configLoc = self.Env.getConfigLocation() self.bootStrapFile = self.getBootStrapFile() self.dbConfigData = {} self.daemonConfifData = {} self.schedulerConfigData = {} self.restApiConfigData = {} self.agentConfigData = {} #print(self.Env._Env__initData) #print(self.Env._Env__EnvDetails) print("Loading bootstrap config....................".ljust(50), end='') self.__loadBootStrapConfig() self.__loadSchema() # ensuring all needed lib is available print("Checking all required libraries................".ljust(50), end='') self.__validateAllLib() # ensure db is up and repository is abvailable print("Validating database............................".ljust(50), end='') self.__validateDb() # loading DB schema # populating json schema for database self.__loadDbJsonSchema() print("[OK - OS pid {pid}]".format(pid=self.getMyOsPid())) #self.db_dyna_sql = self.jsonSchema.get('Main').get('db_dyna_sql_call') #self.myModuleLogger.info ('Infrastructure started with os pid [{pid}]'.format(pid=os.getpid())) except Exception as err: exc_type, exc_value, exc_traceback = sys.exc_info() myErrorMessage = repr( traceback.format_exception(exc_type, exc_value, exc_traceback)) print('Error [{error}], terminating !!!'.format( error=myErrorMessage)) sys.exit(-1)
def __init__(self): # setting the environment try: self.env = Environment() self.__appCfgKey= 'APP_CONFIG' self.configLoc = self.getConfigLocation() self.bootStrapFile = self.getBootStrapFile() self.dbConfigData = {} self.schedulerConfigData = {} self.restApiConfigData = {} self.agentConfigData = {} #print(self.env._Environment__initData) #print(self.env._Environment__envDetails) print("Validating bootstrap config....................".ljust(50),end='') self.validateBootStrapConfig() # ensuring all needed lib is available print("Checking all required libraries................".ljust(50),end='') self.validateAllLib() # ensure db is up and repository is abvailable print("Validating database............................".ljust(50),end='') self.validateDb() # vaidating scheduler config print("Validating scheduler config file...............".ljust(50),end='') self.validaterScheduleCfgFile() print("[OK - OS pid {pid}]".format(pid=os.getpid())) #self.myModuleLogger.info ('Infrastructure started with os pid [{pid}]'.format(pid=os.getpid())) except Exception as err: exc_type, exc_value, exc_traceback = sys.exc_info() myErrorMessage = repr(traceback.format_exception(exc_type, exc_value, exc_traceback)) print ('Error [{error}], terminating !!!'.format(error=myErrorMessage)) sys.exit(-1)
def __init__(self): try: #print('initializing env 1') self.env = Environment() self.globals = Global() self.util = Utility() #self.logging = Logging() self.configLoc = self.env.appCfgLoc self.bootStrapFile = os.path.join(self.configLoc, self.globals.bootStrapFile) if not self.bootStrapFile: print('error: port8-infra10001, bootstrap error !!!') sys.exit(-1) self.dbConfigData = {} self.daemonConfifData = {} self.schedulerConfigData = {} self.restApiConfigData = {} self.agentConfigData = {} print("Loading bootstrap config....................".ljust(50), end='') self.__loadBootStrapConfig() #self.jsonSchema = JsonRef.replace_refs(self.__bootStrapData['Main']) #self.__loadSchema() #self.jsonSchemaConfigData # ensuring all needed lib is available print("Checking all required libraries................".ljust(50), end='') self.__validateAllLib() print("[infra started with OS pid {pid}]".format( pid=self.util.getMyOsPid())) except Exception as err: exc_type, exc_value, exc_traceback = sys.exc_info() myErrorMessage = repr( traceback.format_exception(exc_type, exc_value, exc_traceback)) print('Error [{error}], terminating !!!'.format( error=myErrorMessage)) sys.exit(-1)
def __init__(self): try: ''' if not infraType or infraType not in ['REST','SCHEDULE','DAEMON']: print('expectig valid infra type REST/SCHEDULE/DAMEON got {got}, exiting !!!'.format(got = infraType)) sys.exit(-1) ''' self.env = Environment() self.globals = Global() self.util = Utility() self.logging = Logging() self.configLoc = self.env.appCfgLoc #print(self.configLoc) self.bootStrapFile = os.path.join(self.configLog, self.globals.bootStrapFile) if not self.bootStrapFile: print('error: port8-infra10001, bootstrap error !!!') sys.exit(-1) self.dbConfigData = {} self.daemonConfifData = {} self.schedulerConfigData = {} self.restApiConfigData = {} self.agentConfigData = {} #print(self.Env._Env__initData) #print(self.Env._Env__EnvDetails) print("Loading bootstrap config....................".ljust(50),end='') self.__loadBootStrapConfig() self.__loadSchema() # ensuring all needed lib is available print("Checking all required libraries................".ljust(50),end='') self.__validateAllLib() ''' self.Logger = \ self.logging.buildLoggingInfra(\ self.loggingConfigData,\ self.globals.LoggerName[infraType]['LogFile'], self.globals.LoggerName[infraType]['Name'] ) ''' #self.Logger.debug('this is test from Infrastructure') # ensure db is up and repository is abvailable #print("Validating database............................".ljust(50),end='') #self.__validateDb(infraType) #self.db = self.__getNewConnection() # loading DB schema # populating json schema for database ''' commenting follwoing line, will revisit later to implement jsonref for db self.__loadDbJsonSchema() ''' #print("Loading logging config.........................".ljust(50),end='') #self.logger = Logging(self.loggingConfigData) #logger print("[infra started with OS pid {pid}]".format(pid=self.getMyOsPid())) #self.db_dyna_sql = self.jsonSchema.get('Main').get('db_dyna_sql_call') #self.myModuleLogger.info ('Infrastructure started with os pid [{pid}]'.format(pid=os.getpid())) except Exception as err: exc_type, exc_value, exc_traceback = sys.exc_info() myErrorMessage = repr(traceback.format_exception(exc_type, exc_value, exc_traceback)) print ('Error [{error}], terminating !!!'.format(error=myErrorMessage)) sys.exit(-1)
def __init__(self): self.env = Environment() self.Global = Global() self.Utility = Utility()
class Infra(object, metaclass=Singleton): def __init__(self): # setting the Environment try: self.Env = Environment() self.Logging = Logging() self.Global = Global() self.Utility = Utility() self.initInfra = False self.configLoc = self.Env.getConfigLocation() self.bootStrapFile = self.getBootStrapFile() self.dbConfigData = {} self.daemonConfifData = {} self.schedulerConfigData = {} self.restApiConfigData = {} self.agentConfigData = {} #print(self.Env._Env__initData) #print(self.Env._Env__EnvDetails) print("Loading bootstrap config....................".ljust(50), end='') self.__loadBootStrapConfig() self.__loadSchema() # ensuring all needed lib is available print("Checking all required libraries................".ljust(50), end='') self.__validateAllLib() # ensure db is up and repository is abvailable print("Validating database............................".ljust(50), end='') self.__validateDb() # loading DB schema # populating json schema for database self.__loadDbJsonSchema() print("[OK - OS pid {pid}]".format(pid=self.getMyOsPid())) #self.db_dyna_sql = self.jsonSchema.get('Main').get('db_dyna_sql_call') #self.myModuleLogger.info ('Infrastructure started with os pid [{pid}]'.format(pid=os.getpid())) except Exception as err: exc_type, exc_value, exc_traceback = sys.exc_info() myErrorMessage = repr( traceback.format_exception(exc_type, exc_value, exc_traceback)) print('Error [{error}], terminating !!!'.format( error=myErrorMessage)) sys.exit(-1) def __loadBootStrapConfig(self): # read bootstrap cnfig file try: self.__bootStrapData = json.load(open(self.bootStrapFile)) if not self.__bootStrapData: print("Empty bootstrap data, terminating !!!") sys.exit(-1) #fi # validating if all modules config data is available myMissingModule = self.Utility.findMissingKeyInDict( self.__bootStrapData['Main']['Modules'], list(self.__bootStrapData['Main']['ModulesConfig'].keys())) if myMissingModule: print('Missing config information for module {0}'.format( myMissingModule)) sys.exit(-1) #extracting module config information self.dbConfigData = self.__bootStrapData['Main']['ModulesConfig'][ 'DB'][self.__bootStrapData['Main']['RepositoryDb']] self.schedulerConfigData = self.__bootStrapData['Main'][ 'ModulesConfig']['Scheduler'] self.loggingConfigData = self.__bootStrapData['Main'][ 'ModulesConfig']['Logging'] self.restApiConfigData = self.__bootStrapData['Main'][ 'ModulesConfig']['RestApi'] self.daemonConfigData = self.__bootStrapData['Main'][ 'ModulesConfig']['Daemon'] self.jsonSchemaConfigData = self.__bootStrapData['Main'][ 'ModulesConfig']['JsonSchema'] if (not self.dbConfigData): print('DB Configuration is empty') sys.exit(-1) if (not self.schedulerConfigData): print('Scheduler Configuration is empty') sys.exit(-1) if (not self.loggingConfigData): print('Loggine Configuration is empty') sys.exit(-1) if (not self.restApiConfigData): print('RestApi Configuration is empty') sys.exit(-1) if (not self.restApiConfigData): print('Daemon Configuration is empty') sys.exit(-1) if (not self.jsonSchemaConfigData): print('Json Schema Configuration is empty') sys.exit(-1) print("[OK]") except Exception as err: myErrorMessage = sys.exc_info()[1:], traceback.format_exc(limit=2) #myErrorMessage = self.Utility.extractError() print(myErrorMessage) #print("Error [{err}] loading bootstrap config data".format(err=err.message)) sys.exit(-1) #end validateBootStrapConfig def __loadSchema(self): # load json schema data and resolve the reference if used, this will be needed to validate user data if not self.Env.isFileExists( os.path.join(self.configLoc, self.jsonSchemaConfigData['configFile'])): print( 'Json Schema Configuration file {file} is missing !!!'.format( file=os.path.join(self.configLoc, self. jsonSchemaConfigData['configFile']))) sys.exit(-1) #fi #loading json schema file and resolving references if used in schema try: self.jsonSchema = JsonRef.replace_refs( json.load( open('/home/anil/app/src/com/port8/config/schema.json'))) except Exception as err: myErrorMessage = sys.exc_info()[1:], traceback.format_exc(limit=2) print(myErrorMessage) sys.exit(-1) #end def __validateAllLib(self): # Ensuring all required library as specified in bootStrap.json is installed try: for lib in self.__bootStrapData['Main']['Libraries']: if not self.isModuleInstalled(lib): #self.myModuleLogger.error('Lib {frmtLib} is not installed, Pls install it using <pip install {frmtLib}>'.format(frmtLib=lib)) print("[missing library {frmtLib}]".format(frmtLib=lib)) sys.exit(-1) #fi #end for print("[OK]") except Exception as err: exc_type, exc_value, exc_traceback = sys.exc_info() myErrorMessage = repr( traceback.format_exception(exc_type, exc_value, exc_traceback)) print('[Failed {err}]'.format(err=myErrorMessage)) sys.exit(-1) # end validateAllLib def isValidBootStrapData(self): if self.__bootStrapData: return True else: return False # end isValidBootStrapData def isValidLogger(self): if self.myModuleLogger: return True else: return False def getBootStrapFile(self): #print(self.Env._Env__bootStrapFileKey) return os.getenv(self.Env._Environment__bootStrapFileKey) #mybootStrapFile = os.getEnv[self.Env._Environment__bootStrapKey] def getAppName(self): return os.Environ['APP_NAME'] def getMyOsPid(self): # returns current OS pid return os.getpid() def getInfraLogger(self, infraArg): if infraArg == 'Scheduler': return self.SchedLogger elif infraArg == 'Daemon': return self.DaemonLogger elif infraArg == 'Rest': return self.RestLogger def isModuleInstalled(self, argLib): # returns existence of a library passed as an argument try: __import__('imp').find_module(argLib) return True except ImportError: #print('Missing library {lib}'.format(lib=argLib)) return False #end isModuleInstalled #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # method for DB #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ def __validateMySqlDB(self): self.dbLib = importlib.import_module('mysql.connector') # validate the db config file try: # connecting to database to ensure db is up db = self.dbLib.connect(**self.dbConfigData) # connection is successful, closing the connection db.close() # connection is successful print('[OK]') except mysql.connector.Error as err: if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: print("Something is wrong with your user name or password") elif err.errno == errorcode.ER_BAD_DB_ERROR: print("Database does not exist") else: print(err) ''' except Exception as err: exc_type, exc_value, exc_traceback = sys.exc_info() myErrorMessage = repr(traceback.format_exception(exc_type, exc_value, exc_traceback)) print('[Failed {err}]'.format(err=myErrorMessage)) sys.exit(-1) ''' # end validateMySqlDB def __validateDb(self): if self.__bootStrapData['Main']['RepositoryDb'] == "MySql": self.__validateMySqlDB() #end validateDb def __loadDbJsonSchema(self): self.dbSchema = self.jsonSchema.get('Main').get('db_schema').get( self.__bootStrapData['Main']['RepositoryDb']) def getNewConnection(self): try: db = self.dbLib.connect(**self.dbConfigData) dbCursor = db.cursor(dictionary=True, buffered=True) #dbCursor = db.cursor(buffered=True) return db, dbCursor except Exception as err: self.logger.critical( 'Error obtaining db connection using {}'.format( self.dbConfigData)) raise err def closeConnection(self, dbArg): if dbArg: dbArg.close() def isConnectionOpen(self, dbCursorArg): try: dbCursorArg.execute('select now()') return True except Exception as err: return False
class Infra(object, metaclass=Singleton): def __init__(self): # setting the environment try: self.env = Environment() self.__appCfgKey= 'APP_CONFIG' self.configLoc = self.getConfigLocation() self.bootStrapFile = self.getBootStrapFile() self.dbConfigData = {} self.schedulerConfigData = {} self.restApiConfigData = {} self.agentConfigData = {} #print(self.env._Environment__initData) #print(self.env._Environment__envDetails) print("Validating bootstrap config....................".ljust(50),end='') self.validateBootStrapConfig() # ensuring all needed lib is available print("Checking all required libraries................".ljust(50),end='') self.validateAllLib() # ensure db is up and repository is abvailable print("Validating database............................".ljust(50),end='') self.validateDb() # vaidating scheduler config print("Validating scheduler config file...............".ljust(50),end='') self.validaterScheduleCfgFile() print("[OK - OS pid {pid}]".format(pid=os.getpid())) #self.myModuleLogger.info ('Infrastructure started with os pid [{pid}]'.format(pid=os.getpid())) except Exception as err: exc_type, exc_value, exc_traceback = sys.exc_info() myErrorMessage = repr(traceback.format_exception(exc_type, exc_value, exc_traceback)) print ('Error [{error}], terminating !!!'.format(error=myErrorMessage)) sys.exit(-1) def isValidBootStrapData(self): if self.__bootStrapData: return True else: return False def isValidLogger(self): if self.myModuleLogger: return True else: return False def getBootStrapFile(self): #print(self.env._Environment__bootStrapFileKey) return os.getenv(self.env._Environment__bootStrapFileKey) #mybootStrapFile = os.getenv[self.env._Environment__bootStrapKey] def getConfigLocation(self): #print(os.getenv(''.join([os.environ['APP_NAME'],'_CONFIG']))) return os.getenv(''.join([os.environ['APP_NAME'],'_CONFIG'])) #end def getLoggingConfigFile(self): return os.path.join(self.configLoc, self.__bootStrapData['LoggingCfg']) # end getLoggingConfigFile def getAppName(self): return os.environ['APP_NAME'] def validateBootStrapConfig(self): # read bootstrap cnfig file #print(self.bootStrapFile) try: self.__bootStrapData = json.load(open(self.bootStrapFile)) print("[OK]") if not self.__bootStrapData: print("Empty bootstrap data, terminating !!!") sys.exit(-1) except Exception as err: print("Error [{err}] loading bootstrap config data".format(err=err.message)) sys.exit(-1) #end validateBootStrapConfig def isModuleInstalled(self, argLib): # returns existence of a library passed as an argument try: __import__('imp').find_module(argLib) return True except ImportError: #print('Missing library {lib}'.format(lib=argLib)) return False #end isModuleInstalled def validateAllLib(self): # Ensuring all required library as specified in bootStrap.json is installed try: for lib in self.__bootStrapData['Libraries']: if not self.isModuleInstalled(lib): #self.myModuleLogger.error('Lib {frmtLib} is not installed, Pls install it using <pip install {frmtLib}>'.format(frmtLib=lib)) print("[missing library {frmtLib}]".format(frmtLib=lib)) sys.exit(-1) #fi #end for print("[OK]") except Exception as err: exc_type, exc_value, exc_traceback = sys.exc_info() myErrorMessage = repr(traceback.format_exception(exc_type, exc_value, exc_traceback)) print('[Failed {err}]'.format(err=myErrorMessage)) sys.exit(-1) # end validateAllLib def validateMySqlDB(self): mySqlLib = importlib.import_module('pymysql') # validate the db config file try: self.dbConfigFile = self.__bootStrapData['DBConfigFile'] self.dbConfigFileWPath = os.path.join(self.getConfigLocation(), self.dbConfigFile) if not self.env.isFileExists(self.dbConfigFileWPath): print ("missing config file {cfgFile}, terminating !!!".format(cfgFile=self.dbConfigFileWPath)) sys.exit(-1) # fi self.dbConfigData = json.load(open(self.dbConfigFileWPath)) # checking if loading the file was successful if not self.dbConfigData: print ("[Empty db config file]") sys.exit(-1) #fi # constructing config data myDbConfig = \ { 'user': self.dbConfigData[self.__bootStrapData['RepositoryDb']]['DbUser'], 'password': self.dbConfigData[self.__bootStrapData['RepositoryDb']]['DbPasswd'], 'host': self.dbConfigData[self.__bootStrapData['RepositoryDb']]['DbHost'], 'db':self.dbConfigData[self.__bootStrapData['RepositoryDb']]['DbName'], } mySqlConnection = mySqlLib.connect(**myDbConfig) # connection is successful print('[OK]') except Exception as err: exc_type, exc_value, exc_traceback = sys.exc_info() myErrorMessage = repr(traceback.format_exception(exc_type, exc_value, exc_traceback)) print('[Failed {err}]'.format(err=myErrorMessage)) sys.exit(-1) # end validateMySqlDB def validateDb(self): if self.__bootStrapData['RepositoryDb'] == "MySql" : self.validateMySqlDB() #end validateDb def validaterScheduleCfgFile(self): # validating schduler config file try: self.schdulerConfigFile = self.__bootStrapData['SchedulerCfg'] self.schdulerConfigFileWPath = os.path.join(self.getConfigLocation(), self.schdulerConfigFile) if not self.env.isFileExists(self.schdulerConfigFileWPath): print ("missing config file {cfgFile}, terminating !!!".format(cfgFile=self.schdulerConfigFileWPath)) sys.exit(-1) # fi self.schedulerConfigData = json.load(open(self.schdulerConfigFileWPath)) if not self.schedulerConfigData: print('[Empty Scheduler config file]') #fi print('[OK]') except Exception as err: exc_type, exc_value, exc_traceback = sys.exc_info() myErrorMessage = repr(traceback.format_exception(exc_type, exc_value, exc_traceback)) print('[Failed {err}]'.format(err=myErrorMessage)) sys.exit(-1) def buildLoggingInfra(self, argLogCfgFile): # Logging utility, constructing dictionary object to be used by native logging module #print ("Constructing logging foundation") try: myLogPath = os.environ['LOG_LOC'] myAbsLogFile = os.path.basename(self.__bootStrapData['LogFile']) myLogFileWPath = os.path.join(myLogPath, myAbsLogFile) # check if logging config file is available if not self.env.isFileExists(argLogCfgFile): print("could not locate Logging Config file {cfgFile}, terminating !!!".format(cfgFile=argLogCdfgFile)) sys.exit(-1) #fi # reading current config file myLoggingConfig = json.load(open(argLogCdfgFile)) # Loading current configuration to logger's config file logging.config.dictConfig(myLoggingConfig) #print(myLoggingConfig) #myLogger = logging.getLogger('Port8') except Exception as err: print ("\n") print ("Error builidng logging infra using file {cfgFile}, terminating !!!".format(cfgFile=argLogCfgFile)) sys.exit(-1) '''
def __init__(self): # setting the environment try: self.env = Environment.Instance() self.__appCfgKey = 'APP_CONFIG' self.configLoc = self.getConfigLocation() #print(self.env._Environment__initData) #print(self.env._Environment__envDetails) print( "Starting infrastructure...........................".ljust(50), end='') # read bootstrap cnfig file self.bootStrapFile = self.getBootStrapFile() #print(self.bootStrapFile) try: self.__bootStrapData = json.load(open(self.bootStrapFile)) if not self.__bootStrapData: print("Empty bootstrap data, terminating !!!") sys.exit(-1) except Exception as err: print("Error [{err}] loading bootstrap config data".format( err=err.message)) # configuring logging myLogFile = self.buildLoggingInfra() print(myLogFile) myLogger = logging.getLogger('Port8') print(dir(myLogger)) self.myModuleLogger = logging.getLogger(__name__ + '.' + self.__class__.__name__) print(dir(self.myModuleLogger)) self.myModuleLogger.info( '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' ) self.myModuleLogger.info( 'Startig up {app} infrastructure .....'.format( app=self.getAppName())) self.myModuleLogger.info('Initializing ....') # configuring schedule # ensuring all needed lib is available self.myModuleLogger.info('Validating all required libraries') self.validateAllLib() # ensure db is up and repository is abvailable self.validateDb() print("[OK - OS pid {pid}]".format(pid=os.getpid())) print("logFile...........................".ljust(50) + "[{logfile}]".format(logfile=myLogFile)) self.myModuleLogger.info( 'Infrastructure started with os pid [{pid}]'.format( pid=os.getpid())) except Exception as err: exc_type, exc_value, exc_traceback = sys.exc_info() myErrorMessage = repr( traceback.format_exception(exc_type, exc_value, exc_traceback)) if self.isValidLogger(): self.myModuleLogger.info( 'An error {error} occurred, terminating'.format( error=myErrorMessage)) print('Error [{error}], terminating !!!'.format( error=myErrorMessage)) sys.exit(-1)
class Logging(object, metaclass=Singleton): def __init__(self): self.env = Environment() self.Global = Global() self.Utility = Utility() #myLogger = self.__buildLoggingInfra(argCfgFile, argLogFile, argLogger) #return myLogger def buildLoggingInfra(self, argConfig, argLogFile=None, argLogger='Default'): ''' Logging utility, constructing dictionary object to be used by native logging module Level: ++++++++++++++++++++ CRITICAL 50 ERROR 40 WARNING 30 INFO 20 DEBUG 10 NOTSET 0 ++++++++++++++++++++ ''' try: #validating parameter if (not argConfig): print("Missing reuired configuraton data !!!") sys.exit(-1) #fi myLogPath = self.env.getLogLocation() #print('LogPath',myLogPath) #myConfigFile = os.path.join(self.env.getConfigLocation(), os.path.basename(argCfgFile)) # check if logging config file is available #if not self.env.isFileExists(myConfigFile): # print("could not locate Logging Config file {cfgFile}, terminating !!!".format(cfgFile=myConfigFile)) # sys.exit(-1) #fi # reading current config file myLoggingConfig = self.Utility.getACopy(argConfig) # checking if we got valid logger name, if not will use default logger name "Console" if argLogger not in myLoggingConfig['loggers']: myLogger = self.Global.LoggerName[ self.Global.DefaultLoggerNameKey]['Name'] else: myLogger = argLogger #fi # will override logfile if passed as an argument also, set the directory as defined in LOG_LOC env variable if argLogFile: # will use the path as specified in LOG_PATH environment variable, any path specified in argument will be ignored myLogFile = os.path.basename(argLogFile) myLogFileWPath = os.path.join(myLogPath, myLogFile) else: myLogFileWPath = os.path.join( myLogPath, os.path.basename( myLoggingConfig['handlers']['file']['filename'])) #fi if not (myLogger == self.Global.DefaultLoggerNameKey): myLoggingConfig['handlers']['file'][ 'filename'] = myLogFileWPath # Loading current configuration to logger's config file logging.config.dictConfig(myLoggingConfig) #print('Logger',myLogger) return logging.getLogger(myLogger) except Exception as err: print("\n") exc_type, exc_value, exc_traceback = sys.exc_info() myErrorMessage = repr( traceback.format_exception(exc_type, exc_value, exc_traceback)) print( "Error [{err}] builidng logging infra using config [{cfg}], terminating !!!" .format(err=myErrorMessage, cfg=myLoggingConfig)) sys.exit(-1)