本文整理汇总了Python中twisted.scripts._twistd_unix.UnixAppLogger类的典型用法代码示例。如果您正苦于以下问题:Python UnixAppLogger类的具体用法?Python UnixAppLogger怎么用?Python UnixAppLogger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UnixAppLogger类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getLogObserverFile
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_getLogObserverSyslog
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"}])
示例3: test_getLogObserverDefaultFile
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"))
示例4: test_getLogObserverSyslog
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")
示例5: test_getLogObserverSyslog
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")
示例6: test_getLogObserverDontOverrideSignalHandler
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, [])
示例7: test_getLogObserverStdout
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)