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


Python LogFile.write方法代码示例

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


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

示例1: DummyLogFile

# 需要导入模块: from twisted.python.logfile import LogFile [as 别名]
# 或者: from twisted.python.logfile.LogFile import write [as 别名]
class DummyLogFile(object):
    '''Dummy log file used for testing.'''
    def __init__(
            self, worker_id, directory, rotateLength, maxRotatedFiles):
        self.worker_id = worker_id
        self.directory = directory
        self.rotateLength = rotateLength
        self.maxRotatedFiles = maxRotatedFiles
        self.closed_count = 0
        self.logfile = LogFile(
            worker_id, directory, rotateLength=rotateLength,
            maxRotatedFiles=maxRotatedFiles)
        self.path = self.logfile.path

    @property
    def logs(self):
        reader = self.logfile.getCurrentLog()
        logs = []
        lines = reader.readLines()
        while lines:
            logs.extend(lines)
            lines = reader.readLines()
        return logs

    def write(self, data):
        self.logfile.write(data)
        self.logfile.flush()

    def close(self):
        self.closed_count += 1

    def listLogs(self):
        return []
开发者ID:praekelt,项目名称:junebug,代码行数:35,代码来源:helpers.py

示例2: emmit

# 需要导入模块: from twisted.python.logfile import LogFile [as 别名]
# 或者: from twisted.python.logfile.LogFile import write [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

示例3: receive_logs

# 需要导入模块: from twisted.python.logfile import LogFile [as 别名]
# 或者: from twisted.python.logfile.LogFile import write [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: msg

# 需要导入模块: from twisted.python.logfile import LogFile [as 别名]
# 或者: from twisted.python.logfile.LogFile import write [as 别名]
 def msg(self, content=""):
     head = "=="*10+"START"+"=="*10
     tail = "=="*10+"=END="+"=="*10
     LogFile.write(self, "\n%d:%s\n" % (self.Counter, head))
     for line in content.split('\n'):
         if line != "":
             LogFile.write(self, "%d:%s\n" % (self.Counter, line))
     LogFile.write(self, "%d:%s\n" % (self.Counter, tail))
     self.Counter += 1
开发者ID:dinimicky,项目名称:drop_server,代码行数:11,代码来源:log.py

示例5: LocalProcess

# 需要导入模块: from twisted.python.logfile import LogFile [as 别名]
# 或者: from twisted.python.logfile.LogFile import write [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.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。