本文整理汇总了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 []
示例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)
示例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}
示例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
示例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)