本文整理汇总了Python中log4py.Logger.get_formatstring方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.get_formatstring方法的具体用法?Python Logger.get_formatstring怎么用?Python Logger.get_formatstring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类log4py.Logger
的用法示例。
在下文中一共展示了Logger.get_formatstring方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from log4py import Logger [as 别名]
# 或者: from log4py.Logger import get_formatstring [as 别名]
class LoggingProducerUtils:
def __init__(self,parameterContainer, logLevel=log4py.LOGLEVEL_DEBUG, logTarget=LOGGER_PRODUCER_LOG_DIR):
if parameterContainer.getParamValue(PRINTER_TYPE) is not None:
self.__errorFileName = "%s" % (parameterContainer.getErrorFileName())
self.__logFileName = "%s/%s-%s.log" % (parameterContainer.getParamValue(TMP_DIR),parameterContainer.getParamValue(PRINTER_TYPE), parameterContainer.getParamValue(PRINTER_NAME))
else:
if parameterContainer.getParamValue(PARAM_DIR) is not None:
if os.access(parameterContainer.getFullPathJobDir(), os.W_OK) :
# Error/Log directory locally
self.__errorFileName = "%s/%s" % (parameterContainer.getFullPathJobDir(), parameterContainer.getErrorFileName())
self.__logFileName = "%s/%s.log" % (parameterContainer.getFullPathJobDir(), parameterContainer.getJobID())
else:
# Error/Log directory remotely
self.__errorFileName = "%s/%s" % (parameterContainer.getInputDir(), parameterContainer.getErrorFileName())
self.__logFileName = "%s/%s.log" % (parameterContainer.getInputDir(), parameterContainer.getJobID())
else:
self.__errorFileName = "%s/%s" % (LOG_DIRECTORY, parameterContainer.getErrorFileName())
self.__logFileName = "%s/%s.log" % (LOG_DIRECTORY, parameterContainer.getJobID())
### LOG4PY ###
self._log4py = Logger().get_instance(self)
self._jobid = parameterContainer.getJobID()
# Set target(s) according to configuration
if logTarget == LOGGER_JOBS_DIR and self.__logFileName is not None:
self.__log4pyFile = self.__logFileName
else:
# Log to the producer log directory using the OsEnv variable from producerjavastarter.py
#self.__log4pyFile = '/prod_data/sefas/data/traffic/log/producer_log4py_' + self.getLogFileTimestamp() +'.log'
self.__log4pyFile = LOG_DIRECTORY+'/producer_log4py_' + self.getLogFileTimestamp() +'.log'
self._log4py.set_target(self.__log4pyFile)
# Set time format
timeformat = "%Y-%m-%d %H:%M:%S "
self._log4py.set_time_format(timeformat)
# Set log format
self._log4py.set_formatstring(FMT_SEFAS)
# Set level from configuration file?
self._log4py.set_loglevel(logLevel)
# Set rotation
self._log4py.set_rotation(log4py.ROTATE_DAILY)
### END LOG4PY ###
def getLogFileTimestamp(self):
t = datetime.datetime.now();
return t.strftime("%Y%m%d")
# Wrap the log4py methods
def info(self, msg):
if self._jobid is not None:
self._log4py.info("[JOB_ID=" + self._jobid + "] %s" % msg)
else:
self._log4py.info("[NO JOB_ID] %s" % msg)
def error(self, msg, exceptionType=None, exceptionValue=None):
self._log4py.set_target(self.__errorFileName)
if self._jobid is not None:
self._log4py.error("[JOB_ID=" + self._jobid + "] %s" % msg)
else:
self._log4py.error("[NO JOB_ID] %s" % msg)
if exceptionType != None and exceptionValue != None:
type, values, tb = sys.exc_info()
traceback.print_exception(exceptionType, exceptionValue, tb)
if self._jobid is not None:
self._log4py.error("[JOB_ID=" + self._jobid + "] %s" % tb)
else:
self._log4py.error("[NO JOB_ID] %s" % tb)
# Finally write to regular log
self._log4py.set_target(self.__log4pyFile)
self._log4py.error(msg)
def debug(self, msg):
if self._jobid is not None:
self._log4py.debug("[JOB_ID=" + self._jobid + "] %s" % msg)
else:
self._log4py.debug("[NO JOB_ID] %s" % msg)
def warn(self, msg):
if self._jobid is not None:
self._log4py.warn("[JOB_ID=" + self._jobid + "] %s" % msg)
else:
self._log4py.warn("[NO JOB_ID=] %s" % msg)
def getFormatString(self):
self._log4py.get_formatstring()
def setFormatString(self, format):
self._log4py.set_formatstring(format)
# Wrap the loglevel and target
def setLogLevel(self, level):
self._log4py.set_loglevel(level)
def setLogTarget(self, target):
self._log4py.set_target(target)
#.........这里部分代码省略.........