当前位置: 首页>>代码示例>>Python>>正文


Python LogFile.close方法代码示例

本文整理汇总了Python中twisted.python.logfile.LogFile.close方法的典型用法代码示例。如果您正苦于以下问题:Python LogFile.close方法的具体用法?Python LogFile.close怎么用?Python LogFile.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.python.logfile.LogFile的用法示例。


在下文中一共展示了LogFile.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: emmit

# 需要导入模块: from twisted.python.logfile import LogFile [as 别名]
# 或者: from twisted.python.logfile.LogFile import close [as 别名]
 def emmit(self, event):
     if event.get("isDebug", False) and is_production():
         return  # Don't log debug messages in production.
     location, prefix, log_time, log_time_str, entry_text = self.parse_from(event)
     folder, name = build_file(self.folder, location, self.extension)
     try:
         log = LogFile(name, folder)
         log.write("%s %s\n\t%s\n" % (prefix, log_time_str, entry_text.replace("\n", "\n\t\t")))
         log.flush()
         log.close()
     finally:
         if event.get("transmit", False) and not event.get("isDebug", False):
             self.service.write_entry(location, log_time, entry_text)
开发者ID:leesdolphin,项目名称:eventstreamr,代码行数:15,代码来源:logging.py

示例2: JunebugLoggerService

# 需要导入模块: from twisted.python.logfile import LogFile [as 别名]
# 或者: from twisted.python.logfile.LogFile import close [as 别名]
class JunebugLoggerService(Service):
    '''Service for :class:`junebug.logging.JunebugLogObserver`'''
    log_observer = None

    def __init__(self, worker_id, path, rotate, max_files, logger=None):
        '''
        Create the service for the Junebug Log Observer.

        :param str worker_id: ID of the worker to observe logs for.
        :param str path: Path to place the log files.
        :param int rotate: Size (in bytes) before rotating log file.
        :param int max_files:
            Maximum amount of log files before old log files
            start to get deleted.
        :param logger:
            logger to add observer to. Defaults to
            twisted.python.log.theLogPublisher
        :type logger: :class:`twisted.python.log.LogPublisher`
        '''
        self.setName('Junebug Worker Logger')
        self.logger = logger if logger is not None else log.theLogPublisher
        self.worker_id = worker_id
        self.path = path
        self.rotate = rotate
        self.max_files = max_files

    def startService(self):
        if not os.path.exists(self.path):
            os.makedirs(self.path, 0755)
        self.logfile = LogFile(
            self.worker_id, self.path, rotateLength=self.rotate,
            maxRotatedFiles=self.max_files)
        self.log_observer = JunebugLogObserver(self.logfile, self.worker_id)
        self.logger.addObserver(self.log_observer)
        return super(JunebugLoggerService, self).startService()

    def stopService(self):
        if self.running:
            self.logger.removeObserver(self.log_observer)
            self.logfile.close()
        return super(JunebugLoggerService, self).stopService()

    def registered(self):
        return self.log_observer in self.logger.observers
开发者ID:praekelt,项目名称:junebug,代码行数:46,代码来源:logging_service.py

示例3: receive_logs

# 需要导入模块: from twisted.python.logfile import LogFile [as 别名]
# 或者: from twisted.python.logfile.LogFile import close [as 别名]
    def receive_logs(self, logs, transport):
        client_mac = self.__stations[transport.client].mac;
        client_mac = client_mac.translate(None, ":|/\\")
        files = {}
        for time, location, msg in logs:
            if location in files:
                log_file = files[location]
            else:
                loc = [client_mac] + list(location)
                folder, name = build_file(self.__output_folder, loc, self.__extension)
                log_file = LogFile(name, folder)
                files[location] = log_file
            log_time_str = strftime("%Y-%m-%d %H:%M:%S:%f", gmtime(time))
            log_file.write(">%s\n\t%s\n" % (log_time_str, msg.replace("\n", "\n\t\t")))

        # Now close those files
        for log_file in files.itervalues():
            log_file.flush()
            log_file.close()
        return {"accepted": True}
开发者ID:leesdolphin,项目名称:eventstreamr,代码行数:22,代码来源:station_logs.py

示例4: LocalProcess

# 需要导入模块: from twisted.python.logfile import LogFile [as 别名]
# 或者: from twisted.python.logfile.LogFile import close [as 别名]
class LocalProcess(protocol.ProcessProtocol):
  def __init__(self, name,group):
    self.orgName = name
    self.name = "".join([x for x in name if x.isalnum()])
    self.group = group
    self.logFile = LogFile(self.name+".log",group.groupDir,rotateLength=100000000,maxRotatedFiles=10)#10M
    self.updateLogFile = LogFile(self.name+".ulog",group.groupDir,rotateLength=100000000,maxRotatedFiles=5)
    self.ssLogFile = LogFile(self.name+".slog",group.groupDir,rotateLength=100000000,maxRotatedFiles=5)
    self.status = PROC_STATUS.STOP
    self.endTime = None
    self.startMemo = ''

  def connectionMade(self):
    self.status = PROC_STATUS.RUN#todo add support startCompletion check
    self._ssLog("startTime",datetime.now().strftime(TIME_FORMAT),self.startMemo)
    self.startMemo = ''
    global sendStatusFunc
    if sendStatusFunc:
      sendStatusFunc(self.group.name,self.orgName,self.status)

  def _writeLog(self,data):
    self.logFile.write("%s%s"%(data,CR)) 
  def _ssLog(self,stage,time,memo=''):
    self.ssLogFile.write("%s%s%s%s%s%s"%(stage,SEP,time,SEP,memo,CR)) 
  def logUpdate(self,fname):
    _updateLog(self.updateLogFile,fname)

  def outReceived(self, data):
    self._writeLog(data)
  def errReceived(self, data):
    self._writeLog("[ERROR DATA %s]:%s"%(datetime.now().strftime(TIME_FORMAT),data))
  def childDataReceived(self, childFD, data):
    self._writeLog(data)
  def inConnectionLost(self):
    pass
  def outConnectionLost(self):
    pass
  def errConnectionLost(self):
    pass
  def childConnectionLost(self, childFD):
    pass

  def isRunning(self):
    return self.status == PROC_STATUS.RUN

  def processExited(self,reason):
    pass
  def processEnded(self,reason):
    self.endTime = datetime.now()
    if reason.value.exitCode is None:
      self._ssLog("endInfo","code is None,info:%s"% (reason))
    elif reason.value.exitCode != 0 :
      self._ssLog("endInfo", "code:%d,info:%s"%(reason.value.exitCode,reason))
    self.status = PROC_STATUS.STOP
    self._ssLog("endTime",self.endTime.strftime(TIME_FORMAT))
    global sendStatusFunc
    if sendStatusFunc:
      sendStatusFunc(self.group.name,self.orgName,self.status)
    self.logFile.close()
    self.updateLogFile.close()
    self.ssLogFile.close()

  def signal(self,signalName):
    self.transport.signalProcess(signalName.name)
开发者ID:fordguo,项目名称:stdpm,代码行数:66,代码来源:process.py


注:本文中的twisted.python.logfile.LogFile.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。