本文整理匯總了Python中twisted.python.logfile.DailyLogFile方法的典型用法代碼示例。如果您正苦於以下問題:Python logfile.DailyLogFile方法的具體用法?Python logfile.DailyLogFile怎麽用?Python logfile.DailyLogFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.python.logfile
的用法示例。
在下文中一共展示了logfile.DailyLogFile方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_rotateAlreadyExists
# 需要導入模塊: from twisted.python import logfile [as 別名]
# 或者: from twisted.python.logfile import DailyLogFile [as 別名]
def test_rotateAlreadyExists(self):
"""
L{DailyLogFile.rotate} doesn't do anything if they new log file already
exists on the disk.
"""
log = RiggedDailyLogFile(self.name, self.dir)
self.addCleanup(log.close)
# Build a new file with the same name as the file which would be created
# if the log file is to be rotated.
newFilePath = "{0}.{1}".format(log.path, log.suffix(log.lastDate))
with open(newFilePath, "w") as fp:
fp.write("123")
previousFile = log._file
log.rotate()
self.assertEqual(previousFile, log._file)
示例2: test_toDateDefaultToday
# 需要導入模塊: from twisted.python import logfile [as 別名]
# 或者: from twisted.python.logfile import DailyLogFile [as 別名]
def test_toDateDefaultToday(self):
"""
Test that L{DailyLogFile.toDate} returns today's date by default.
By mocking L{time.localtime}, we ensure that L{DailyLogFile.toDate}
returns the first 3 values of L{time.localtime} which is the current
date.
Note that we don't compare the *real* result of L{DailyLogFile.toDate}
to the *real* current date, as there's a slight possibility that the
date changes between the 2 function calls.
"""
def mock_localtime(*args):
self.assertEqual((), args)
return list(range(0, 9))
log = logfile.DailyLogFile(self.name, self.dir)
self.addCleanup(log.close)
self.patch(time, "localtime", mock_localtime)
logDate = log.toDate()
self.assertEqual([0, 1, 2], logDate)
示例3: test_persistence
# 需要導入模塊: from twisted.python import logfile [as 別名]
# 或者: from twisted.python.logfile import DailyLogFile [as 別名]
def test_persistence(self):
"""
L{DailyLogFile} objects can be pickled and unpickled, which preserves
all the various attributes of the log file.
"""
defaultMode = 0o642
log = logfile.DailyLogFile(self.name, self.dir,
defaultMode)
self.addCleanup(log.close)
log.write("123")
# Check that the unpickled log is the same as the original one.
copy = pickle.loads(pickle.dumps(log))
self.addCleanup(copy.close)
self.assertEqual(self.name, copy.name)
self.assertEqual(self.dir, copy.directory)
self.assertEqual(self.path, copy.path)
self.assertEqual(defaultMode, copy.defaultMode)
self.assertEqual(log.lastDate, copy.lastDate)
示例4: __init__
# 需要導入模塊: from twisted.python import logfile [as 別名]
# 或者: from twisted.python.logfile import DailyLogFile [as 別名]
def __init__(self, path, queue, name):
threading.Thread.__init__(self)
self.queue = queue
self.writer = DailyLogFile(name, path)
# Don't want this to float around if the rest of the system goes down
self.setDaemon(True)
示例5: _openFile
# 需要導入模塊: from twisted.python import logfile [as 別名]
# 或者: from twisted.python.logfile import DailyLogFile [as 別名]
def _openFile(self):
logfile.DailyLogFile._openFile(self)
# rig the date to match _clock, not mtime
self.lastDate = self.toDate()
示例6: test_getLog
# 需要導入模塊: from twisted.python import logfile [as 別名]
# 或者: from twisted.python.logfile import DailyLogFile [as 別名]
def test_getLog(self):
"""
Test retrieving log files with L{DailyLogFile.getLog}.
"""
data = ["1\n", "2\n", "3\n"]
log = RiggedDailyLogFile(self.name, self.dir)
self.addCleanup(log.close)
for d in data:
log.write(d)
log.flush()
# This returns the current log file.
r = log.getLog(0.0)
self.addCleanup(r.close)
self.assertEqual(data, r.readLines())
# We can't get this log, it doesn't exist yet.
self.assertRaises(ValueError, log.getLog, 86400)
log._clock = 86401 # New day
r.close()
log.rotate()
r = log.getLog(0) # We get the previous log
self.addCleanup(r.close)
self.assertEqual(data, r.readLines())
示例7: test_rotatePermissionDirectoryNotOk
# 需要導入模塊: from twisted.python import logfile [as 別名]
# 或者: from twisted.python.logfile import DailyLogFile [as 別名]
def test_rotatePermissionDirectoryNotOk(self):
"""
L{DailyLogFile.rotate} doesn't do anything if the directory containing
the log files can't be written to.
"""
log = logfile.DailyLogFile(self.name, self.dir)
self.addCleanup(log.close)
os.chmod(log.directory, 0o444)
# Restore permissions so tests can be cleaned up.
self.addCleanup(os.chmod, log.directory, 0o755)
previousFile = log._file
log.rotate()
self.assertEqual(previousFile, log._file)
示例8: test_rotatePermissionFileNotOk
# 需要導入模塊: from twisted.python import logfile [as 別名]
# 或者: from twisted.python.logfile import DailyLogFile [as 別名]
def test_rotatePermissionFileNotOk(self):
"""
L{DailyLogFile.rotate} doesn't do anything if the log file can't be
written to.
"""
log = logfile.DailyLogFile(self.name, self.dir)
self.addCleanup(log.close)
os.chmod(log.path, 0o444)
previousFile = log._file
log.rotate()
self.assertEqual(previousFile, log._file)
示例9: test_toDateUsesArgumentsToMakeADate
# 需要導入模塊: from twisted.python import logfile [as 別名]
# 或者: from twisted.python.logfile import DailyLogFile [as 別名]
def test_toDateUsesArgumentsToMakeADate(self):
"""
Test that L{DailyLogFile.toDate} uses its arguments to create a new
date.
"""
log = logfile.DailyLogFile(self.name, self.dir)
self.addCleanup(log.close)
date = (2014, 10, 22)
seconds = time.mktime(date + (0,)*6)
logDate = log.toDate(seconds)
self.assertEqual(date, logDate)
示例10: logToDir
# 需要導入模塊: from twisted.python import logfile [as 別名]
# 或者: from twisted.python.logfile import DailyLogFile [as 別名]
def logToDir(self, logdir):
self.logdir = logdir
self.console_logfile = DailyLogFile('console.log', logdir)
self.custom_logs = {}
self.observer = self.logdirObserver
示例11: logdirObserver
# 需要導入模塊: from twisted.python import logfile [as 別名]
# 或者: from twisted.python.logfile import DailyLogFile [as 別名]
def logdirObserver(self, event):
msg = formatEvent(event)
log_type = event.get('type')
if log_type is not None and log_type not in self.custom_logs:
self.custom_logs[log_type] = DailyLogFile(log_type + '.log', self.logdir)
logfile = self.custom_logs.get(log_type, self.console_logfile)
logfile.write(msg + '\n')
logfile.flush()