本文整理汇总了Python中twisted.scripts._twistd_unix.UnixAppLogger._getLogObserver方法的典型用法代码示例。如果您正苦于以下问题:Python UnixAppLogger._getLogObserver方法的具体用法?Python UnixAppLogger._getLogObserver怎么用?Python UnixAppLogger._getLogObserver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.scripts._twistd_unix.UnixAppLogger
的用法示例。
在下文中一共展示了UnixAppLogger._getLogObserver方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getLogObserverFile
# 需要导入模块: from twisted.scripts._twistd_unix import UnixAppLogger [as 别名]
# 或者: from twisted.scripts._twistd_unix.UnixAppLogger import _getLogObserver [as 别名]
def test_getLogObserverFile(self):
"""
When C{logfile} contains a file name, L{app.AppLogger._getLogObserver}
returns a log observer pointing at the specified path, and a signal
handler rotating the log is installed.
"""
logFiles = _patchFileLogObserver(self.patch)
filename = self.mktemp()
logger = UnixAppLogger({"logfile": filename})
observer = logger._getLogObserver()
self.assertEquals(len(logFiles), 1)
self.assertEquals(logFiles[0].path,
os.path.abspath(filename))
self.assertEquals(len(self.signals), 1)
self.assertEquals(self.signals[0][0], signal.SIGUSR1)
d = Deferred()
def rotate():
d.callback(None)
logFiles[0].rotate = rotate
rotateLog = self.signals[0][1]
rotateLog(None, None)
return d
示例2: test_getLogObserverStdout
# 需要导入模块: from twisted.scripts._twistd_unix import UnixAppLogger [as 别名]
# 或者: from twisted.scripts._twistd_unix.UnixAppLogger import _getLogObserver [as 别名]
def test_getLogObserverStdout(self):
"""
When non-daemonized and C{logfile} is empty or set to C{-},
L{UnixAppLogger._getLogObserver} returns a log observer pointing at
C{sys.stdout}.
"""
logFiles = _patchFileLogObserver(self.patch)
logger = UnixAppLogger({"logfile": "-", "nodaemon": True})
observer = logger._getLogObserver()
self.assertEquals(len(logFiles), 1)
self.assertIdentical(logFiles[0], sys.stdout)
logger = UnixAppLogger({"logfile": "", "nodaemon": True})
observer = logger._getLogObserver()
self.assertEquals(len(logFiles), 2)
self.assertIdentical(logFiles[1], sys.stdout)
示例3: test_getLogObserverSyslog
# 需要导入模块: from twisted.scripts._twistd_unix import UnixAppLogger [as 别名]
# 或者: from twisted.scripts._twistd_unix.UnixAppLogger import _getLogObserver [as 别名]
def test_getLogObserverSyslog(self):
"""
If C{syslog} is set to C{True}, L{UnixAppLogger._getLogObserver} starts
a L{syslog.SyslogObserver} with given C{prefix}.
"""
logs = _setupSyslog(self)
logger = UnixAppLogger({"syslog": True, "prefix": "test-prefix"})
observer = logger._getLogObserver()
self.assertEqual(logs, ["test-prefix"])
observer({"a": "b"})
self.assertEqual(logs, ["test-prefix", {"a": "b"}])
示例4: test_getLogObserverDefaultFile
# 需要导入模块: from twisted.scripts._twistd_unix import UnixAppLogger [as 别名]
# 或者: from twisted.scripts._twistd_unix.UnixAppLogger import _getLogObserver [as 别名]
def test_getLogObserverDefaultFile(self):
"""
When daemonized and C{logfile} is empty, the observer returned by
L{UnixAppLogger._getLogObserver} points at C{twistd.log} in the current
directory.
"""
logFiles = _patchFileLogObserver(self.patch)
logger = UnixAppLogger({"logfile": "", "nodaemon": False})
observer = logger._getLogObserver()
self.assertEquals(len(logFiles), 1)
self.assertEquals(logFiles[0].path,
os.path.abspath("twistd.log"))
示例5: test_getLogObserverSyslog
# 需要导入模块: from twisted.scripts._twistd_unix import UnixAppLogger [as 别名]
# 或者: from twisted.scripts._twistd_unix.UnixAppLogger import _getLogObserver [as 别名]
def test_getLogObserverSyslog(self):
"""
If C{syslog} is set to C{True}, L{UnixAppLogger._getLogObserver} starts
a L{syslog.SyslogObserver} with given C{prefix}.
"""
class fakesyslog(object):
def openlog(self, prefix):
self.prefix = prefix
syslogModule = fakesyslog()
self.patch(syslog, "syslog", syslogModule)
logger = UnixAppLogger({"syslog": True, "prefix": "test-prefix"})
observer = logger._getLogObserver()
self.assertEquals(syslogModule.prefix, "test-prefix")
示例6: test_getLogObserverSyslog
# 需要导入模块: from twisted.scripts._twistd_unix import UnixAppLogger [as 别名]
# 或者: from twisted.scripts._twistd_unix.UnixAppLogger import _getLogObserver [as 别名]
def test_getLogObserverSyslog(self):
"""
If C{syslog} is set to C{True}, L{UnixAppLogger._getLogObserver} starts
a L{syslog.SyslogObserver} with given C{prefix}.
"""
class fakesyslogobserver(object):
def __init__(self, prefix):
fakesyslogobserver.prefix = prefix
def emit(self, eventDict):
pass
self.patch(syslog, "SyslogObserver", fakesyslogobserver)
logger = UnixAppLogger({"syslog": True, "prefix": "test-prefix"})
observer = logger._getLogObserver()
self.assertEquals(fakesyslogobserver.prefix, "test-prefix")
示例7: test_getLogObserverDontOverrideSignalHandler
# 需要导入模块: from twisted.scripts._twistd_unix import UnixAppLogger [as 别名]
# 或者: from twisted.scripts._twistd_unix.UnixAppLogger import _getLogObserver [as 别名]
def test_getLogObserverDontOverrideSignalHandler(self):
"""
If a signal handler is already installed,
L{UnixAppLogger._getLogObserver} doesn't override it.
"""
def fakeGetSignal(sig):
self.assertEquals(sig, signal.SIGUSR1)
return object()
self.patch(signal, "getsignal", fakeGetSignal)
filename = self.mktemp()
logger = UnixAppLogger({"logfile": filename})
observer = logger._getLogObserver()
self.assertEquals(self.signals, [])