本文整理汇总了Python中twisted.python.log.FileLogObserver方法的典型用法代码示例。如果您正苦于以下问题:Python log.FileLogObserver方法的具体用法?Python log.FileLogObserver怎么用?Python log.FileLogObserver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.log
的用法示例。
在下文中一共展示了log.FileLogObserver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def setUp(self):
"""
Add a log observer which records log events in C{self.out}. Also,
make sure the default string encoding is ASCII so that
L{testSingleUnicode} can test the behavior of logging unencodable
unicode messages.
"""
self.out = FakeFile()
self.lp = log.LogPublisher()
self.flo = log.FileLogObserver(self.out)
self.lp.addObserver(self.flo.emit)
try:
str(u'\N{VULGAR FRACTION ONE HALF}')
except UnicodeEncodeError:
# This is the behavior we want - don't change anything.
self._origEncoding = None
else:
if _PY3:
self._origEncoding = None
return
reload(sys)
self._origEncoding = sys.getdefaultencoding()
sys.setdefaultencoding('ascii')
示例2: test_startLogging
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def test_startLogging(self):
"""
startLogging() installs FileLogObserver and overrides sys.stdout and
sys.stderr.
"""
origStdout, origStderr = sys.stdout, sys.stderr
self._startLoggingCleanup()
# When done with test, reset stdout and stderr to current values:
fakeFile = StringIO()
observer = log.startLogging(fakeFile)
self.addCleanup(observer.stop)
log.msg("Hello!")
self.assertIn("Hello!", fakeFile.getvalue())
self.assertIsInstance(sys.stdout, LoggingFile)
self.assertEqual(sys.stdout.level, NewLogLevel.info)
encoding = getattr(origStdout, "encoding", None)
if not encoding:
encoding = sys.getdefaultencoding()
self.assertEqual(sys.stdout.encoding.upper(), encoding.upper())
self.assertIsInstance(sys.stderr, LoggingFile)
self.assertEqual(sys.stderr.level, NewLogLevel.error)
encoding = getattr(origStderr, "encoding", None)
if not encoding:
encoding = sys.getdefaultencoding()
self.assertEqual(sys.stderr.encoding.upper(), encoding.upper())
示例3: test_emitNewline
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def test_emitNewline(self):
"""
FileLogObserver.emit() will append a newline to its file output.
"""
output = StringIO()
flo = log.FileLogObserver(output)
publisher = log.LogPublisher()
publisher.addObserver(flo.emit)
publisher.msg("Hello!")
result = output.getvalue()
suffix = "Hello!\n"
self.assertTrue(
result.endswith(suffix),
"{0!r} does not end with {1!r}".format(result, suffix)
)
示例4: _patchFileLogObserver
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def _patchFileLogObserver(patch):
"""
Patch L{log.FileLogObserver} to record every call and keep a reference to
the passed log file for tests.
@param patch: a callback for patching (usually L{unittest.TestCase.patch}).
@return: the list that keeps track of the log files.
@rtype: C{list}
"""
logFiles = []
oldFileLobObserver = log.FileLogObserver
def FileLogObserver(logFile):
logFiles.append(logFile)
return oldFileLobObserver(logFile)
patch(log, 'FileLogObserver', FileLogObserver)
return logFiles
示例5: setUp
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def setUp(self):
"""
Add a log observer which records log events in C{self.out}. Also,
make sure the default string encoding is ASCII so that
L{testSingleUnicode} can test the behavior of logging unencodable
unicode messages.
"""
self.out = FakeFile()
self.lp = log.LogPublisher()
self.flo = log.FileLogObserver(self.out)
self.lp.addObserver(self.flo.emit)
try:
str(u'\N{VULGAR FRACTION ONE HALF}')
except UnicodeEncodeError:
# This is the behavior we want - don't change anything.
self._origEncoding = None
else:
reload(sys)
self._origEncoding = sys.getdefaultencoding()
sys.setdefaultencoding('ascii')
示例6: CanvasApp
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def CanvasApp(nginx=False):
application = service.Application("Canvas")
web_server = CanvasTCPServer()
web_server.setServiceParent(application)
log_file = logfile.LogFile(
name="twistd.log",
directory="/var/canvas/website/run",
maxRotatedFiles=100,
)
application.setComponent(log.ILogObserver, log.FileLogObserver(log_file).emit)
return application
示例7: logger
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def logger():
try:
if 'ANCHORE_LOGFILE' in os.environ:
thefile = os.environ['ANCHORE_LOGFILE']
else:
thefile = "anchore-general.log"
except:
thefile = "anchore-general.log"
f = logfile.LogFile(thefile, '/var/log/', rotateLength=10000000, maxRotatedFiles=10)
log_observer = log.FileLogObserver(f)
return log_observer.emit
#def logger():
# return log.PythonLoggingObserver().emit
示例8: _setUpLogFile
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def _setUpLogFile(self):
self._tearDownLogFile()
if self.logfile == '-':
logFile = sys.stdout
else:
logFile = open(self.logfile, 'a')
self._logFileObject = logFile
self._logFileObserver = log.FileLogObserver(logFile)
log.startLoggingWithObserver(self._logFileObserver.emit, 0)
示例9: test_getTimezoneOffsetWestOfUTC
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def test_getTimezoneOffsetWestOfUTC(self):
"""
Attempt to verify that L{FileLogObserver.getTimezoneOffset} returns
correct values for the current C{TZ} environment setting for at least
some cases. This test method exercises a timezone that is west of UTC
(and should produce positive results).
"""
self._getTimezoneOffsetTest("America/New_York", 14400, 18000)
示例10: test_getTimezoneOffsetEastOfUTC
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def test_getTimezoneOffsetEastOfUTC(self):
"""
Attempt to verify that L{FileLogObserver.getTimezoneOffset} returns
correct values for the current C{TZ} environment setting for at least
some cases. This test method exercises a timezone that is east of UTC
(and should produce negative results).
"""
self._getTimezoneOffsetTest("Europe/Berlin", -7200, -3600)
示例11: test_getTimezoneOffsetWithoutDaylightSavingTime
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def test_getTimezoneOffsetWithoutDaylightSavingTime(self):
"""
Attempt to verify that L{FileLogObserver.getTimezoneOffset} returns
correct values for the current C{TZ} environment setting for at least
some cases. This test method exercises a timezone that does not use
daylight saving time at all (so both summer and winter time test values
should have the same offset).
"""
# Test a timezone that doesn't have DST. mktime() implementations
# available for testing seem happy to produce results for this even
# though it's not entirely valid.
self._getTimezoneOffsetTest("Africa/Johannesburg", -7200, -7200)
示例12: test_microsecondTimestampFormatting
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def test_microsecondTimestampFormatting(self):
"""
L{FileLogObserver.formatTime} supports a value of C{timeFormat} which
includes C{"%f"}, a L{datetime}-only format specifier for microseconds.
"""
self.flo.timeFormat = '%f'
self.assertEqual("600000", self.flo.formatTime(12345.6))
示例13: test_emitPrefix
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def test_emitPrefix(self):
"""
FileLogObserver.emit() will add a timestamp and system prefix to its
file output.
"""
output = StringIO()
flo = log.FileLogObserver(output)
events = []
def observer(event):
# Capture the event for reference and pass it along to flo
events.append(event)
flo.emit(event)
publisher = log.LogPublisher()
publisher.addObserver(observer)
publisher.msg("Hello!")
self.assertEqual(len(events), 1)
event = events[0]
result = output.getvalue()
prefix = "{time} [{system}] ".format(
time=flo.formatTime(event["time"]), system=event["system"],
)
self.assertTrue(
result.startswith(prefix),
"{0!r} does not start with {1!r}".format(result, prefix)
)
示例14: __init__
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def __init__(self, f=None, level="info", default=DEBUG):
log.FileLogObserver.__init__(self, f or sys.stdout)
self.level = levels[level]
self.default = default
示例15: emit
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import FileLogObserver [as 别名]
def emit(self, eventDict):
ll = eventDict.get('loglevel', self.default)
if eventDict['isError'] or 'failure' in eventDict or self.level >= ll:
log.FileLogObserver.emit(self, eventDict)