__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
# -*- test-case-name: twisted.logger.test.test_file -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
File log observer.
"""
from typing import IO, Any, Callable, Optional
from zope.interface import implementer
from twisted.python.compat import ioType
from ._format import formatEventAsClassicLogText, formatTime, timeFormatRFC3339
from ._interfaces import ILogObserver, LogEvent
@implementer(ILogObserver)
class FileLogObserver:
"""
Log observer that writes to a file-like object.
"""
def __init__(
self, outFile: IO[Any], formatEvent: Callable[[LogEvent], Optional[str]]
) -> None:
"""
@param outFile: A file-like object. Ideally one should be passed which
accepts text data. Otherwise, UTF-8 L{bytes} will be used.
@param formatEvent: A callable that formats an event.
"""
if ioType(outFile) is not str:
self._encoding: Optional[str] = "utf-8"
else:
self._encoding = None
self._outFile = outFile
self.formatEvent = formatEvent
def __call__(self, event: LogEvent) -> None:
"""
Write event to file.
@param event: An event.
"""
text = self.formatEvent(event)
if text:
if self._encoding is None:
self._outFile.write(text)
else:
self._outFile.write(text.encode(self._encoding))
self._outFile.flush()
def textFileLogObserver(
outFile: IO[Any], timeFormat: Optional[str] = timeFormatRFC3339
) -> FileLogObserver:
"""
Create a L{FileLogObserver} that emits text to a specified (writable)
file-like object.
@param outFile: A file-like object. Ideally one should be passed which
accepts text data. Otherwise, UTF-8 L{bytes} will be used.
@param timeFormat: The format to use when adding timestamp prefixes to
logged events. If L{None}, or for events with no C{"log_timestamp"}
key, the default timestamp prefix of C{"-"} is used.
@return: A file log observer.
"""
def formatEvent(event: LogEvent) -> Optional[str]:
return formatEventAsClassicLogText(
event, formatTime=lambda e: formatTime(e, timeFormat)
)
return FileLogObserver(outFile, formatEvent)
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| test | Folder | 0755 |
|
|
| __init__.py | File | 3.29 KB | 0644 |
|
| _buffer.py | File | 1.49 KB | 0644 |
|
| _capture.py | File | 624 B | 0644 |
|
| _file.py | File | 2.28 KB | 0644 |
|
| _filter.py | File | 6.71 KB | 0644 |
|
| _flatten.py | File | 4.88 KB | 0644 |
|
| _format.py | File | 13.16 KB | 0644 |
|
| _global.py | File | 8.43 KB | 0644 |
|
| _interfaces.py | File | 2.29 KB | 0644 |
|
| _io.py | File | 4.44 KB | 0644 |
|
| _json.py | File | 8.21 KB | 0644 |
|
| _legacy.py | File | 5.12 KB | 0644 |
|
| _levels.py | File | 2.89 KB | 0644 |
|
| _logger.py | File | 9.75 KB | 0644 |
|
| _observer.py | File | 3.17 KB | 0644 |
|
| _stdlib.py | File | 4.42 KB | 0644 |
|
| _util.py | File | 1.34 KB | 0644 |
|