def __init__(self, msgIn, params=[], extendedformat=None): msg = None if not extendedformat: print( "PROGRAMMING ERROR, it to remind me, this will never occur in real life" ) if not is_array(params): params = [str(params)] prm = None if bibutils.is_array(params): prm = bibutils.array2Dict(params, "P") prm["P0"] = current_user() if isinstance(msgIn, dict): msg = bibutils.dict2obj(msgIn) else: if type(msgIn) == bibutils.dict2obj: msg = msgIn self.type = "ERROR" msgstr = "#UNDEF#_ID" if msg: import re self.type = '?' if msg.typemsg in TYPE_MSG_CONV: self.type = TYPE_MSG_CONV[msg.typemsg] msgstr = msg.lbc.replace("%", "$") msgstr = re.sub(r"\$(\d)", r"$P\1", msgstr) try: self.msgstr = msgstr if prm: self.msgstr = Template(msgstr).safe_substitute(prm) msgIn["flbc"] = self.msgstr extra = _getExtra(msgIn) self.msgstr = extendedformat % extra except KeyError: err = str(sys.exc_info()[1]) pass except Exception: err = str(sys.exc_info()[1]) pass
def __init__(self,msgIn,params=[],extendedformat=None): msg=None if not extendedformat: print ("PROGRAMMING ERROR, it to remind me, this will never occur in real life") if not is_array(params): params=[str(params)] prm = None if bibutils.is_array(params): prm = bibutils.array2Dict(params,"P") prm["P0"]=current_user() if isinstance(msgIn, dict): msg=bibutils.dict2obj(msgIn) else: if type(msgIn) ==bibutils.dict2obj: msg=msgIn self.type = "ERROR" msgstr = "#UNDEF#_ID" if msg : import re self.type = '?' if msg.typemsg in TYPE_MSG_CONV: self.type = TYPE_MSG_CONV[msg.typemsg] msgstr = msg.lbc.replace("%","$") msgstr = re.sub(r"\$(\d)",r"$P\1",msgstr) try: self.msgstr = msgstr if prm: self.msgstr = Template(msgstr).safe_substitute(prm) msgIn["flbc"] = self.msgstr extra=_getExtra(msgIn) self.msgstr = extendedformat % extra except KeyError : err = str(sys.exc_info()[1]) pass except Exception : err = str(sys.exc_info()[1]) pass
def __init__(self,confs=None,msgconf=None,logformat=LOGFORMAT,extendedformat=EXTENDEDFORMAT,quiet=False): global loggerInstNumber loggerInstNumber+=1 self.instNumber=loggerInstNumber self.logformat = logformat self.quiet=quiet self.extendedformat=extendedformat _msgconf=msgconf if not msgconf: if "BIB_MSGCONF_PATH" in os.environ: BIB_MSGCONF_PATH=os.environ["BIB_MSGCONF_PATH"] _msgconf = loadMsgConf(BIB_MSGCONF_PATH) else: print ("#### FATAL ERROR : ###\nNo logging configuration found and missing BIB_MSGCONF_PATH environment variable") exit(0) else: if not isinstance(msgconf, bibutils.dict2obj): if isinstance(msgconf, dict): _msgconf=bibutils.dict2obj(msgconf) _confs=confs if not isinstance(confs, dict) : if "BIB_LOGCONF_PATH" in os.environ: BIB_LOGCONF_PATH=os.environ["BIB_LOGCONF_PATH"] _confs = loadMsgConf(BIB_LOGCONF_PATH) else: print ("#### FATAL ERROR : ###\nNo logging configuration found and missing BIB_MSGCONF_PATH environment variable") exit(0) else: if not isinstance(confs, bibutils.dict2obj): _confs=bibutils.dict2obj(confs) if len ( sys.argv ) > 1: log_dir = "%s/%s" % ( os.environ['EDC_LOG'] , sys.argv[1] ) else: log_dir = os.environ['EDC_LOG'] if "singlefile" in _confs: if _confs["singlefile"]: self.singlefile = "%s/%s" % (log_dir,_confs["singlefile"]) self.createdir(self.singlefile) self.dbgfile=self.singlefile self.errfile=self.singlefile self.infofile=self.singlefile else: if "multi-dbgfile" in _confs: if _confs["multi-dbgfile"]: self.dbgfile = "%s/%s" % (log_dir,_confs["multi-dbgfile"]) self.createdir(self.dbgfile) if "multi-errfile" in _confs: if _confs["multi-errfile"]: self.errfile = "%s/%s" % (log_dir,_confs["multi-errfile"]) self.createdir(self.errfile) if "multi-infofile" in _confs: if _confs["multi-infofile"]: self.infofile = "%s/%s" % (log_dir,_confs["multi-infofile"]) self.createdir(self.infofile) if "level" in _confs: if _confs["level"] in LEVELS: if LEVELS[_confs["level"]]: self.level=LEVELS[_confs["level"]] if "rotate-maxBytes" in _confs: if _confs["rotate-maxBytes"]: self.maxBytes=int(_confs["rotate-maxBytes"]) if "rotate-backupCount" in _confs: if _confs["rotate-backupCount"]: self.backupCount=int(_confs["rotate-backupCount"]) if "logInConsole" in _confs: if _confs.logInConsole: self.logInConsole=int(_confs.logInConsole) if not _msgconf : raise BibBadConfException("_msgconf null, Messages' file is incorrect") if not _msgconf : raise BibBadConfException("_msgconf null, Messages' file is incorrect") self.msgconf = _msgconf if not 'BIB_DBG_DEFAULT_MESSAGE' in self.msgconf: raise BibBadConfException("BIB_DBG_DEFAULT_MESSAGE not found, Messages' file is incorrect") self.msgconf = _msgconf
def loadMsgConf(path): jsonconf = bibutils.getObjectFromJson(path) conf=bibutils.dict2obj(jsonconf) return conf
def __init__(self, confs=None, msgconf=None, logformat=LOGFORMAT, extendedformat=EXTENDEDFORMAT, quiet=False): global loggerInstNumber loggerInstNumber += 1 self.instNumber = loggerInstNumber self.logformat = logformat self.quiet = quiet self.extendedformat = extendedformat _msgconf = msgconf if not msgconf: if "BIB_MSGCONF_PATH" in os.environ: BIB_MSGCONF_PATH = os.environ["BIB_MSGCONF_PATH"] _msgconf = loadMsgConf(BIB_MSGCONF_PATH) else: print( "#### FATAL ERROR : ###\nNo logging configuration found and missing BIB_MSGCONF_PATH environment variable" ) exit(0) else: if not isinstance(msgconf, bibutils.dict2obj): if isinstance(msgconf, dict): _msgconf = bibutils.dict2obj(msgconf) _confs = confs if not isinstance(confs, dict): if "BIB_LOGCONF_PATH" in os.environ: BIB_LOGCONF_PATH = os.environ["BIB_LOGCONF_PATH"] _confs = loadMsgConf(BIB_LOGCONF_PATH) else: print( "#### FATAL ERROR : ###\nNo logging configuration found and missing BIB_MSGCONF_PATH environment variable" ) exit(0) else: if not isinstance(confs, bibutils.dict2obj): _confs = bibutils.dict2obj(confs) if "singlefile" in _confs: if _confs["singlefile"]: self.singlefile = _confs["singlefile"] self.createdir(self.singlefile) self.dbgfile = self.singlefile self.errfile = self.singlefile self.infofile = self.singlefile else: if "multi-dbgfile" in _confs: if _confs["multi-dbgfile"]: self.dbgfile = _confs["multi-dbgfile"] self.createdir(self.dbgfile) if "multi-errfile" in _confs: if _confs["multi-errfile"]: self.errfile = _confs["multi-errfile"] self.createdir(self.errfile) if "multi-infofile" in _confs: if _confs["multi-infofile"]: self.infofile = _confs["multi-infofile"] self.createdir(self.infofile) if "level" in _confs: if _confs["level"] in LEVELS: if LEVELS[_confs["level"]]: self.level = LEVELS[_confs["level"]] if "rotate-maxBytes" in _confs: if _confs["rotate-maxBytes"]: self.maxBytes = int(_confs["rotate-maxBytes"]) if "rotate-backupCount" in _confs: if _confs["rotate-backupCount"]: self.backupCount = int(_confs["rotate-backupCount"]) if "logInConsole" in _confs: if _confs.logInConsole: self.logInConsole = int(_confs.logInConsole) if not _msgconf: raise BibBadConfException( "_msgconf null, Messages' file is incorrect") if not _msgconf: raise BibBadConfException( "_msgconf null, Messages' file is incorrect") self.msgconf = _msgconf if not 'BIB_DBG_DEFAULT_MESSAGE' in self.msgconf: raise BibBadConfException( "BIB_DBG_DEFAULT_MESSAGE not found, Messages' file is incorrect" ) self.msgconf = _msgconf
def loadMsgConf(path): jsonconf = bibutils.getObjectFromJson(path) conf = bibutils.dict2obj(jsonconf) return conf
def loadfilterConf(path): if path: jsonconf = bibutils.getObjectFromJson(path) conf=bibutils.dict2obj(jsonconf) return conf return None