本文整理汇总了Python中twisted.python.logfile.LogFile类的典型用法代码示例。如果您正苦于以下问题:Python LogFile类的具体用法?Python LogFile怎么用?Python LogFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LogFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DummyLogFile
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: __init__
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 = ''
示例3: startService
def startService(self):
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()
示例4: __init__
def __init__(
self, worker_id, path, rotateLength, maxRotatedFiles):
self.worker_id = worker_id
self.path = path
self.rotateLength = rotateLength
self.maxRotatedFiles = maxRotatedFiles
self.closed_count = 0
self.logfile = LogFile.fromFullPath(
path, rotateLength=rotateLength, maxRotatedFiles=maxRotatedFiles)
示例5: startService
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()
示例6: __init__
def __init__(self, nick, server, channel, port, loggingfile=None):
self.server = server
self.port = port
if loggingfile is not None:
log.startLogging(LogFile.fromFullPath(loggingfile))
self.factory = ConversationBotFactory(self, ConversationBotClient,
nick,
channel)
示例7: JunebugLoggerService
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
示例8: _openLogFile
def _openLogFile(self, path):
try:
from twisted.python.logfile import LogFile
log.msg("Setting up http.log rotating %s files of %s bytes each" %
(maxRotatedFiles, rotateLength))
if hasattr(LogFile, "fromFullPath"): # not present in Twisted-2.5.0
return LogFile.fromFullPath(path, rotateLength=rotateLength, maxRotatedFiles=maxRotatedFiles)
else:
log.msg("WebStatus: rotated http logs are not supported on this version of Twisted")
except ImportError, e:
log.msg("WebStatus: Unable to set up rotating http.log: %s" % e)
示例9: startService
def startService(self):
Service.startService(self)
if self.filename != '-':
self.logfile = LogFile.fromFullPath(
self.filename, rotateLength=None, defaultMode=0o644)
self.__previous_signal_handler = signal.signal(
signal.SIGUSR1, self._signal_handler)
else:
self.logfile = sys.stdout
self.observer = FileLogObserver(self.logfile)
self.observer.start()
示例10: __init__
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
示例11: __init__
def __init__(self, logfilename):
if logfilename is None:
logFile = sys.stdout
else:
logFile = LogFile.fromFullPath(logfilename, rotateLength=None)
# Override if signal is set to None or SIG_DFL (0)
if not signal.getsignal(signal.SIGUSR1):
def signalHandler(signal, frame):
from twisted.internet import reactor
reactor.callFromThread(logFile.reopen)
signal.signal(signal.SIGUSR1, signalHandler)
self.observer = log.FileLogObserver(logFile)
示例12: setup_logging
def setup_logging():
filename = LOG_SETTINGS['file_path']
log_file = LogFile.fromFullPath(
filename,
rotateLength=LOG_SETTINGS['max_bytes'],
maxRotatedFiles=LOG_SETTINGS['max_backups']
) if filename is not None else sys.stdout
log_level = getattr(logging, LOG_SETTINGS['level'])
observer = LevelFileLogObserver(log_file, log_level)
observer.timeFormat = LOG_SETTINGS['time_format']
observer.start()
示例13: opt_logfile
def opt_logfile(self, logfile_path):
"""
Log to a file. Log is written to ``stdout`` by default. The logfile
directory is created if it does not already exist.
"""
logfile = FilePath(logfile_path)
logfile_directory = logfile.parent()
if not logfile_directory.exists():
logfile_directory.makedirs()
self['logfile'] = LogFile.fromFullPath(
logfile.path,
rotateLength=LOGFILE_LENGTH,
maxRotatedFiles=LOGFILE_COUNT,
)
示例14: setServiceParent
def setServiceParent(self, app):
MultiService.setServiceParent(self, app)
if config.ErrorLogEnabled:
errorLogFile = LogFile.fromFullPath(
config.ErrorLogFile,
rotateLength=config.ErrorLogRotateMB * 1024 * 1024,
maxRotatedFiles=config.ErrorLogMaxRotatedFiles
)
errorLogObserver = FileLogObserver(errorLogFile).emit
# Registering ILogObserver with the Application object
# gets our observer picked up within AppLogger.start( )
app.setComponent(ILogObserver, errorLogObserver)
示例15: msg
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